locked
Entity Id must be specified for Update in MS CRM 2011 Post-plugin RRS feed

  • Question

  • Hi All,

    I am getting the error 'Entity Id must be specified for Update" while updating the account record from Post-plug of the account, the below is the code.

    if (context.PostEntityImages["account"] is Entity)

    {

    Entity PostEntity = (Entity)context.PostEntityImages["account"];

    Guid AccountRecordID = (Guid)PostEntity["accountid"];

    Entity account = new Entity("account"); account.Attributes.Add("accountid", AccountRecordID);

    account.Attributes.Add("new_sign", AccountRecordID.ToString());

    service.Update(account);

    }

    I am not getting what went wrong. please advice.

    Thanks in advance,

    srikanth


    Tuesday, July 1, 2014 7:12 PM

All replies

  • Change this

    account.Attributes.Add("accountid", AccountRecordID);

    to

    account.Attributes.Add("id", AccountRecordID);

    • Proposed as answer by myCRMGuy Wednesday, July 2, 2014 12:59 AM
    Wednesday, July 2, 2014 12:59 AM
  • Hi Srikanth,

    The following code should work, and is a bit easier to read and work with;

    if (context.PostEntityImages["account"] is Entity)
    {
        Entity PostEntity = (Entity)context.PostEntityImages["account"];
        Guid AccountRecordID = (Guid)PostEntity["accountid"];
    
        Entity account = new Entity("account"); 
        account["accountid"] = AccountRecordID;
        account["new_sign"] = AccountRecordID.ToString();
        service.Update(account);
    }

    ~ Atomic Coder

    Wednesday, July 2, 2014 1:18 AM
  • Hi Srikanth,

    You can even try this code

    if (context.PostEntityImages["account"] is Entity)  
    
    {
    
    Entity PostEntity = (Entity)context.PostEntityImages["account"]; 
    
    Guid AccountRecordID = PostEntity.Id;
    
    Entity account = new Entity("account"); 
    //account.Attributes.Add("accountid", AccountRecordID); 
    account.Id = AccountRecordID;
    
    account.Attributes.Add("new_sign", AccountRecordID.ToString()); 
    
    service.Update(account); 
    
    }
    

    Regards,

    Ravi

    Wednesday, July 2, 2014 10:55 AM