• Lakshmi Deepak Inkurthi
  • NEWBIE
  • 70 Points
  • Member since 2018
  • Technical Design Lead
  • Dover


  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 6
    Replies
I wanted to pass data from visualforce page to apex class based on user clicks ?
Hi All,
I have two triggers in quote and Quote line item
Quote Trigger; v2_QuoteTaxUpdate
Quote line Item Trigger: RolluplineitemTrigger

while testing the RolluplineitemTrigger in QuotelineItem am  getting the following error

User-added image

kindly Let me know where am doing mistake
RolluplineitemTrigger;

trigger RolluplineitemTrigger on QuoteLineItem  (after insert, after update) {

    List<Id> VQuoteID = new List<Id>();
    
    for(QuoteLineItem p: Trigger.new) {
        VQuoteID.add(p.QuoteiD);
    }
    
    AggregateResult[] groupedResults = [SELECT Sum(Stock_Not_Available__c) lineItemCOunt, QuoteiD FROM QuoteLineItem 
    WHERE QuoteiD in :VQuoteID  GROUP BY QuoteiD];
    
    Map<id,Quote> QuoteMap = new Map<Id,Quote>([SELECT id, No_of_Products_Stock_Not_Available__c 
    FROM Quote WHERE Id in :VQuoteID]); 
    
    for(AggregateResult ar: groupedResults) {
    
    QuoteMap.get((Id)ar.get('QuoteiD')).No_of_Products_Stock_Not_Available__c = (decimal) ar.get('lineItemCOunt');

       
    }
    
    //try {
        update QuoteMap.values();
    //}   catch(DmlException e) {
        //System.debug(e.getMessage());
    //}

}

v2_QuoteTaxUpdate:

