You need to sign in to do that
Don't have an account?

Trigger to fire before delete
Hi All,
Please help me with this trigger. It currently calls a class called webservicecallout and send notification method on insert and update actions. I want it to also call this class and method once the contact is deleted.. Please help
Many Thanks in advance
Abraham
Please help me with this trigger. It currently calls a class called webservicecallout and send notification method on insert and update actions. I want it to also call this class and method once the contact is deleted.. Please help
trigger Contactcall on Contact (after insert, after update) { Map<Id, String> m = new Map<Id, String>(); list<Contact> validContacts = new list<Contact>(); set<ID> accIds = new set<ID>(); for (contact c : Trigger.new) { if(c.RecordTypeId == '012D7865454BaFA' && c.Reg__c == TRUE){ if(Trigger.isUpdate){ contact old = Trigger.oldMap.get(c.Id); if (c.Email != old.Email||c.FirstName!=old.FirstName||c.LastName!=old.LastName||c.phone!=old.phone||c.Title__c!=old.Title__c||c.status__c!=old.status__c||c.AccountID!=old.AccountID) { validContacts.add(c); accIds.add(c.accountid); } }else{ validContacts.add(c); accIds.add(c.accountid); } } map<ID, Account> accMap; if(!accIds.IsEmpty()) // guard condition for SOQL accMap = new map<ID, Account>([select name from account where id in :accIds]); for (contact c1 : validContacts) { Account acc = accMap.get(c.AccountID); string accName = acc == null ? null : acc.Name; WebServiceCallout.sendNotification(c.Id,c.Email,c.FirstName,c.LastName,c.phone,c.Title__c,accName,c.status__c); } } }
Many Thanks in advance
Abraham
Please try with the updated snippet below. Please paste the code as it is without making any changes.
All Answers
Please let us know if this will help you
Thanks
Amit Chaudhary
Thank you soo much for helping me again..
Im getting this below error on deleting
Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger Contactcallout caused an unexpected exception, contact your administrator: Contactcallout: execution of BeforeDelete caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.Contactcallout: line 16, column 1".
Many Thanks
Abraham
Can you try Amit's snippet with the "after delete" event, keeping the rest of the code as it is.
Thanks Akhil...But still the same error
Thanks
Abraham
Are you sure that you are getting the error from this trigger itself, becasue the error message states that the error is in the "
trigger Contactcallout" whereas the trigger you posted here is named trigger Contactcall.
Yes it is both the same
Thanks
Abraham
They both are the same i had just edited the name to Contactcall while posting here. The actual trigger name is contactcallout.
Thanks
Abraham
Im still getting the same error.
Thanks
Abraham
for (contact c : Trigger.new) {
Thanks
Abraham
Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger Contactcallout caused an unexpected exception, contact your administrator: Contactcallout: execution of BeforeDelete caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.Contactcallout: line 19, column 1".
Click here to return to the previous page.
You were not including the "else" block in Amit's code, hence the error creeped in.
Please let us know if this will help you
Error: Compile Error: Variable does not exist: c.AccountID at line 42 column 30
This line---> Account acc = accMap.get(c.AccountID);
Thanks
Abraham
The below code should resolve the compilation error.
No i did not work.. but changing it as below saves the code but it is not making the callout on delete action. It is not calling sendnotification method
It is only deleting
Any Suggestions. Please let me know
Thanks
Abraham
Below is the code which compiles successfully and works on insert and update but does not trigger in delete alone. PLease can you help me with any suggestions
Many Thanks in advance
Abraham
Please try with the updated snippet below. Please paste the code as it is without making any changes.