Saturday, September 17, 2011

Reterive all Activities in MS CRM 4.0 through QueryExpression object

Database Query: "SELECT * FROM ActivityPointerBase"

static void GetAllActivities()
        {
            CRMHelper objCRMHelper = new CRMHelper();
            CrmService service = objCRMHelper.GetCRMService();

            AllColumns activityPointerBaseColumns = new AllColumns();

            QueryExpression query = new QueryExpression();
            query.ColumnSet = activityPointerBaseColumns;
            query.EntityName = EntityName.activitypointer.ToString();

            BusinessEntityCollection result = service.RetrieveMultiple(query);

            if (result.BusinessEntities.Length > 0)
            {
                foreach (BusinessEntity objBE in result.BusinessEntities)
                {
                }
            }
        }