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
Shruthi MN 88Shruthi MN 88 

Write a code

Can you help me with the below code

 

Note - All Trigger must have a handler.

 

1. Create Trigger on OpportunityLineItem, on insertion of record GST should be applied.

Create GST (percentage) fields on Product.


Note - All Trigger must have a handler.

 

1. Create Trigger on OpportunityLineItem, on insertion of record GST should be applied.

Create GST (percentage) fields on Product.


Note - All Trigger must have a handler.

 

1. Create Trigger on OpportunityLineItem, on insertion of record GST should be applied.

Create GST (percentage) fields on Product.


 
AshwiniAshwini (Salesforce Developers) 
Hi Shruthi,
Can you elaborate more on the ask?
Is there any specific code which you have tried and facing any issues?
Shruthi MN 88Shruthi MN 88
I have wortten the below code i am getting the attached errors

public class GSTofproductsHandler {
    public static void calculateDiscount(List<OpportunityLineItem> oppItemList){
        set<id> prodid = new  set<id>();
        List<OpportunityLineItem> updopItemlist = new List<OpportunityLineItem>();
        for(OpportunityLineItem opItem: oppItemList){
            prodid.add(opItem.Product2Id);
        }
        List<Product2> prodlist = [select id, Discount__c from Product2 where id IN: prodid LIMIT 1];
        decimal disc = prodlist[0].Discount__c;
        if(prodlist.size() > 0 &&  disc != null ){
            for(OpportunityLineItem opItem:oppItemList ){
                OpportunityLineItem item = new OpportunityLineItem();
                item.Id = opItem.Id;
                item.UnitPrice = opItem.UnitPrice - disc;
                updopItemlist.add(item);
            }
            if(prodlist.GST__c != null && prodlist.GST_Percentage__c != null){
                for(Product2 prod : prodlist)
               prod.GST__c = disc-prod.GST_Percentage__c ;
                else
                    (if disc == null ){
                 prod.GST__c =  opItem.ListPrice + prod.GST_Percentage__c;
                    
                    }  
            }
            if(updopItemlist.size() > 0){
                update updopItemlist;
            }
        }
    } 
 
}
Show Less
gst.pngUser-added imageUser-added image