You need to sign in to do that
Don't have an account?
JosephT
Compile Error on Campaign Roll-Up Summary Trigger
I am receiving the error "Error: Compile Error: Variable does not exist: Campaigns at line 15 column 21" for this line of code in my trigger;
LINE 15: for (Campaign c : Campaigns.values())
HERE IS MY FULL CODE:trigger TotalCampaignServicePackagesAmountforTitleServices on Opportunity (after insert, after update) {
List<Campaign> campIds = new List<Campaign>();
for (Opportunity o : trigger.new){
if (o.CampaignID != null && (trigger.isInsert || o.Service_Packages_Amount__c != trigger.oldMap.get(o.id).Service_Packages_Amount__c))
campIds.add(o.Campaign);
}
if (campIds.size() > 0) {
Map<Id,Campaign> mapCampaigns = new Map<Id,Campaign>([select id from Campaign where Id in :campIds]);
for (Campaign c : Campaigns.values())
c.Total_Value_Services__c = 0;
for (Opportunity o : [SELECT id, Service_Packages_Amount__c, CampaignId FROM Opportunity WHERE CampaignId =: campIds]){
Campaign c = campaigns.get(o.CampaignId); c.Total_Value_Services__c += o.Service_Packages_Amount__c;
}
update campaigns.values();
}
}
Any help would be greatly appreciated.
LINE 15: for (Campaign c : Campaigns.values())
HERE IS MY FULL CODE:trigger TotalCampaignServicePackagesAmountforTitleServices on Opportunity (after insert, after update) {
List<Campaign> campIds = new List<Campaign>();
for (Opportunity o : trigger.new){
if (o.CampaignID != null && (trigger.isInsert || o.Service_Packages_Amount__c != trigger.oldMap.get(o.id).Service_Packages_Amount__c))
campIds.add(o.Campaign);
}
if (campIds.size() > 0) {
Map<Id,Campaign> mapCampaigns = new Map<Id,Campaign>([select id from Campaign where Id in :campIds]);
for (Campaign c : Campaigns.values())
c.Total_Value_Services__c = 0;
for (Opportunity o : [SELECT id, Service_Packages_Amount__c, CampaignId FROM Opportunity WHERE CampaignId =: campIds]){
Campaign c = campaigns.get(o.CampaignId); c.Total_Value_Services__c += o.Service_Packages_Amount__c;
}
update campaigns.values();
}
}
Any help would be greatly appreciated.
that shoud resolve the problem
Thanks
Thank you for your insight and feedback.
I updated my code based on your feedback and I am getting this error; Error: Compile Error: Invalid field Service_Packages_Amount__c for SObject Campaign at line 6 column 110
For this line; if (o.CampaignID != null && (trigger.isInsert || o.Service_Packages_Amount__c != trigger.oldMap.get(o.id).Service_Packages_Amount__c))
Here is the updated code;
trigger TotalCampaignServicePackagesAmountforTitleServices on Campaign (after insert,after update,after delete) {
List campIds = new List();
for (Opportunity o : trigger.new){
if (o.CampaignID != null && (trigger.isInsert || o.Service_Packages_Amount__c != trigger.oldMap.get(o.id).Service_Packages_Amount__c))
campIds.add(o.Campaign);
}
if (campIds.size() > 0) {
Map mapCampaigns = new Map([select id from Campaign where Id in :campIds]);
for (Campaign c : mapCampaigns.values())
c.Total_Value_Services__c = 0;
for (Opportunity o : [SELECT id, Service_Packages_Amount__c, CampaignId FROM Opportunity WHERE CampaignId =: campIds]){
Campaign c = mapCampaigns.get(o.CampaignId); c.Total_Value_Services__c += o.Service_Packages_Amount__c;
}
update mapCampaigns.values();
}
}
Thoughts?
________________________________________
if (o.CampaignID != null && (trigger.isInsert || o.Service_Packages_Amount__c != trigger.oldMap.get(o.id).Service_Packages_Amount__c))
campIds.add(o.Campaign);
}
above code is not correct as you are writing the trigger on Campaign and looping through opportunity .
and this line will give you the Campiagn object not the opportunity trigger.oldMap.get(o.id)
that is why it is saying field is not available .
Thanks
If I am trying to roll-up a Opportunity custom field to a Campaign level field, wouldn't I need to run the trigger against the campaign?
Joseph