trigger v2_QuoteTaxUpdate on Quote (after insert, after update) {

    list<QuoteLineItem> lstUpdateQLI = new list<QuoteLineItem>();
    set<id> setQuoteId = new set<id>();
     set<id> setQuoteIdTaxUpd = new set<id>();
    set<id> setQLIId = new set<id>();
    set<String> setHSNCode = new set<String>();  
    List<Id> VQuoteID = new List<Id>();  
    map<string, list<Tax_Master__c>>mapTaxMasToTaxKey = new map<string, list<Tax_Master__c>>();    
        
    for(Quote iQLI : Trigger.New){   
        If(Trigger.Isinsert) {
        
            if(iQLI.Tax_Classification__c !=''){
            
                setQuoteId.add(iQLI.id);
                setQuoteIdTaxUpd.add(iQLI.id);
                system.debug('****setQLIId'+setQLIId);       
                
            }
        }
        
        if(Trigger.isupdate) {
        
         if(iQLI.Tax_Classification__c!=''){
            
                setQuoteId.add(iQLI.id);
                setQuoteIdTaxUpd.add(iQLI.id);
                system.debug('****setQLIId'+setQLIId);       
          }            
          if(iQLI.Discount_Amount__c!=Null){  
          
              setQuoteId.add(iQLI.id);
              system.debug('****setQLIId'+setQLIId);  
          }
        
        }
        
    }
    
        
    
    if(setQuoteId.size() > 0){
    
        for(Quote iQuot : [SELECT id,(SELECT id, Product2.HSN_Code__c FROM QuoteLineItems ) 
            FROM Quote WHERE Id IN :setQuoteIdTaxUpd]){
        
            for(QuoteLineItem iQLI : iQuot.QuoteLineItems){
                  
                    if(iQLI.Product2.HSN_Code__c != ''){
                    
                        setHSNCode.add(iQLI.Product2.HSN_Code__c);
                    }    
            }   
            system.debug('****setHSNCode'+setHSNCode);                    
        }
        
        if(setHSNCode.size() > 0){
        
            if(setHSNCode.size() > 0){
            
                for(Tax_Master__c iTM : [SELECT id, Product_Family__c,Product_Sub_Family__c,HSN_Code__c, IGST__c, CGST__c, SGST__c, Active__c,Start_Date__c,End_date__c FROM Tax_Master__c  WHERE HSN_Code__c IN :setHSNCode ]){
                
                     String ikey = iTM.HSN_Code__c;
                    if(!String.isblank(iTM.Product_Family__c))
                    {
                        ikey = ikey + iTM.Product_Family__c;                         
                    } 
                    if(!String.isblank(iTM.Product_Sub_Family__c))
                    {
                        ikey = ikey + iTM.Product_Sub_Family__c;                         
                    } 
                    list<Tax_Master__c> lstTax = new list<Tax_Master__c>();
                    lstTax.add(iTM);
                    if(mapTaxMasToTaxKey.containskey(ikey))
                    {
                        lstTax.addall(mapTaxMasToTaxKey.get(ikey));
                    }
                    mapTaxMasToTaxKey.put(ikey, lstTax); 
                                 
                 }   
                    system.debug('****mapTaxMasToTaxKey'+mapTaxMasToTaxKey);                    
 
            }  
            
                  
            
            for(Quote iQuot : [SELECT id, Tax_Classification__c, Discount_Amount__c,Anki_total_Amt__c,
                (SELECT CreatedDate,Product2.family, Product2.Sub_Family__c,Product2.HSN_Code__c, Tax_Master__c, IGST__c, CGST__c, SGST__c FROM QuoteLineItems) 
                FROM Quote WHERE Id IN :setQuoteId]){
            
                for(QuoteLineItem iQLI : iQuot.QuoteLineItems){  
                       
                       system.debug('****iQuot.Discount_Amount__c'+iQuot.Discount_Amount__c); 
                       system.debug('****iQuot.Anki_total_Amt__c'+iQuot.Anki_total_Amt__c); 
                          
                          if(iQuot.Discount_Amount__c <= 0 ){
                                iQLI.Q_Discount__c = 0;    
                          
                            } else {
                                if(iQuot.Discount_Amount__c != null && iQuot.Anki_total_Amt__c !=null){
                                iQLI.Q_Discount__c =(iQuot.Discount_Amount__c/iQuot.Anki_total_Amt__c) * 100;
                                
                                }
                            } 
                                                       
                         system.debug('****Q_Discount__c'+iQLI.Q_Discount__c);
                        Date myDate =  date.parse('11/10/2017');
                        Date myDate2 = date.parse(iqli.CreatedDate.day()+'/'+iqli.CreatedDate.month()+'/'+iqli.CreatedDate.year());
                        
                        Tax_Master__c itax = new Tax_Master__c();
                        
                        
                        if(mapTaxMasToTaxKey.containsKey(iQLI.Product2.HSN_Code__c+iQLI.Product2.Family+iQLI.Product2.Sub_Family__c) && myDate2 >= myDate ){
                            for(Tax_Master__c irow : mapTaxMasToTaxKey.get(iQLI.Product2.HSN_Code__c+iQLI.Product2.Family+iQLI.Product2.Sub_Family__c))
                            {
                                if(irow.Start_Date__c <= iqli.CreatedDate && irow.End_Date__c  >= iqli.CreatedDate)
                                {
                                
                                    itax = irow;
                                    break;
                                }
                            }
                        }
                        else if(mapTaxMasToTaxKey.containsKey(iQLI.Product2.HSN_Code__c+iQLI.Product2.Family) && myDate2 >= myDate ){
                            
                            for(Tax_Master__c irow : mapTaxMasToTaxKey.get(iQLI.Product2.HSN_Code__c+iQLI.Product2.Family))
                            {
                                if(irow.Start_Date__c <= iqli.CreatedDate && irow.End_Date__c  >= iqli.CreatedDate)
                                {
                                
                                    itax = irow;
                                    break;
                                }
                            }
                        }else if(mapTaxMasToTaxKey.containsKey(iQLI.Product2.HSN_Code__c))
                        {
                            for(Tax_Master__c irow : mapTaxMasToTaxKey.get(iQLI.Product2.HSN_Code__c))
                            {
                                if(irow.Start_Date__c <= iqli.CreatedDate && irow.End_Date__c  >= iqli.CreatedDate)
                                {
                                
                                    itax = irow;
                                    break;
                                }
                            }
                        }
                        
                        if(!String.isblank(itax.id)){
                    
                        iQLI.Tax_Master__c = itax.id;
                        
                        
                        
                        if(iQuot.Tax_Classification__c == 'IGST'){
                        
                            iQLI.IGST__c = itax.IGST__c;
                            iQLI.SGST__c = 0; 
                            iQLI.CGST__c = 0;
                            //iQLI.Q_Discount__c = iQuot.Ankidyne_Discount_Percentage__c;
                        } 
                        
                        if(iQuot.Tax_Classification__c == NUll){
                        
                            iQLI.SGST__c = 0;
                            iQLI.CGST__c = 0;    
                            iQLI.IGST__c = 0;  
                            //iQLI.Q_Discount__c = iQuot.Ankidyne_Discount_Percentage__c;                      
                        }
                        if(iQuot.Tax_Classification__c == 'SGST'){
                        
                            iQLI.SGST__c = itax.SGST__c;
                            iQLI.CGST__c = itax.CGST__c;    
                            iQLI.IGST__c = 0;  
                            //iQLI.Q_Discount__c = iQuot.Ankidyne_Discount_Percentage__c;                      
                        }                       
                        
                        lstUpdateQLI.add(iQLI);                            
                    }    
                                         
                }    
            }  
            
            if(lstUpdateQLI.size() > 0){            
                update lstUpdateQLI;
            }          
        }
    }
}

 
Hello everyone,
This is my code, I wanted to write this class with all best practises recommended.
please help me to rectify this code also i want it to work if both account and contact have same country.

