Hi CRM Guy,
Below is the code for getting all the record for an entity. You need to create a console application and put the below code.
public static List<Entity> RetrieveOpportunity(IOrganizationService service)
{
// Query using the paging cookie.
// Define the paging attributes.
// The number of records per page to retrieve.
int queryCount = 5000;
// Initialize the page number.
int pageNumber = 1;
List<Entity> Entities = new List<Entity>();
var getOpportunities = new QueryExpression();
getOpportunities.EntityName = "opportunity";
getOpportunities.ColumnSet = new ColumnSet("opportunityid", "parentaccountid");
EntityCollection retrieveOpportunities = service.RetrieveMultiple(getOpportunities);
// Assign the pageinfo properties to the query expression.
getOpportunities.PageInfo = new PagingInfo();
getOpportunities.PageInfo.Count = queryCount;
getOpportunities.PageInfo.PageNumber = pageNumber;
// The current paging cookie. When retrieving the first page,
// pagingCookie should be null.
getOpportunities.PageInfo.PagingCookie = null;
while (true)
{
// Retrieve the page.
EntityCollection results = service.RetrieveMultiple(getOpportunities);
if (results.Entities != null)
{
Entities.AddRange(results.Entities);
}
// Check for more records, if it returns true.
if (results.MoreRecords)
{
// Increment the page number to retrieve the next page.
getOpportunities.PageInfo.PageNumber++;
// Set the paging cookie to the paging cookie returned from current results.
getOpportunities.PageInfo.PagingCookie = results.PagingCookie;
}
else
{
// If no more records are in the result nodes, exit the loop.
break;
}
}
return Entities;
}
If you find it helpful, Please mark as verified.
Best Regards,
Shahbaaz