You need to sign in to do that
Don't have an account?
Sunil m
How to know whether upsert statement inserted or updated record after executing upsert statement
Hi all,
I used upsert sObject; statement , after executing this statement I need to know upsert is inserted or updated record
yes, there is a class call upsertResult, and use isCreated() method to determine whether is insert or update
like this
Database.UpsertResult[] urList = Database.upsert(list, opt); for (Database.UpsertResult ur : urList) { if (ur.isCreated()) { //dosomething } }
more infomation:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_Database_UpsertResult_instance_methods.htm
All Answers
hello,
in trigger events, there are insert trigger and update trigger,
you can create two seprerate triggers to do different actions,
or you can create one insert,update trigger , in this case, you can use if (Trigger.isInsert) and if (Trigger.isUpdate) to perform different actions.
Actually I don't have requirement to implement trigger here, My requirement is If upsert stmt performs insert operation I need to add this new record to List if updated then I need to replace existing record in List . So I need to know that in controller.
yes, there is a class call upsertResult, and use isCreated() method to determine whether is insert or update
like this
Database.UpsertResult[] urList = Database.upsert(list, opt); for (Database.UpsertResult ur : urList) { if (ur.isCreated()) { //dosomething } }
more infomation:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_Database_UpsertResult_instance_methods.htm
Hello,
you could use Database.upsert for your DML and check the isCreated of the UpsertResult.
Good luck.
hi sunil
when ever we use Upsert statement, in salesforce Inserting and Updating records automatically.