function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Fabrice76Fabrice76 

INVALID_FIELD_FOR_INSERT_UPDATE error with account update

Hi,
I use the soap API in C# to show/edit/update objects in my program.
When i want to update an object (account for example), I've got an error : INVALID_FIELD_FOR_INSERT_UPDATE

Unable to create/update fields: 
LastModifiedDate,
LastActivityDate, 
SystemModstamp,
LastReferencedDate,
LastModifiedById,
LastViewedDate,
CreatedById,
CreatedDate,
... and all my custom fields such as formulas, reference fields
IsDeleted.
Please check the security settings of this field and verify that it is read/write for your profile or permission set.

At first, i have all permissions...

When i get account, i actually get all fields using the results of "describeSObjects" on account.
Even if i don't need all fields (like IsDeleted, SystemModstamp), i need some fields like LastModifiedDate, CreatedDate to show them on a form or on a grid row.
I just want to edit a record, change some (editable) fields and update the record.
Is there a way to do that with this "full Account object" with this R/O fields (that i never modify of course)
or have i to duplicate the record in an another account object only with R/W fields ?

Here is my code to get the record / update the record :

        public SF.Account GetAccountWithId(SF.SforceService aSfdcBinding, string aId)
        {
            SF.Account Result = null;
            string SOQL;
            SF.QueryResult queryResult = null;
            // LstFieldsAccount contains all fields from account
            SOQL = string.Format("select "+String.Join(",", LstFieldsAccount.ToArray())+" from account where Id ='{0}'",aId);
            try
            {
                queryResult = aSfdcBinding.query(SOQL);
                if (queryResult != null)
                {
                    if (queryResult.size > 0)
                    {
                        SF.sObject[] TabRecords = queryResult.records;
                        Result = (SF.Account)TabRecords[0];
                    }
                }
            }
            catch (System.Web.Services.Protocols.SoapException e)
            {
                DoWriteError(string.Format(StringErrorSoapException, e.Message ,e.StackTrace));
            }
            return Result;
        }
   
    public bool DoModifyAccount(SF.SforceService aSfdcBinding, SF.Account aRecord)
        {           
            return DoModifyObject(aSfdcBinding, aRecord);                   
        }
       
        // To save all kinds of sobject
    public bool DoModifyObject(SF.SforceService aSfdcBinding, SF.sObject aRecord)
        {
            bool Result = true;
            try
            {               
                SF.SaveResult[] results = aSfdcBinding.update(new SF.sObject[] { aRecord });
                foreach (SF.SaveResult CurrentResult in results)
                {
                    if (CurrentResult.success)
                    {
                        Console.WriteLine("ID update : " + CurrentResult.id);
                    }
                    else
                    {                       
                        Result = false;
                       
                        SF.Error[] TabErrors = CurrentResult.errors;
                        if (TabErrors.Length > 0)
                        {
                            Console.WriteLine("Error : Unable to update " +
                                  "ID " + ResultatCourant.id + "."
                            );
                            Console.WriteLine("\tError is : (" +
                                  TabErrors[0].statusCode + ") " +
                                  TabErrors[0].message + "."
                            );
                        }
                    }
                }
            }
            catch (System.Web.Services.Protocols.SoapException e)
            {
                Result = false;
                AtlUtil.DoWriteError(string.Format(StringErrorSoapException, e.Message ,e.StackTrace));
            }
            return Result;
        }
SuperfellSuperfell
For updates you should create a new instance of the Account object, just set the fields you want to change and send that, Update specifically is based on partial updates, so you should only send what you want to change, so that you don't potentially overwrite another concurrent change of a field you're not changing.
Fabrice76Fabrice76
Ok, thanks Superfell but does it mean i've got to specifically use the changed fields by their name, or is there a way to check if a field is R/O or R/W...or if it had been changed. I'd like to write a generic proc...