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
vinni shreevinni shree 

Insert or Upsert

Hi,
I have one custom object now when user creates record it should be inserted in the custom object and it should relate to the existing contact and this contact has one external ID field so this custom record should relate it to the external ID filed now should I use insert followed by an update or can I use upsert on the custom object by specifying the relationship of external object.
Thank you 
Best Answer chosen by vinni shree
SubratSubrat (Salesforce Developers) 
Hello Vinni ,

You can use upsert operation to insert a new record in the custom object and relate it to an existing contact using the external ID field.

When using upsert, you can specify the external ID field and its value for the related contact object in the external ID mapping of the custom object. This will ensure that the new record is related to the correct contact based on its external ID value.

Using insert followed by an update can also achieve the same result, but it would require two separate API calls and may not be as efficient as using upsert. 

If the above information helps , please mark this as Best Answer.
Thank you.

All Answers

SubratSubrat (Salesforce Developers) 
Hello Vinni ,

You can use upsert operation to insert a new record in the custom object and relate it to an existing contact using the external ID field.

When using upsert, you can specify the external ID field and its value for the related contact object in the external ID mapping of the custom object. This will ensure that the new record is related to the correct contact based on its external ID value.

Using insert followed by an update can also achieve the same result, but it would require two separate API calls and may not be as efficient as using upsert. 

If the above information helps , please mark this as Best Answer.
Thank you.
This was selected as the best answer
vinni shreevinni shree
Hi Vinni Thank you