Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

i'm getting this error while retriving multiple records and updating records "Unable to cast object of type 'System.Guid' to type 'Microsoft.Xrm.Sdk.EntityReference'."

(0) ShareShare
ReportReport
Posted on by 85

if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity acc_entity = (Entity)context.InputParameters["Target"];

var query = new QueryExpression("contact")
{
ColumnSet = new ColumnSet("contactid"),

};
query.Criteria.AddCondition("parentcustomerid", ConditionOperator.Equal, acc_entity.Id);

EntityCollection results = service.RetrieveMultiple(query);

results.Entities.ToList().ForEach(x =>
{
// Console.WriteLine(x.Attributes["contactid"]);

EntityReference contact_ref = x.GetAttributeValue<EntityReference>("contactid");
Entity contact = service.Retrieve("contact", contact_ref.Id, new ColumnSet(new string[] { "fax" }));
contact["fax"] = "789456";
service.Update(contact);
});

}

  • Manoj  Profile Picture
    Manoj 85 on at
    RE: i'm getting this error while retriving multiple records and updating records "Unable to cast object of type 'System.Guid' to type 'Microsoft.Xrm.Sdk.EntityReference'."

    Thank you Mehdi

  • Verified answer
    meelamri Profile Picture
    meelamri 13,212 User Group Leader on at
    RE: i'm getting this error while retriving multiple records and updating records "Unable to cast object of type 'System.Guid' to type 'Microsoft.Xrm.Sdk.EntityReference'."

    Hi, 

    var query = new QueryExpression("contact")
    {
        ColumnSet = new ColumnSet(false),
    };
    
    query.Criteria.AddCondition("parentcustomerid", ConditionOperator.Equal, acc_entity.Id);
    EntityCollection results = crmSvc.RetrieveMultiple(query);
    
    results.Entities.ToList().ForEach(x =>
        {
            Entity contactToUpdate = new Entity(x.LogicalName, x.Id);
            contactToUpdate["fax"] = "789456";
            service.Update(contactToUpdate);
        });
        

  • Manoj  Profile Picture
    Manoj 85 on at
    RE: i'm getting this error while retriving multiple records and updating records "Unable to cast object of type 'System.Guid' to type 'Microsoft.Xrm.Sdk.EntityReference'."

    can any one guide me here

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans