You need to sign in to do that
Don't have an account?
Trigger old fields v new
Hi there we are going to pull our users details name, email etc from a portal site onto their contact record in SFDC to allow us to compare the values. We will also include an auto update trigger checkbox that allows the contact owner to accept the portal site as the source of truth and overwrite the contact fields. The code below does this but a new requirement has arisen that means the trigger should only fire if any of the Portal fields have changed.
In a formula id just use ischanged(c.strPortalTitle__c) but I doubt that'll work in apex triggers :-)
"trigger AutoUpdate on Contact (after delete, after insert, after undelete,
after update, before delete, before insert, before update) {
if (trigger.isBefore){
if (trigger.isInsert || trigger.isUpdate){
for (Contact c : trigger.new){
if (c.intAutomaticallyUpdate__c){
if (c.Salutation != c.strPortalTitle__c) c.Salutation = c.strPortalTitle__c;
//Multiselect picklist fields
if (c.strMarketingOptOutPreference__c != c.strPortalMarketingOptOutPreference__c) c.strMarketingOptOutPreference__c = c.strPortalMarketingOptOutPreference__c;
if (c.strCompanyPeerGroupFocus__c != c.strPortalCompanyPeerGroupFocus__c) c.strCompanyPeerGroupFocus__c = c.strPortalCompanyPeerGroupFocus__c;
if (c.Commodity_Fuel_Focus__c != c.strPortalCommodityFuelFocus__c) c.Commodity_Fuel_Focus__c = c.strPortalCommodityFuelFocus__c;
if (c.Regional_Focus__c != c.strPortalRegionalFocus__c) c.Regional_Focus__c = c.strPortalRegionalFocus__c;"
Thanks in advance for your help
Paul
You want something similar to:-
ischanged(c.strPortalTitle__c) in your trigger.
Try using trigger.new and trigger.old
say :-
Map<id,contact> aMap = new Map<id,account>(trigger.oldMap.keySet(), trigger.oldMap());
for (Contact c : trigger.newMap)
{
if(c.strPortalTitle__c != aMap.get(c.id).strPortalTitle__c)
{
Now ur code here
}
else
{
Do NMothing
}
}
hope this helps!!
Thanks and regards,
Ispita Saha