public class Update_Contact_Phone {
    public static void contactOtherPhone(List<Account> AccountList){
        set <id> IdCollect = new set <id>();
        List <Contact> Contacts = [SELECT Id,
                                    OtherPhone
                                   From Contact 
                                  WHERE AccountId IN :IdCollect];
        For(Account acc :AccountList){
            If (acc.Phone != null){
                IdCollect.add(acc.Id);
            }
        }
        Map <Id, string> conmap = new Map <Id, string>();
        For(Account acc : AccountList){
            conmap.put(acc.Id , acc.Phone);
             }
        For(Contact c : Contacts ){
            c.OtherPhone = conmap.get(c.AccountId);
        }
       Update Contacts;
    }}
I wanted to pass data from visualforce page to apex class based on user clicks ?
Hi All,
I have two triggers in quote and Quote line item
Quote Trigger; v2_QuoteTaxUpdate
Quote line Item Trigger: RolluplineitemTrigger

while testing the RolluplineitemTrigger in QuotelineItem am  getting the following error

User-added image

kindly Let me know where am doing mistake
RolluplineitemTrigger;

trigger RolluplineitemTrigger on QuoteLineItem  (after insert, after update) {

    List<Id> VQuoteID = new List<Id>();
    
    for(QuoteLineItem p: Trigger.new) {
        VQuoteID.add(p.QuoteiD);
    }
    
    AggregateResult[] groupedResults = [SELECT Sum(Stock_Not_Available__c) lineItemCOunt, QuoteiD FROM QuoteLineItem 
    WHERE QuoteiD in :VQuoteID  GROUP BY QuoteiD];
    
    Map<id,Quote> QuoteMap = new Map<Id,Quote>([SELECT id, No_of_Products_Stock_Not_Available__c 
    FROM Quote WHERE Id in :VQuoteID]); 
    
    for(AggregateResult ar: groupedResults) {
    
    QuoteMap.get((Id)ar.get('QuoteiD')).No_of_Products_Stock_Not_Available__c = (decimal) ar.get('lineItemCOunt');

       
    }
    
    //try {
        update QuoteMap.values();
    //}   catch(DmlException e) {
        //System.debug(e.getMessage());
    //}

}

