I have been trying to create this trigger and its not working. I'm not getting any errors, but an opportunity product is not being added to the opportunity automatically. I'm not sure why.
Here is the code:
trigger AUTOADDPRODUCTAttempt1 on OpportunityLineItem (after insert) {
List<OpportunityLineItem> OpportunityLineItems = new List<OpportunityLineItem>();
for (OpportunityLineItem newOpportunityLineItemsitem: Trigger.New)[
{ SELECT OpportunityId, Name
FROM OpportunityLineItem
WHERE if(newOpportunityLineItemsId = :Trigger.new AND Name === 'CarOIL''Car_Filter_Plus']) {
OpportunityLineItems.add(new OpportunityLineItem(PricebookEntryId
='ID CODE FOR CarOILplus',Quantity = 1,UnitPrice OpportunityId = 25));item.OpportunityId,
}
}PricebookEntryId ='01uA000000QdelEIAD',
if(!OpportunityLineItems.isEmpty()){ Quantity = 1,
insert OpportunityLineItems; UnitPrice = 25)
);
}
}
Ideally, here is what I need the code to do:
We have a lot of additional cost products that need to be be added to the opportunity whenever a product is added to the opportunity by the proposal team. The $ value of the additional cost needs to be a % of the product added by the proposal writer. I came across a couple codes online but have not been able to get very far. Here is one that I came across:
Proposal writer adds the following products
- CarOIL
- CarFILTER
- CarTIRE'
- CarLIGHTS
The $ value is manually added by the writer in SFDC. They put the quantity and sale price and it auto calculates
Here is what I need the code to automatically add to the opportunity
- CarOILplus
- CarFILTERplus
- CarTIREplus
- CarLIGHTSplus
The $ value of each plus product is a % of the original product, which has a dollar value entered by the writer. For example:
CarOILplus - is 5% of the $ value entered by the write when added CarOIL CarFILTERplus - is 2% of the $ value entered by the write when added CarFILTER CarTIREplus - is 3% of the $ value entered by the write when added CarTIRE CarLIGHTplus - is 1% of the $ value entered by the write when added CarLIGHT Can anyone help me? Please...