• Swapnil W
  • NEWBIE
  • 15 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
Hi All,
Really need help with this issue:  I am trying to populate field Version__c [Lookup(Product)] on QuotLine__c object, whenever New_Management_Version__c (checkbox field) on Product object is set to true. But don't know why Version__c is not getting populated.
Also would like to mention here, QuoteLine child object of Product parent object.
Here is my Apex Class:
public without sharing class QuoteLineManager{
public static void updateVersion(List<QuoteLine__c> lstQuoteLine){
        
        List<QuoteLine__c> softwareQlines = new List<QuoteLine__c>();
        List<QuoteLine__c> versionQlines = new List<QuoteLine__c>();
         
        for(QuoteLine__c ql:lstQuoteLine){
            if(ql.ProductFamily__c == 'Software'){
                softwareQlines.add(ql);
            }
                        if(ql.ProductFamily__c == 'Version'){
                versionQlines.add(ql);
            }
        }
        
        for(QuoteLine__c softQl:softwareQlines){
            for(QuoteLine__c versQl:versionQlines){
                if(versQl.Parent_Product_Name__c == softQl.Parent_Product_Name__c){
                     softQl.Version__c = versQl.SBQQ__Product__c;
            }
          }
        }        
    }
}
   
Apex Trigger:
trigger QuoteLineBeforeUpdate on QuoteLine__c (before update) {
    
    
    List<QuoteLine__c> listQuotelinesNewVersionManagementTrue =  new  List<QuoteLine__c>();
   
// need to verify if the New Version Management is true :
  for (QuoteLine__c ql : Trigger.new) {
         
        if (ql.ProductFamily__c == 'Software' &&  ql.Product__r.New_Version_Management__c == true ){
            //if is true I put it in the list
            listQuotelinesNewVersionManagementTrue.add(ql);
        } 
     }
   
  if (!listQuotelinesNewVersionManagementTrue.isEmpty()) {
           QuoteLineManager.updateVersion(listQuotelinesNewVersionManagementTrue);
      }
     
             
    }

Please let me know if you didn't get clear picture of issue. Looking forward for positive feedback. Thanks in advance.