You need to sign in to do that
Don't have an account?
Travis Wright
expecting a semi-colon, found 'oppIdSet'
Hey Guys need another set of eyes on this as I am not sure why this is happening.
trigger Projectrollup on OpportunityLineItem (after insert, after update, before delete)
{
Set oppIdSet = new Set();
if(Trigger.isAfter)
for(OpportunityLineItem oli : Trigger.new)
oppIdSet.add(oli.OpportunityId);
if(Trigger.isBefore)
for(OpportunityLineItem oli : Trigger.old)
oppIdSet.add(oli.OpportunityId);
Map oppOldMap = new Map([Select Id, Implementation_Team__c, Training_Team__c From Opportunity Where Id IN :oppIdSet]);
Set oppImplementationTeamList = new Set();
Set oppTrainingTeamList = new Set();
List oliList = [Select UnitPrice, Quantity, PricebookEntry.Product2Id, TotalPrice,PricebookEntry.Product2.Name, Description,
Converted_to_Asset__c,Asset__c,PricebookEntry.Product2.Create_Asset__c, PricebookEntry.Product2.Sales_Order_Group__c, OpportunityId From OpportunityLineItem where
OpportunityId IN : oppIdSet And (PricebookEntry.Product2.Product_Reporting_Category__c = 'Services' or PricebookEntry.Product2.Name LIKE '%Communications%')];
for(OpportunityLineItem oli : oliList)
{
if(oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Hotline Services' || oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Policy Management Services' || oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Incident Management Services')
{
oppImplementationTeamList.add(oli.OpportunityId);
}
if(oli.PricebookEntry.Product2.Sales_Order_Group__c == 'ReadyTraining Services')
{
oppTrainingTeamList.add(oli.OpportunityId);
}
}
Map updateMap = new Map();
for(Id oppId : oppIdSet)
{
Opportunity opp = new Opportunity(Id = oppId, Implementation_Team__c = false, Training_Team__c = false);
updateMap.put(oppId, opp);
}
for(Id oppId : oppImplementationTeamList)
{
Opportunity opp = updateMap.get(oppId);
opp.Implementation_Team__c = true;
}
for(Id oppId : oppTrainingTeamList)
{
Opportunity opp = updateMap.get(oppId);
opp.Training_Team__c = true;
}
for(Opportunity oppOld : oppOldMap.values())
{
Opportunity oppNew = updateMap.get(oppOld.Id);
if(oppNew.Implementation_Team__c == oppOld.Implementation_Team__c && oppNew.Training_Team__c == oppOld.Training_Team__c)
updateMap.remove(oppOld.Id);
}
List updateList = updateMap.values();
if(updateList.size()>0)
update updateList;
}
trigger Projectrollup on OpportunityLineItem (after insert, after update, before delete)
{
Set oppIdSet = new Set();
if(Trigger.isAfter)
for(OpportunityLineItem oli : Trigger.new)
oppIdSet.add(oli.OpportunityId);
if(Trigger.isBefore)
for(OpportunityLineItem oli : Trigger.old)
oppIdSet.add(oli.OpportunityId);
Map oppOldMap = new Map([Select Id, Implementation_Team__c, Training_Team__c From Opportunity Where Id IN :oppIdSet]);
Set oppImplementationTeamList = new Set();
Set oppTrainingTeamList = new Set();
List oliList = [Select UnitPrice, Quantity, PricebookEntry.Product2Id, TotalPrice,PricebookEntry.Product2.Name, Description,
Converted_to_Asset__c,Asset__c,PricebookEntry.Product2.Create_Asset__c, PricebookEntry.Product2.Sales_Order_Group__c, OpportunityId From OpportunityLineItem where
OpportunityId IN : oppIdSet And (PricebookEntry.Product2.Product_Reporting_Category__c = 'Services' or PricebookEntry.Product2.Name LIKE '%Communications%')];
for(OpportunityLineItem oli : oliList)
{
if(oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Hotline Services' || oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Policy Management Services' || oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Incident Management Services')
{
oppImplementationTeamList.add(oli.OpportunityId);
}
if(oli.PricebookEntry.Product2.Sales_Order_Group__c == 'ReadyTraining Services')
{
oppTrainingTeamList.add(oli.OpportunityId);
}
}
Map updateMap = new Map();
for(Id oppId : oppIdSet)
{
Opportunity opp = new Opportunity(Id = oppId, Implementation_Team__c = false, Training_Team__c = false);
updateMap.put(oppId, opp);
}
for(Id oppId : oppImplementationTeamList)
{
Opportunity opp = updateMap.get(oppId);
opp.Implementation_Team__c = true;
}
for(Id oppId : oppTrainingTeamList)
{
Opportunity opp = updateMap.get(oppId);
opp.Training_Team__c = true;
}
for(Opportunity oppOld : oppOldMap.values())
{
Opportunity oppNew = updateMap.get(oppOld.Id);
if(oppNew.Implementation_Team__c == oppOld.Implementation_Team__c && oppNew.Training_Team__c == oppOld.Training_Team__c)
updateMap.remove(oppOld.Id);
}
List updateList = updateMap.values();
if(updateList.size()>0)
update updateList;
}
In List Map and set you are not using <Type> That is why you are getting error.
Please try below code. I hope that will resolve your issue.
Please let us know if this will help you
All Answers
issue is with init of different collection items. For example check the set initialisation
it should be
set<type> variable name = new set<type>();
Same with the Map
Here is the the detailed document
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_set.htm#apex_methods_system_set
In List Map and set you are not using <Type> That is why you are getting error.
Please try below code. I hope that will resolve your issue.
Please let us know if this will help you
Is there any way that I can call this trigger to run when ever the opportunity is edited? It is working but the functionality is not exactly what I was looking for. As when the Sales Reps delete the OLI it will fire but if they delete the product that is driving this trigger last the opportunity won't update.
I first tried to write the trigger on the opportunity to call and @future Class but couldn't get it to uncheck the box when the OLI was removed.
Thanks again for correcting my mistake but additional help would be great.
The following products are selected when the opportunity is created, Tier 1 Standard Hotline Implementation, Training Implementation (1 Course), Domestic Hotline, and 1 Training Course (1 Year).
During the discovery process the sales rep finds out that the Prospect is only intrested in the Hotline and not the training product. If the sales rep Deletes the 1 Training Course (1 Year) and then deletes Training Implementation (1 Course) the opportunity doesn't update to show that the training_Team__c = false. If the sales rep reverses the order in which they delete the products it works fine. But being that this is for Sales I can expect them to follow this kind of process.
Idealy I would be writing a trigger that will always check the products on the opportunity when Stage = Closed Won and update these field according to the products selected.
I hope that helps let me know if you need additional details.