triggers - Get Account name from contact object -
please want account.name account object contact (after iupdate) trigger. below trigger.but giving null c.account.name..
trigger contactcallout on contact (after update) { map<id, string> m = new map<id, string>(); (contact c : trigger.new) { if(c.recordtypeid == '012d0000000bafa'){ contact old = trigger.oldmap.get(c.id); if (c.email != old.email||c.firstname!=old.firstname||c.lastname!=old.lastname||c.phone!=old.ph one||c.title__c!=old.title__c||c.account.name!=old.account.name) { webservicecallout.sendnotification(c.id,c.email,c.firstname,c.lastname,c.phone,c .title__c,c.account.name); } } } }
parent fields values not accessible trigger.new, need retrieve them soql. check trigger below:
trigger contactcallout on contact (after update) { map<id, string> m = new map<id, string>(); (contact c : [select id, email, firstname, lastname, phone, title__c, account.name account id in: trigger.new]) { if(c.recordtypeid == '012d0000000bafa'){ 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.account.name != old.account.name) { webservicecallout.sendnotification(c.id, c.email, c.firstname, c.lastname, c.phone, c.title__c, c.account.name); } } } }
try above code, , 1 more thing should never hardcode record id in apex.
(edit: reason doesn't allow me post trigger code, added html comment.)
Comments
Post a Comment