As I have research we can update the record based on either External Id or Indexed field.
Account object has Name field with an Indexed attribute.
Id accountId = 'XXXXXXXXXXXXXXX'; // 15 Char Account record id // Retrive acccount record based on Id. Account acc = [Select Id, Name from Account where Id =: accountId]; // Update account record. acc.Site = 'www.google.com'; // Retrive Name SobjectField. Schema.SObjectField NameField = Schema.getGlobalDescribe().get('Account').getDescribe().fields.getMap().get('Name'); // Upsert record based on name field. Database.upsert(acc, NameField, true);
Note: Here I am passing Name field for update account record.
I am getting an error.
System.SObjectException: Invalid field for upsert, must be an External Id custom or standard indexed field: Name
I have passed standard Name field for upsert still it was giving error which said that pass standard Name field.
I am not able to figure it out where is the issue. anyone has any Idea? Why am I not able to update account record using Name field?