function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
shyam Sundar 101shyam 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.                                                                                                                
shyam Sundar 101shyam Sundar 101
THIS IS WHAT I TRIED HELP ME!!!


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;
    }
    
        
    }

}
}