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
MajMaj 

How to know if upsert updated or created?

I'm working on adding lead sources to newly created accounts-- is there a way to either a)know if an upsert did a create or an update or b)update a field only if there isn't already a value...

Basically, if an account was created manually, we don't want to overwrite the Source...

 

 

The only way I can see, is to do an additional query, test the result and then update if it's empty, but I feel like there should be a smarter way!

 


Thanks,

Michele

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell
UpsertResult contains a created flag that indicates if there was a new record created. not sure of an easy way to do (b) other than the write it in apex and call the apex webservice instead. (that'll at least reduce the number of round trips).

All Answers

SuperfellSuperfell
UpsertResult contains a created flag that indicates if there was a new record created. not sure of an easy way to do (b) other than the write it in apex and call the apex webservice instead. (that'll at least reduce the number of round trips).
This was selected as the best answer
MajMaj

That's what I was hoping!

Guess I just overlooked it...

 

Thanks for replying though the answer was somewhat obvious...

 

m