web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archive)
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);
});

}

Categories:
  • Manoj  Profile Picture
    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
    13,198 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
    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

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Blog subscriptions now enabled!

Follow your favorite blogs

TechTalk: How Dataverse and Microsoft Fabric powers ...

Explore the latest advancements in data export and integration within ...

Leaderboard > 🔒Ι Microsoft Dynamics CRM (Archived)

Featured topics

Product updates

Dynamics 365 release plans