function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Teach_me_howTeach_me_how 

How to avoid campaign trigger when deleting campaign member?

I believe deleting campaign member will call the trigger on campaign because of roll up for "NumberOfContacts" but i want to avoid my custom trigger ? what is the workaround for this?

blueflame121blueflame121

Sure the trigger will fire beacuse of change in related list and change in rollup . if you add the below logic in starting of the trigger 

 

if(Trigger.New[0].total_number_of_contacts__c ==trigger.old[0].total_number_of_contacts__c)
{

////  all the trigger logic 

}

 

that will not cause the trigger to perform any action whn there will be a change in "NumberOfContacts"

 

Not very sure if we are able to stop execution on the trigger . hope this hepls .......

 

 

Teach_me_howTeach_me_how

NumberOfContacts is standard field from salesforce . The weird part is when i delete campaignmeber then check the value of  NumberOfContacts both old and new always has same value so i cannot define if condition in my trigger

blueflame121blueflame121

in case of standard field ,Trigger will not get fire . check in your debug log then you will be sure . 

Teach_me_howTeach_me_how

i have no trigger in campaign member. In user interface i delete 1 campaign member under campaign record. and i see in debug log that it goes to campaign trigger. how to avoid to go to campaign trigger if i only deleting campaign member .

see below debug log

 

26.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
02:45:17.262 (262040000)|EXECUTION_STARTED
02:45:17.262 (262081000)|CODE_UNIT_STARTED|[EXTERNAL]|TRIGGERS
02:45:17.262 (262108000)|CODE_UNIT_STARTED|[EXTERNAL]|01qc0000000CjBw|preventInvalidMember on Campaign trigger event BeforeUpdate for [701c000000011vm]
02:45:17.263 (263984000)|SYSTEM_CONSTRUCTOR_ENTRY|[3]|<init>(Integer)
02:45:17.264 (264041000)|SYSTEM_CONSTRUCTOR_EXIT|[3]|<init>(Integer)
02:45:17.264 (264247000)|SYSTEM_CONSTRUCTOR_ENTRY|[5]|<init>(Integer)
02:45:17.264 (264285000)|SYSTEM_CONSTRUCTOR_EXIT|[5]|<init>(Integer)
02:45:17.264 (264450000)|SYSTEM_METHOD_ENTRY|[8]|LIST<Campaign>.size()
02:45:17.264 (264492000)|SYSTEM_METHOD_EXIT|[8]|LIST<Campaign>.size()
02:45:17.265 (265465000)|SYSTEM_METHOD_ENTRY|[10]|SET<Id>.add(Object)
02:45:17.265 (265513000)|SYSTEM_METHOD_EXIT|[10]|SET<Id>.add(Object)
02:45:17.265 (265540000)|SYSTEM_METHOD_ENTRY|[8]|LIST<Campaign>.size()
02:45:17.265 (265551000)|SYSTEM_METHOD_EXIT|[8]|LIST<Campaign>.size()
02:45:17.265 (265575000)|SYSTEM_METHOD_ENTRY|[14]|SET<Id>.size()