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
Linda 98Linda 98 

Before Insert Trigger not working

Hi,

 

I have a trigger on quote line items.I have a custom number field on quote line item .Based on that value line items will be duplicated.

If user gives 3 in the custom field value then quote line items will be added in 3 number.

I am using a trigger for this.

Here is my code:

 

trigger AddingQuoteProducts on QuoteLineItem (before insert,before update) {

  List<QuoteLineItem> listItem = new List<QuoteLineItem>();
  for(QuoteLineItem qLI:trigger.new){  
      System.debug('*******'+qLI.customfield__c);  //////This value comes as null during insert and shows value during update.
     if(qLI.Customfield__c > 1){
      for(Integer i=1;i<qLI.CustomField__c;i++){
         QuoteLineItem qLiIt = new QuoteLineItem();
               qLiIt.QuoteId = qLI.QuoteId;
               qLiIt.UnitPrice = qLI.UnitPrice;
               system.debug('opp.PricebookEntry.Id '+qLI.PricebookEntryId);
               system.debug('opp.PricebookEntry.Product2.Id '+qLI.PricebookEntry.Product2.Id);
               qLiIt.PricebookEntryId = qLI.PricebookEntryId;               
               
               qLiIt.Quantity = qLI.Quantity;
               listItem.add(qLiIt);
      }
     }
     insert listItem;
  }  
}

It works fine in my dev org but not in my org.Also it works on update but not on insert.I dont understand what i am missing.

 

Please help!!!!!!!I need this ASAP

 

Best Answer chosen by Admin (Salesforce Developers) 
Linda 98Linda 98
Lol..That was simple issue:) My manager changed the name of custom field in production and he gave me wrong name ...So it was not working:)

Other than that my code is fine...:)

Thanks all:)

All Answers

TomSnyderTomSnyder

change 

//if(qLI.Customfield__c > 1)
if(qLI.Customfield__c!=null && qLI.Customfield__c > 1)

 

Linda 98Linda 98
Thanks for that but it didn't work.The value is showing as null(in debug log) so its not entering in to if loop and entire logic is not working.

I need this ASAP....Any helps please.
Rajesh SriramuluRajesh Sriramulu

Hi,

 

Have enter the value CustomField__c before u clicked on save button?

 

If yes means ur code will executed perfectly. else not.

 

Regards,

Rajesh.

Neha LundNeha Lund

Are you testing this with System administrator User or any other profile User ?

FLS is correct right ?

Linda 98Linda 98
Ya i am system admin
Linda 98Linda 98
Yeah...i am entering value at the time of creating/adding quotelineitems.

My trigger worked fine in same sandbox before i refreshed it.I dont understand what is making my custom
Field value as null when i save the record.
I checked the log and nothing is executing except trigger.How can i find what is the problem?please suggest...


Sent from my iPhone
Linda 98Linda 98
Lol..That was simple issue:) My manager changed the name of custom field in production and he gave me wrong name ...So it was not working:)

Other than that my code is fine...:)

Thanks all:)
This was selected as the best answer