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 comment

Filed under MS CRM 4.0

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s