v2_QuoteTaxUpdate:

trigger v2_QuoteTaxUpdate on Quote (after insert, after update) {

    list<QuoteLineItem> lstUpdateQLI = new list<QuoteLineItem>();
    set<id> setQuoteId = new set<id>();
     set<id> setQuoteIdTaxUpd = new set<id>();
    set<id> setQLIId = new set<id>();
    set<String> setHSNCode = new set<String>();  
    List<Id> VQuoteID = new List<Id>();  
    map<string, list<Tax_Master__c>>mapTaxMasToTaxKey = new map<string, list<Tax_Master__c>>();    
        
    for(Quote iQLI : Trigger.New){   
        If(Trigger.Isinsert) {
        
            if(iQLI.Tax_Classification__c !=''){
            
                setQuoteId.add(iQLI.id);
                setQuoteIdTaxUpd.add(iQLI.id);
                system.debug('****setQLIId'+setQLIId);       
                
            }
        }
        
        if(Trigger.isupdate) {
        
         if(iQLI.Tax_Classification__c!=''){
            
                setQuoteId.add(iQLI.id);
                setQuoteIdTaxUpd.add(iQLI.id);
                system.debug('****setQLIId'+setQLIId);       
          }            
          if(iQLI.Discount_Amount__c!=Null){  
          
              setQuoteId.add(iQLI.id);
              system.debug('****setQLIId'+setQLIId);  
          }
        
        }
        
    }
    
        
    
    if(setQuoteId.size() > 0){
    
        for(Quote iQuot : [SELECT id,(SELECT id, Product2.HSN_Code__c FROM QuoteLineItems ) 
            FROM Quote WHERE Id IN :setQuoteIdTaxUpd]){
        
            for(QuoteLineItem iQLI : iQuot.QuoteLineItems){
                  
                    if(iQLI.Product2.HSN_Code__c != ''){
                    
                        setHSNCode.add(iQLI.Product2.HSN_Code__c);
                    }    
            }   
            system.debug('****setHSNCode'+setHSNCode);                    
        }
        
        if(setHSNCode.size() > 0){
        
            if(setHSNCode.size() > 0){
            
                for(Tax_Master__c iTM : [SELECT id, Product_Family__c,Product_Sub_Family__c,HSN_Code__c, IGST__c, CGST__c, SGST__c, Active__c,Start_Date__c,End_date__c FROM Tax_Master__c  WHERE HSN_Code__c IN :setHSNCode ]){
                
                     String ikey = iTM.HSN_Code__c;
                    if(!String.isblank(iTM.Product_Family__c))
                    {
                        ikey = ikey + iTM.Product_Family__c;                         
                    } 
                    if(!String.isblank(iTM.Product_Sub_Family__c))
                    {
                        ikey = ikey + iTM.Product_Sub_Family__c;                         
                    } 
                    list<Tax_Master__c> lstTax = new list<Tax_Master__c>();
                    lstTax.add(iTM);
                    if(mapTaxMasToTaxKey.containskey(ikey))
                    {
                        lstTax.addall(mapTaxMasToTaxKey.get(ikey));
                    }
                    mapTaxMasToTaxKey.put(ikey, lstTax); 
                                 
                 }   
                    system.debug('****mapTaxMasToTaxKey'+mapTaxMasToTaxKey);                    
 
            }  
            
                  
            
            for(Quote iQuot : [SELECT id, Tax_Classification__c, Discount_Amount__c,Anki_total_Amt__c,
                (SELECT CreatedDate,Product2.family, Product2.Sub_Family__c,Product2.HSN_Code__c, Tax_Master__c, IGST__c, CGST__c, SGST__c FROM QuoteLineItems) 
                FROM Quote WHERE Id IN :setQuoteId]){
            
                for(QuoteLineItem iQLI : iQuot.QuoteLineItems){  
                       
                       system.debug('****iQuot.Discount_Amount__c'+iQuot.Discount_Amount__c); 
                       system.debug('****iQuot.Anki_total_Amt__c'+iQuot.Anki_total_Amt__c); 
                          
                          if(iQuot.Discount_Amount__c <= 0 ){
                                iQLI.Q_Discount__c = 0;    
                          
                            } else {
                                if(iQuot.Discount_Amount__c != null && iQuot.Anki_total_Amt__c !=null){
                                iQLI.Q_Discount__c =(iQuot.Discount_Amount__c/iQuot.Anki_total_Amt__c) * 100;
                                
                                }
                            } 
                                                       
                         system.debug('****Q_Discount__c'+iQLI.Q_Discount__c);
                        Date myDate =  date.parse('11/10/2017');
                        Date myDate2 = date.parse(iqli.CreatedDate.day()+'/'+iqli.CreatedDate.month()+'/'+iqli.CreatedDate.year());
                        
                        Tax_Master__c itax = new Tax_Master__c();
                        
                        
                        if(mapTaxMasToTaxKey.containsKey(iQLI.Product2.HSN_Code__c+iQLI.Product2.Family+iQLI.Product2.Sub_Family__c) && myDate2 >= myDate ){
                            for(Tax_Master__c irow : mapTaxMasToTaxKey.get(iQLI.Product2.HSN_Code__c+iQLI.Product2.Family+iQLI.Product2.Sub_Family__c))
                            {
                                if(irow.Start_Date__c <= iqli.CreatedDate && irow.End_Date__c  >= iqli.CreatedDate)
                                {
                                
                                    itax = irow;
                                    break;
                                }
                            }
                        }
                        else if(mapTaxMasToTaxKey.containsKey(iQLI.Product2.HSN_Code__c+iQLI.Product2.Family) && myDate2 >= myDate ){
                            
                            for(Tax_Master__c irow : mapTaxMasToTaxKey.get(iQLI.Product2.HSN_Code__c+iQLI.Product2.Family))
                            {
                                if(irow.Start_Date__c <= iqli.CreatedDate && irow.End_Date__c  >= iqli.CreatedDate)
                                {
                                
                                    itax = irow;
                                    break;
                                }
                            }
                        }else if(mapTaxMasToTaxKey.containsKey(iQLI.Product2.HSN_Code__c))
                        {
                            for(Tax_Master__c irow : mapTaxMasToTaxKey.get(iQLI.Product2.HSN_Code__c))
                            {
                                if(irow.Start_Date__c <= iqli.CreatedDate && irow.End_Date__c  >= iqli.CreatedDate)
                                {
                                
                                    itax = irow;
                                    break;
                                }
                            }
                        }
                        
                        if(!String.isblank(itax.id)){
                    
                        iQLI.Tax_Master__c = itax.id;
                        
                        
                        
                        if(iQuot.Tax_Classification__c == 'IGST'){
                        
                            iQLI.IGST__c = itax.IGST__c;
                            iQLI.SGST__c = 0; 
                            iQLI.CGST__c = 0;
                            //iQLI.Q_Discount__c = iQuot.Ankidyne_Discount_Percentage__c;
                        } 
                        
                        if(iQuot.Tax_Classification__c == NUll){
                        
                            iQLI.SGST__c = 0;
                            iQLI.CGST__c = 0;    
                            iQLI.IGST__c = 0;  
                            //iQLI.Q_Discount__c = iQuot.Ankidyne_Discount_Percentage__c;                      
                        }
                        if(iQuot.Tax_Classification__c == 'SGST'){
                        
                            iQLI.SGST__c = itax.SGST__c;
                            iQLI.CGST__c = itax.CGST__c;    
                            iQLI.IGST__c = 0;  
                            //iQLI.Q_Discount__c = iQuot.Ankidyne_Discount_Percentage__c;                      
                        }                       
                        
                        lstUpdateQLI.add(iQLI);                            
                    }    
                                         
                }    
            }  
            
            if(lstUpdateQLI.size() > 0){            
                update lstUpdateQLI;
            }          
        }
    }
}

 
I wanted to pass data from visualforce page to apex class based on user clicks ?