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
lolly133lolly133 

Can anyone help me with this trigger??

Hi All

Have created this trigger to create a in opt in trial record when the opt in checkboxs are changed on the contact..
Have created this trigger on the contact record but it doesnt seem to do anything.. have gone through the debug logs and it is being stepped through but nothing happens.. any help would be much appreciated.


trigger CreateOptInTrail on Contact (after insert, after update){
    
    List <Opt_In_Trial__c> optToInsert = new List <Opt_In_Trial__c>();

        for (Contact c : Trigger.new){
        System.debug('Hello');

            if (c.Channel__c != null ){
System.debug('Hello123');
    Opt_In_Trial__c o = new Opt_In_Trial__c ();
    
    
        o.Contact__c = c.Id;
        o.Channel__c = c.Channel__c;System.debug('channel');
        o.Email_Opt_In__c = c.Email_Opt_In__c;System.debug('Email');
        o.Phone_Opt_In__c = c.Phone_Opt_In__c;System.debug('Phone');
        o.Post_Opt_In__c = c.Post_Opt_In__c;System.debug('Post');
        o.SMS_Opt_In__c = c.SMS_Opt_In__c;System.debug('SMS');
       

    optToInsert.add(o);
}

}
Best Answer chosen by lolly133
MithunPMithunP
Hi lolly133,

Try this trigger code.
 
trigger CreateOptInTrail on Contact (after insert, after update){
    
    List <Opt_In_Trial__c> optToInsert = new List <Opt_In_Trial__c>();

        for (Contact c : Trigger.new){
        System.debug('Hello');

            if (c.Channel__c != null ){
System.debug('Hello123');
    Opt_In_Trial__c o = new Opt_In_Trial__c ();
    
    
        o.Contact__c = c.Id;
        o.Channel__c = c.Channel__c;System.debug('channel');
        o.Email_Opt_In__c = c.Email_Opt_In__c;System.debug('Email');
        o.Phone_Opt_In__c = c.Phone_Opt_In__c;System.debug('Phone');
        o.Post_Opt_In__c = c.Post_Opt_In__c;System.debug('Post');
        o.SMS_Opt_In__c = c.SMS_Opt_In__c;System.debug('SMS');
       

    optToInsert.add(o);
}
}
Insert optToInsert;

}

Best Regards,
Mithun.

All Answers

MithunPMithunP
Hi lolly133,

Try this trigger code.
 
trigger CreateOptInTrail on Contact (after insert, after update){
    
    List <Opt_In_Trial__c> optToInsert = new List <Opt_In_Trial__c>();

        for (Contact c : Trigger.new){
        System.debug('Hello');

            if (c.Channel__c != null ){
System.debug('Hello123');
    Opt_In_Trial__c o = new Opt_In_Trial__c ();
    
    
        o.Contact__c = c.Id;
        o.Channel__c = c.Channel__c;System.debug('channel');
        o.Email_Opt_In__c = c.Email_Opt_In__c;System.debug('Email');
        o.Phone_Opt_In__c = c.Phone_Opt_In__c;System.debug('Phone');
        o.Post_Opt_In__c = c.Post_Opt_In__c;System.debug('Post');
        o.SMS_Opt_In__c = c.SMS_Opt_In__c;System.debug('SMS');
       

    optToInsert.add(o);
}
}
Insert optToInsert;

}

Best Regards,
Mithun.
This was selected as the best answer
lolly133lolly133
Thats brillant! thanks so much...