You need to sign in to do that
Don't have an account?

Apex Code Question
Hi, I am writing an Apex Trigger for product X to be added to all Opportuntities containing products Y and Z. My current trigger coding is is not getting the result I was hoping for. Can anyone help me out here on what I need to do to have it look for products Y and Z in my opportunities? Thank you for your help!
trigger CreateOLI on Opportunity (after insert) {
List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
List<PriceBookEntry> priceBookList = [SELECT Id, Product2Id, Product2.Id, Product2.Name FROM PriceBookEntry WHERE Product2Id='01t1a000000Cwc3' AND PriceBook2.isStandard=true LIMIT 1];
for (Opportunity oppty: Trigger.new) {
if (OLI.Name=Z) (OLI.Name=Y)
OLI.Name = (Product2.Name)
//create new Oli
OpportunityLineItem oli = new OpportunityLineItem(OpportunityId=oppty.Id, PricebookEntryId=priceBookList[0].Id /*rest of required fields*/);
oliList.add(oli);
}
}
insert oliList;
}
trigger CreateOLI on Opportunity (after insert) {
List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
List<PriceBookEntry> priceBookList = [SELECT Id, Product2Id, Product2.Id, Product2.Name FROM PriceBookEntry WHERE Product2Id='01t1a000000Cwc3' AND PriceBook2.isStandard=true LIMIT 1];
for (Opportunity oppty: Trigger.new) {
if (OLI.Name=Z) (OLI.Name=Y)
OLI.Name = (Product2.Name)
//create new Oli
OpportunityLineItem oli = new OpportunityLineItem(OpportunityId=oppty.Id, PricebookEntryId=priceBookList[0].Id /*rest of required fields*/);
oliList.add(oli);
}
}
insert oliList;
}
Try using this trigger: Let me know, if you need any other help.
Thanks,
Neetu
All Answers
Try using this trigger: Let me know, if you need any other help.
Thanks,
Neetu
This seems that you need to write trigger on Opportunity Line Items. I can help you on that too.
Can you please contact me either on my gmail id: neetu.bansal.5@gmail.com or Skype id: neetu.bansal.5
Thanks,
Neetu