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
sunny@99-chgsunny@99-chg 

Error on click of Convert button on Lead

Hai,

 

I am getting Error Please Resolve it...

 

Error: System.DmlException: Update failed. First exception on row 0 with id 00QK0000003I8KhMAK; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadAfterUpdate: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, o2bc.SetOrderLineItemPrice: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object (o2bc): [] Trigger.LeadAfterUpdate: line 64, column 1: [] (System Code) 

 

My Trigger is below:

 

trigger LeadAfterUpdate on Lead (after update)
{
    System.debug('******AfterUpdate********' );
    Set<Id> leadIdsSet = new Set<Id>();
    List<Customer_Certification_Line__c> Progrms = new List<Customer_Certification_Line__c>();
    for(Integer i=0;i<Trigger.old.size();i++)
        leadIdsSet.add(Trigger.old[i].id);
    System.debug('******leadIdsSet*******'+leadIdsSet);    
    System.debug('******Trigger.old[0].IsConverted*******'+Trigger.old[0].IsConverted);
    List<Lead> leadList = [Select id,Credit_Card_Number_Enc__c,mailing_city__c,mailing_address_1__c,mailing_address_2__c,mailing_state__c,mailing_zip_code__c,(SELECT Account__c,Certification_Name__c FROM Customer_Certification_Lines__r),ConvertedAccountId,(Select id,Item__c,Lead__c,Quantity__c from Lead_Line_Items__r) from Lead where IsConverted = true and id in :leadIdsSet];
    System.debug('******leadList*******'+leadList);
    if(leadList.size()>0)
    {
        if (lead.ConvertedAccountId != null) {
            
            for(Lead lead:leadList){
                system.debug(lead.ConvertedAccountId);
                Account a = [Select a.id,a.shippingstreet,a.shippingcountry,a.shippingstate,a.shippingPostalCode,a.shippingcity From Account a Where a.Id = :lead.ConvertedAccountId];
                System.debug('******account fields*******'+a);
                a.shippingcity = lead.mailing_city__c;
                if(lead.mailing_address_2__c!=null)
                    a.ShippingStreet = lead.mailing_address_1__c+' '+lead.mailing_address_2__c;
                else
                    a.ShippingStreet = lead.mailing_address_1__c;
                    a.shippingstate = lead.mailing_state__c;
                    a.ShippingPostalCode = lead.Mailing_Zip_Code__c;
                    a.o2bc__Credit_Card_Number__c = lead.Credit_Card_Number_Enc__c;
                update a;
            }
 
        }
        Map<Id,o2bc__Sales_Order__c> accountIdSalesOrderMap = new Map<Id,o2bc__Sales_Order__c>();
        for(Lead lead:leadList)
        {
            o2bc__Sales_Order__c salesOrder = new o2bc__Sales_Order__c();
            salesOrder.o2bc__Account__c = lead.ConvertedAccountId;
            accountIdSalesOrderMap.put(lead.ConvertedAccountId,salesOrder);
        }
        system.debug('Size is--------->' + accountIdSalesOrderMap.size());
        insert accountIdSalesOrderMap.values();
        System.debug('******accountIdSalesOrderMap*******'+accountIdSalesOrderMap);
        List<o2bc__Order_Line__c> orderLineList = new List<o2bc__Order_Line__c>();
        for(Lead lead:leadList)
        {
            for(Lead_Line_Item__c leadProductLineItem:lead.Lead_Line_Items__r)
            {
                o2bc__Order_Line__c orderLine = new o2bc__Order_Line__c();
                orderLine.o2bc__Item__c = leadProductLineItem.Item__c;
                orderLine.o2bc__Sales_Order__c = accountIdSalesOrderMap.get(lead.ConvertedAccountId).id;
                orderLine.o2bc__Quantity__c = leadProductLineItem.Quantity__c;
                orderLineList.add(orderLine);
            }
            if(lead.Customer_Certification_Lines__r.size()>0){
                
                for(Customer_Certification_Line__c oProgram : lead.Customer_Certification_Lines__r){
                    
                    Customer_Certification_Line__c oProgramList = new Customer_Certification_Line__c(id = oProgram.Id);
                    oProgramList.Account__c = lead.ConvertedAccountId;
                    Progrms.add(oProgramList);
                }
            }
        }
        System.debug('******orderLineList*******'+orderLineList);
        insert orderLineList; // ----->Line 64
        if(!Progrms.isEmpty()){
            update Progrms;
        }
    }
}

Afzal MohammadAfzal Mohammad

Is there a before insert trigger on o2bc__Order_Line__c object? If yes, then the problem is within that trigger. You need to debug that trigger.

 

Afzal

HariDineshHariDinesh

Hi,

 

Before Inserting or updating the list please check the list size. Whether the list has data or not?

Add this condition before “insert  orderLineList”

 

IF(orderLineList.size()>0)
  insert orderLineList; 

 Now this error will not come. 

Now you have to check why the data is not coming into list by analyzing the trigger and try to figure it out

sunny@99-chgsunny@99-chg

Hai Haridinesh,Thats not working it giving the same error...