+ Start a Discussion
Tom Blamire 24Tom Blamire 24 



I am a complete virgin when it comes to code and i am looking to create a trigger that populates the 'Active' checkbox on the campaign object based on the start and end date (cant be formula). I have tried using workflow and process builder but this only seems only to work when campaign is edited rather than based on the criteria. (Yes i have used Scheduled Actions as well and criteria has been verified as being correct as well).

Is it possible to create this functionality using a trigger or does anyone have a better solution? 

Any help greatly appreciated

Mahesh DMahesh D
Hi Tom,

You can achieve this in 2 ways:

Option 1: Apex Trigger

You can use the trigger on Campaign before insert, before update and perform the Date check and populate the Active flag.

But if you go this option, the activte flag will not update at late point even though the dates are not valid at a later point. Hence going with Trigger may not help 100% if you want to maintain the falg by continuously checking the Date field values.

Option 2: Batch Apex

Assume that the flag is checked in the insert trigger, need to query all the records which are failing the Date check and populate then with false value to the active flag. As the Batch class runs every day, it will check every day and if something is invalid then it will mark it as false.

What I would recommend it,

You can use both option1 and option 2.

Option 1 will maintain the falg to true for all valid scenarios.
Option 2 will make sure that the falg is set to false for all invalid scenarios.

Please do let me know if it helps you.