We have external system that is pushing an event using Platform events saying that an asset is changed. I have created a Platform event object and a trigger on it, make a webservice callout to get the changed asset information and need to perform an upsert (We have a unique key on Asset object). However, I realized that platform event objects do not support external ids.

How do I perform an upsert without an external id? I can query the asset object and if the list size is greater than zero, update the asset record and if the list size is 0, I can insert a new asset.

Is there a better way of doing this?

1 Answer 1


The Platform Event itself doesn't need to have the data marked as an External Id.

If you have an External Id field on Asset, and receive data in your platform event that matches 0 or 1 value for that External Id field on Asset, then you can upsert.


Asset toBeUpserted = new Asset(
    My_External_Id_Field__c = myPlatformEvent.Regular_Text_Field__c

upsert tobeUpserted My_External_Id_Field__c;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .