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
Raj R.Raj R. 

What is the recommended way to check is the Campaign Start date change in apex trigger?

Hi,

I am using an apex trigger to create events that are based on the campaign start date. So when the campaign start date changes, i want to update the events and only when the start date changes. 

What is the best way to check if the start date field value changed? I am having difficulty finding a good way to compare the date fields prior and current values. 
Best Answer chosen by Raj R.
Nisar799Nisar799
Hello rRup,

If you want to check that Campaign Start Date chaged in apex Trigger, then I would suggest you to trace everything in the trigger. Because we can trace that if any field's value is changed from prior value in the trigger. Here is the sample code.
trigger <YOUR Trigger Name> on Campaign (before update) {
    for(Campaign c : Trigger.new){
        if(c.StartDate != Trigger.oldMap.get(c.id).StartDate){
            // StartDate is changed
            // Your logic will go here when startDate is changed.
        }
    }
}

Thanks,
799 Coder.

All Answers

SRKSRK
one way is simple workflow 

Ischange(DateField) and this worrkflow update a field example campaign start date counter and in trigger you can check for number field that if it increse by one form old value then you can process your logic

what is the issues you are facing in comapring date field in trigger actully 
Nisar799Nisar799
Hello rRup,

If you want to check that Campaign Start Date chaged in apex Trigger, then I would suggest you to trace everything in the trigger. Because we can trace that if any field's value is changed from prior value in the trigger. Here is the sample code.
trigger <YOUR Trigger Name> on Campaign (before update) {
    for(Campaign c : Trigger.new){
        if(c.StartDate != Trigger.oldMap.get(c.id).StartDate){
            // StartDate is changed
            // Your logic will go here when startDate is changed.
        }
    }
}

Thanks,
799 Coder.
This was selected as the best answer