Retrieve Account Related Activity

Sometime we need to get all activities related to specific account or contact. We can easily do this by Querying activitypointer entity based on regardingobjectID. you can use below function to get all activity related to account.

You just need to pass Crm service object and Accountid to this function

Public BusinessEntityCollection FetchActivityList(CrmService _Service,Guid AccountID)

{

       QueryExpression _Query = new QueryExpression();

        _Query.EntityName = “activitypointer”;

        ColumnSet _ColsToFetch = new ColumnSet();

        _ColsToFetch.Attributes = new string[] { “activityid”, “activitytypecode”, “subject” }; //you can include others column based on your requirements

        _Query.ColumnSet = _ColsToFetch;

        _Query.Criteria = new FilterExpression();

        _Query.Criteria.FilterOperator = LogicalOperator.And;

        ConditionExpression _Condition = new ConditionExpression();

        _Condition.AttributeName = “regardingobjectid”;

        _Condition.Operator = ConditionOperator.Equal;

        _Condition.Values = new object[] { accountid };

        _Query.Criteria.Conditions = new ConditionExpression[] { _Condition };

        BusinessEntityCollection _ActivityList = _Service.RetrieveMultiple(_Query);

        Return _ActivityList;

}

 Hope it will help somebody

Happy Coding !!!

Leave a Reply

Your email address will not be published. Required fields are marked *