Thursday, 30 July 2015

Get all attributes of the records in CRM

Hi,
 
Many times there could a requirement where we need to get most of the attributes of a record in CRM. Then, we can write the code to get all attributes.
 
Here is the code for it.
 
We can achieve this by using two things
1) Fetch XML
  In FetchXML, if you forgot to mention attribute tag by default it will get all the attributes.
 
string strFetchXML = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
   <entity name='account'>
   </entity>
   </fetch>";
EntityCollection entColAccounts = iService.RetrieveMultiple(new FetchExpression(strFetchXML));

strFetchXML = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
   <entity name='account'>
   <all-attributes/>
   </fetch>";
 entColAccounts = iService.RetrieveMultiple(new FetchExpression(strFetchXML));
2) QueryExpression
 
QueryExpression objQueryExpression = new QueryExpression("account");
objQueryExpression.ColumnSet = new ColumnSet(true);
entColAccounts = iService.RetrieveMultiple(objQueryExpression);
 
Note: Mostly avoid retrieving the record with the all-attributes  as there could be lot of performance degrade. It is always best and recommended way to mention the specific attributes and retrieve records from CRM.
 
Hope this helps.
 
--
Happy CRM'ing
Gopinath

No comments:

Post a Comment