1. CampaignMember の変更記録を保存する「CampaignMemberHistory」(CampaignHistory__c など) というカスタムオブジェクトを作成します。
Trigger HistoryTrack on CampaignMember (after insert, before update, before delete) {
List<CampaignHistory__c> ch= new List<CampaignHistory__c>();
List<CampaignMember> cmOld= Trigger.old;
List<String> changes = new List<String>();
List<String> CampHisId = new List<String>();
integer i=0;
if(Trigger.isDelete){
for(CampaignMember cm: Trigger.old ){
String s;
s='Campaign Member id ' + cm.id +
'is Deleted from campaign id: '+ cm.campaignId + 'by user '+ userinfo.getUserName();
changes.add(s);
CampHisId.add(cm.campaignId);
CampaignHistory__c c= new CampaignHistory__c();
c.Name='History'+DateTime.now();
System.debug('CName:'+c.Name);
c.CampaignId__c=CampHisId[i];
System.debug('CampaignId:'+c.CampaignId__c);
c.HistoryDetails__c=changes[i];
System.debug('CHistory:'+c.HistoryDetails__c);
ch.add(c);
i++;
}
}else {
Trigger.new ){
if((Trigger.isUpdate)){
if(cmOld[i].status!=cm.status){
s='on dated ' + DateTime.now() +
' status changed from ' + cmOld[i].status + ' to ' + cm.status +
' by user ' + userinfo.getUserName();
changes.add(s);
CampHisId.add(cm.campaignId);
c.Name='History'+DateTime.now();
System.debug('CName:'+c.Name);
c.CampaignId__c=CampHisId[i];
System.debug('CampaignId:'+c.CampaignId__c);
c.HistoryDetails__c=changes[i];
System.debug('CHistory:'+c.HistoryDetails__c);
ch.add(c);
}else if(cmOld[i].campaignId!=cm.campaignId){
s='Changed Campaign id from : '+ cmOld[i].campaignId + 'to :' + cm.campaignId +
' by user '+ userinfo.getUserName();
changes.add(s);
CampHisId.add(cm.campaignId);
c.Name='History'+DateTime.now();
System.debug('CName:'+c.Name);
c.CampaignId__c=CampHisId[i];
System.debug('CampaignId:'+c.CampaignId__c);
c.HistoryDetails__c=changes[i];
System.debug('CHistory:'+c.HistoryDetails__c);
ch.add(c);
}
}else if(Trigger.isInsert){
s='A new Campaign Member id : ' + cm.id + ' is added to Campaign id :' + cm.campaignId +' by user '+ userinfo.getUserName();
changes.add(s);
CampHisId.add(cm.campaignId);
System.debug('s>>>'+s);
c.Name='History'+DateTime.now();
System.debug('CName:'+c.Name);
c.CampaignId__c=CampHisId[i];
System.debug('CampaignId:'+c.CampaignId__c);
c.HistoryDetails__c=changes[i];
System.debug('CHistory:'+c.HistoryDetails__c);
ch.add(c);
}
}
}
insert ch;
}
|
4. キャンペーンに移動して [レイアウトを編集する] をクリックし、作成した [キャンペーン履歴] を選択してその他の必須項目を追加し、[保存] をクリックします。
これはサンプルコードであり、シナリオによっては動作しない場合があります。要件に合わせてコードを編集し、調整してください。
000385967

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.