Posts

Showing posts with the label Using Database.upsert with external ID field
External Id plays very important role if you want to update records without knowing the record Ids or want to relate the child record with parent record without knowing the parent record Id. As a best practice, you should always make External Id unique. If you are performing upsert with External Id, then following situations will occur: If no record is found in table with provided External Id, then it will create record in table. If 1 record is found in table with provided External Id, then it will update record in table. If more than 1 records is found in table with provided External Id, then system will throw an error. I am going to cover 2 different aspect of using external Id in apex. Updating a record with External Id Create a External Id field on Account as Account_Unique_Number__c and mark it as External Id and unique while creating it.Now we will create a new record using upsert. Execute below command in developer console List<Account> acclist=new list...