4

I am trying to update a record using an external Id in Apex. The syntax i have tried is given below.

update caserecs SAP_Notification_Number__c;

But the above statement throws compiler error. If i substituted update with upsert it works fine. Any suggestions please.

2

Update and Upsert are two different Data Manipulation Languague (DML) statements.

Update will only use the ID of records for matching. If it finds a match it will update the record with the data you've specified.

Insert will only creates new records. So you can't use insert to update an existing record.

Upsert is a combination of update and insert. It will update a record if it finds a matching ID or it will create the record if it does not find a matching ID. In addition, you can specify an External ID field which Upsert can use instead of the standard ID field.

You can get more information here: https://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_classes_iterable.htm|StartTopic=Content%2Fapex_classes_iterable.htm|SkinName=webhelp

| improve this answer | |
1

The reason here is actually pretty simply - update doesn't support external id. So you need to use upsert. Reference here: Link

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.