+ Start a Discussion
nlsnydernlsnyder 

Why is QuoteLineItem.ListPrice NULL in my trigger?

Here is the trigger code:

trigger UpdateQuoteLineItemTrigger on QuoteLineItem (before insert, before update) {
    System.Debug('>> In UpdateQuoteLineItemTrigger <<');
    
    for (QuoteLineItem li : trigger.new) {
        
        QuoteLineItem qli = [SELECT id, ListPrice FROM QuoteLineItem WHERE id =: li.id];
        
        Decimal listPrice = li.ListPrice;
        if (li.ListPrice == null) {
            System.Debug('>> LIST PRICE IS NULL ?? <<');
            listPrice = qli.ListPrice;
            System.Debug('>> qli.ListPrice = '+ qli.ListPrice + ' <<');
        }
        
        // Assume List Price is yearly so divide by 12 to get monthly price
        Decimal mprice = (ListPrice / 12);
        li.Monthly_Price__c = mprice.SetScale(2); 
        
        li.Description = li.ProductName__c;
        li.Preview__c = 'Description: '+li.ProductName__c;
        System.Debug('>> preview = '+li.Preview__c + ' <<');
        
        if (li.Prorate__c) {
            System.Debug('>> PRORATE <<');
            date begDate = li.BeginDate__c;
            date endDate = li.EndDate__c;
            System.Debug('>> begDate = '+ begDate + ' endDate = ' + endDate + ' <<'); 
           
            integer m = begDate.monthsBetween(endDate);
            date d3 = begDate.addMonths(m);
            integer d = d3.daysBetween(endDate);
            d = d + 1; // increment the current day
            
            if (d < 0) {
                m = m - 1;
                d3 = begDate.addMonths(m);
                d = d3.daysBetween(endDate);
            }
            System.Debug('>>> m='+ m +' d3='+ d3 + ' d='+d+' <<<');
            
            double prorated_period = m;
            if ((d >= 1) && (d <= 15)) {
                prorated_period = m + 0.5;
            }
            else if (d > 15) {
                prorated_period = m + 1;
            }
            if (m == 0) {
                prorated_period = 0.5;
            }
            System.Debug('>>> prorated_period=' + prorated_period + ' <<<');
            
            // Update prorated period
            li.Period__c = prorated_period;        

            // Prorate the unit price 
            Decimal uprice = (li.Monthly_Price__c * prorated_period);  
            li.UnitPrice = uprice.SetScale(2);    
            
            li.Preview__c += ' (' + begDate.month() + '/' + begDate.day() + '/' + begDate.year() + ' - ' + endDate.month() + '/' + endDate.day() + '/' + endDate.year() + '; '+ li.period__c + ' months)';           
        }
        else if (li.Renew__c) {
            System.Debug('>> RENEW <<');
            li.UnitPrice = ListPrice;
           
            System.Debug('>> li.years__c='+li.years__c+' BegDt='+li.BeginDate__c+' EndDt='+li.EndDate__c+' <<');
            if (li.years__c == null) {
               li.years__c = '1';
            }
            integer years = integer.valueOf(li.years__c);
            li.quantity = li.quantity;
            li.period__c = 12 * years;
            
            if (li.BeginDate__c == null) {
                li.BeginDate__c = Date.today();
            }
            date begDate = li.BeginDate__c;
            date newEndDt = begDate.addMonths(years * 12) - 1;
            li.EndDate__c = newEndDt;    
            
            li.Preview__c += ' (' + begDate.month() + '/' + begDate.day() + '/' + begDate.year() + ' - ' + li.EndDate__c.month() + '/' + li.EndDate__c.day() + '/' + li.EndDate__c.year() + ')';      
        }
        else {
            System.Debug('>> NOT PRORATE && NOT RENEW <<');
            li.UnitPrice = ListPrice;
            li.period__c = 0;  // doesn't apply so giving it a zero 
        }
        
        System.Debug('>** ProductName='+ li.ProductName__c + 'quantity=' + li.quantity + ' ListPrice=' + li.ListPrice + ' UnitPrice=' + li.UnitPrice +  ' Renew='+li.renew__c + ' prorate='+li.prorate__c +' Period='+li.period__c + ' desc=' + li.description + ' period='+ li.period__c + ' <<<'); 
    }
}

 I know that ListPrice is a readonly value but I thought it would already be set?   How do I fix this?

SScholtzSScholtz

Sorry for the thread necromancy, but today I ran into this exact same problem.

 

I have a VF page that makes a bunch of changes to the child Quote Line Items of a Quote, and in my trigger code I'm trying to tweak the final price based on some alternative discounting rules.  The problem is that when I edit a single Quote Line Item via the UI, the ListPrice has a value, but when my VF page tries to update a series of Quote Line Items, ListPrice is coming up NULL.

 

Googling around hasn't helped much.  The field is supposed to be read only, I should be able to get access to its value, but it just comes up null unless I edit the Quote Line Item through the UI.

 

Any insight would be greatly appreciated.

SScholtzSScholtz

Just an update for anyone who stumbles across this, I got a response from Salesforce Tech Support and they just gave me a work around which  I had figured out anyways: query the items from product database so you can find the list price.

 

I created an Idea for this over here if you're having the same problem and think it should be fixed: https://success.salesforce.com/ideaView?id=08730000000kqsXAAQ