You need to sign in to do that
Don't have an account?
laxmi narayan 11
Campaign Status
Hi there,
I have an object Campaign_Follow_Up_Stage__c, On this object, I have a Campaign Lookup.
On Campaign_Follow_Up_Stage__c object, there are some record which status is "completed", If the status of any of these records
changes, supposed I changed the status of one record "Completed" to "Planned" then Campaign status field changed
the value "In-progress".
* If all records status is completed then-campaign status field value is Completed.
* If all records status is Planned then-campaign status field value is In-progress.
* If all records status is Draft then-campaign status field value is Planned.
* If one of it's record status is planned then-campaign status field value is In-progress.
* If one of it's record status is Draft then-campaign status field value is planned.
trigger updateCampaignStatus on Campaign_Follow_Up_Stage__c (after Update,after insert) {
//list<Campaign_Follow_Up_Stage__c> cList = new list<Campaign_Follow_Up_Stage__c>();
set<Id> campIds = new set<Id>();
for(Campaign_Follow_Up_Stage__c c : trigger.new){
campIds.add(c.Campaign__c);
}
List<Campaign> cmList = new List<Campaign>();
for(Campaign cam:[SELECT Id,(SELECT Id,Name,status__c ,Campaign__c FROM Campaign_Follow_Up_Stages__r order by Name) FROM Campaign WHERE Id IN :campIds]){
for(Campaign_Follow_Up_Stage__c c:cam.Campaign_Follow_Up_Stages__r){
if(c.status__c == 'Completed'){
cam.status ='Completed';
}
if(c.status__c =='Planned'){
cam.status ='In Progress';
}
if(c.status__c =='Draft'){
cam.status ='Planned';
}
cmList.add(cam);
}
}
update cmList;
}
Any help appreciated
Thanks
L.N
I have an object Campaign_Follow_Up_Stage__c, On this object, I have a Campaign Lookup.
On Campaign_Follow_Up_Stage__c object, there are some record which status is "completed", If the status of any of these records
changes, supposed I changed the status of one record "Completed" to "Planned" then Campaign status field changed
the value "In-progress".
* If all records status is completed then-campaign status field value is Completed.
* If all records status is Planned then-campaign status field value is In-progress.
* If all records status is Draft then-campaign status field value is Planned.
* If one of it's record status is planned then-campaign status field value is In-progress.
* If one of it's record status is Draft then-campaign status field value is planned.
trigger updateCampaignStatus on Campaign_Follow_Up_Stage__c (after Update,after insert) {
//list<Campaign_Follow_Up_Stage__c> cList = new list<Campaign_Follow_Up_Stage__c>();
set<Id> campIds = new set<Id>();
for(Campaign_Follow_Up_Stage__c c : trigger.new){
campIds.add(c.Campaign__c);
}
List<Campaign> cmList = new List<Campaign>();
for(Campaign cam:[SELECT Id,(SELECT Id,Name,status__c ,Campaign__c FROM Campaign_Follow_Up_Stages__r order by Name) FROM Campaign WHERE Id IN :campIds]){
for(Campaign_Follow_Up_Stage__c c:cam.Campaign_Follow_Up_Stages__r){
if(c.status__c == 'Completed'){
cam.status ='Completed';
}
if(c.status__c =='Planned'){
cam.status ='In Progress';
}
if(c.status__c =='Draft'){
cam.status ='Planned';
}
cmList.add(cam);
}
}
update cmList;
}
Any help appreciated
Thanks
L.N
Hi,
Please try below code, As I am unable to understand which case has a priority higher :
* If one of it's record status is planned then-campaign status field value is In-progress.
* If one of it's record status is Draft then-campaign status field value is planned.
so I assumed if any of the record's status is draft than campaign should be planned and if no record in the draft but any one record is in planned then-campaign should be in-progress.
let me know if you have any issues. If it fixed your problem please mark it as the best answer, it will help others having the same issue.