You need to sign in to do that
Don't have an account?
AussieBattler
Problem with an Insert and Update Trigger
Hi. I have created a custom object (Enquiry__c) and when this object is created or updated I want it to create or update a Contact record. I have added a custom lookup field to the Contact object that captures the Enquiry__c unique ID.
I have got the creating part of the trigger working but am struggling on the update. If I try to update an Enquiry__c record I get an error message "MISSING_ARGUMENT, Id not specified in an update call". I realise I must need to locate the ID for the relevant Contact record but have not worked out how to do this. Following is my code:
If anybody coudl point me in the right direction it would be greatly appreciated.
Cheers.
I have got the creating part of the trigger working but am struggling on the update. If I try to update an Enquiry__c record I get an error message "MISSING_ARGUMENT, Id not specified in an update call". I realise I must need to locate the ID for the relevant Contact record but have not worked out how to do this. Following is my code:
Code:
trigger enquiryInsertContact on Enquiry__c (after insert, before update) { List<Contact> contacts = new Contact[0]; if (Trigger.isInsert) { for (Enquiry__c enq : Trigger.new) { contacts.add(new Contact (FirstName = enq.Enquiry_First_Name__c, LastName = enq.Enquiry_Surname__c, Salutation = enq.Salutation__c)); } insert contacts; } else if (Trigger.isUpdate) { for (Enquiry__c enq : Trigger.new) { contacts.add(new Contact (FirstName = enq.Enquiry_First_Name__c)); } update contacts; } }
If anybody coudl point me in the right direction it would be greatly appreciated.
Cheers.
For batch updates, though, this approach will quickly exceed the governor limits for SOQL calls. You will likely need to restructure this so that you can retrieve all the contact Ids in a single SOQL call. Psuedo-code ....
Good luck.
All Answers
For batch updates, though, this approach will quickly exceed the governor limits for SOQL calls. You will likely need to restructure this so that you can retrieve all the contact Ids in a single SOQL call. Psuedo-code ....
Good luck.