I'm attempting to create a trigger that fires when my custom field "Retreat Role", on a campaign member becomes "Prospect". Now when they become a prospect I want to create a task for the user, that reminds them to create a follow up after 5 days from the day the trigger is fired. I have found a similar trigger to what I am looking for, but I am by no means much of a coder. Now I'm not completely sure how to make it so that the due date (ActivityDate) on my Task is presented as 5 days after the date that my trigger fires. I was wondering if anyone could help me with this.

trigger InsertCompletedCallTask on CampaignMember (BEFORE update) {
    list<Task> AddTask = new List<Task>();

    for (CampaignMember CM : Trigger.new) {

        if (cm.Retreat_Role__c == 'Prospect') {
            system.debug(cm + '---------AddTask---------' + CM.Campaign);
            AddTask.add(new Task(
                            Subject = 'Follow up with Prospect',
                            ActivityDate = date.today + 5,
                            WhoId = CM.Contact.AccountId,
                            WhatId = CM.CampaignId));

    insert AddTask;
  • Tony, were you able to deploy this trigger? I have been having the worst time writing a test class for this and I would LOVE your guidance!!! Jan 14 '15 at 23:14

Just read the documentation about things which you use.

 Date myDate = Date.newInstance(1960, 2, 17);
 Date newDate = mydate.addDays(5);

Hi simply use this below code if the error is related to Activitydate :

ActivityDate = Date.Today().addDays(5)

and always try to insert the list by checking the list size. For Example: If(AddTask != null && AddTask.size()>0) then insert AddTask

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.