You need to sign in to do that
Don't have an account?

Trigger Help - Campaign to Campaign Member objects - Rich Text
Hi there,
I'm very new to Apex Triggers, so apologies if this is a silly question...
I'm trying to get a Rich Text field on my Campaign object - Extra_Info_for_Reminder__c - to populate a Rich Text field on my Campaign Member object - Course_Email_Info_2__c. As far as I understand, copying the fields via a workflow strips the text of any HTML (which we need to retain).
In Developer Console the following code doesn't show up with any errors, but it not currently providing the desired affect...
Hopefully there's a very simple explaination. As I say, bit of a fish out of water with this stuff, so any help is much appreciated.
Thanks very much.
I'm very new to Apex Triggers, so apologies if this is a silly question...
I'm trying to get a Rich Text field on my Campaign object - Extra_Info_for_Reminder__c - to populate a Rich Text field on my Campaign Member object - Course_Email_Info_2__c. As far as I understand, copying the fields via a workflow strips the text of any HTML (which we need to retain).
In Developer Console the following code doesn't show up with any errors, but it not currently providing the desired affect...
trigger richtextupdate on Campaign (after update, after insert) {
for(Campaign C:trigger.new){
if(C.Extra_Info_for_Reminder__c!=null){
CampaignMember.Course_Email_Info_2__c=C.Extra_Info_for_Reminder__c;
}
}
}
for(Campaign C:trigger.new){
if(C.Extra_Info_for_Reminder__c!=null){
CampaignMember.Course_Email_Info_2__c=C.Extra_Info_for_Reminder__c;
}
}
}
Hopefully there's a very simple explaination. As I say, bit of a fish out of water with this stuff, so any help is much appreciated.
Thanks very much.
Give this a try. This works:
trigger CampaignTrigger on Campaign (after insert, after update) {
List<CampaignMember> memberList=new List<CampaignMember>();
Map<Id,Campaign> CampMemMap=new Map<Id,Campaign>([select id, (select id from CampaignMembers) from Campaign
where id IN: Trigger.new]);
for(Campaign c: Trigger.new){
if(c.Extra_Info_for_Reminder__c!=null && CampMemMap.get(c.id).CampaignMembers.size()>0){
memberList.addAll(CampMemMap.get(c.id).CampaignMembers);
for(CampaignMember m: memberList){
m.Course_Email_Info_2__c=c.Extra_Info_for_Reminder__c;
}
}
}
if(memberList.size()>0){
update memberList;
}
}
Thanks
All Answers
Can you please try before update and before insert?
After triggers are used to access field values that are set by the system (such as a record's Id or LastModifiedDate field), and to effect changes in other records. The records that fire the after trigger are read-only.
Thanks,
Shyama.
I have tried that, and its still not populating.
I've had a little route around and strangely - when I enter the code via Developer Console, this is how it comes through in the 'Triggers' view:
I'm guessing this is probably the issue? That the code isn't actually running as I've entered it.
Thanks!
Hi Patrick,
Can you try entering the code through developer console?
Setup -> Build -> Apex Triggers -> Developer Console
Click on File -> new Apex Trigger
Enter the code, Save and try again.
Thanks,
Shyama
Patrick
Give this a try. This works:
trigger CampaignTrigger on Campaign (after insert, after update) {
List<CampaignMember> memberList=new List<CampaignMember>();
Map<Id,Campaign> CampMemMap=new Map<Id,Campaign>([select id, (select id from CampaignMembers) from Campaign
where id IN: Trigger.new]);
for(Campaign c: Trigger.new){
if(c.Extra_Info_for_Reminder__c!=null && CampMemMap.get(c.id).CampaignMembers.size()>0){
memberList.addAll(CampMemMap.get(c.id).CampaignMembers);
for(CampaignMember m: memberList){
m.Course_Email_Info_2__c=c.Extra_Info_for_Reminder__c;
}
}
}
if(memberList.size()>0){
update memberList;
}
}
Thanks
Is there a quick addition we could make to this so that this trigger (or a new trigger) is launched from the CampaignMember object (when it's inserted or edited) that would perform this same function, and pull this same Rich Text data from the related Campaign object?
Thanks again!