You need to sign in to do that
Don't have an account?
shyam Sundar 101
Help!!!
i have a custom field called QtyOnHand__c in Product2 and Quantity in opportunity Line Item . I have a scenario if the opportunity is closed won.
Based on the quantity the qtyOnHand in product should get decreased. help me with trigger.
Based on the quantity the qtyOnHand in product should get decreased. help me with trigger.
trigger upd on Opportunity (after update) {
List <OpportunityLineItem> oli = new List <OpportunityLineItem>();
List<Product2> prod = new list <Product2>();
Set <ID> oppId = new Set <ID>();
for (Opportunity oppo : Trigger.new){
if( oppo.StageName = 'Closed Won'){
oppId.add(oppo.oli.ID);
}
Map<Id, Product2> products = new Map<Id, Product2>();
for(OpportunityLineItem oli= [SELECT ID, PricebookEntry.Product2.Id, PricebookEntry.Product2.QtyOnHand__c, Quantity FROM OpportunityLineItem WHERE OpportunityId IN :oppId])
{
if(oli.Quantiy !=Null){
products.QtyOnHand__c-=oli.Quantity;
}
}
}
}