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
pcmca_2007@yahoo.co.inpcmca_2007@yahoo.co.in 

DataLoader Error

Hi,

    I am trying to insert product on opportunity using dataLoader but Out of 279 records we were able to insert 179 records. 100 records throw the exception.The error i get is as:

 

          updateOpportunity: execution of AfterInsert

caused by: System.DmlException: Update failed. First exception on row 0 with id 006S00000058CnhIAE; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [StageName]: [StageName]

Class.Update_OpportunityStageAndStatus_Class.updateOpenStatus_2: line 196, column 14
Trigger.updateOpportunity: line 60, column 10

 

Can any one suggest me what could be the reason for that.

 

With Regards

Prabhash Mishra

ritika@developerforceritika@developerforce

Hi,

 

This error is because of a trigger named updateOpportunity, which is updating the opportunities linked to your products. But these opportunities seem to having missing the Stage Name field, which is a mandatory field. 

 

Internally it seems the trigger is calling a class Update_OpportunityStageAndStatus_Class, which is updating the opportunities.

 

You need to make sure that all mandatory fields are present in opportunities that you are inserting the products for.

 

Would be helpful if you could post your codes (trigger and class) here

 

Hope this helps.

rohitsfdcrohitsfdc

make sure stageName has some value in it, as it is a required field

pcmca_2007@yahoo.co.inpcmca_2007@yahoo.co.in

Hi,

     This is code for trigger.But Class is too long,so i will send it in two post.Jus paste first class portion with

      second post.

 

Trigger Code

 

               trigger updateOpportunity on OpportunityLineItem (After insert , After update) {
List<Opportunity> opprList = new List<opportunity>();
    List<OpportunityLineItem> oppLineItemList = new List<OpportunityLineItem>();
    List<ID> OpportunityIDList = new List<ID>();
    Map<Id, Opportunity> OpportunityMap = new Map<Id, Opportunity>();
    List<Opportunity> NewOpportunityList = new List<Opportunity>();
   
    Map<Id, OpportunityLineItem> OpenOppLineItemMap = new Map<Id, OpportunityLineItem>();
  
    public String Status;


if(Trigger.isInsert || Trigger.isUpdate)
   
    //if((Trigger.isInsert || Trigger.isUpdate) && Oppproducthelperclass.getIsOppTriggerAlreadyFired())
    {
     // Oppproducthelperclass.setIsOppTriggerAlreadyFired(true);
     system.debug('inside trigger');
       
        for(OpportunityLineItem oppLineItem : Trigger.new)
        {
       
       
        oppLineItemList.add(oppLineItem);
       
      
        system.debug('OppList' + oppLineItemList);
        }
        for(OpportunityLineItem ObjOppLineItem : oppLineItemList)
        {
        OpportunityIDList.add(ObjOppLineItem.opportunityid);
        system.debug('OpportunityIDList' + OpportunityIDList);
        }
        List<Opportunity> oppList =[Select id,RecordTypeid,name,StageName,INTL_Status__c from Opportunity where id in:OpportunityIDList];
        system.debug('OpportunityList' + oppList);
        for(Opportunity opp : OppList)
        {
        if(opp.RecordTypeid == '012700000001Wo1AAE')
        {
        opp.Mass_Update_All_Line_Items__c = false;
       
        opprList.add(opp);
       
        Opportunitymap.put(opp.id ,opp);
        system.debug('OpportunityList' + Opportunitymap);
        }
        }
       
       // List<OpportunityLineItem> newOppitemList = [Select id,opportunityid,Stage__c ,Status__c from OpportunityLineItem where opportunityid in : Opportunitymap.keyset()];
        List<OpportunityLineItem> newOppitemList = [Select id,opportunityid,Stage__c ,Status__c from OpportunityLineItem where opportunityid in : OpportunityIDList];
        system.debug('newOppitemList' + newOppitemList);
        system.debug('beforecall');
       // if(Oppproducthelperclass.getIsOppTriggerAlreadyFired())
       // {
       // Oppproducthelperclass.setIsOppTriggerAlreadyFired(true);
       
        /*for(opportunity opp : opprList)
        {
        if(opp.Mass_Update_All_Line_Items__c)
        {*/
       
         Update_OpportunityStageAndStatus_Class.updateOpenStatus_2(newOppitemList,opprList,Opportunitymap);
       //}
       // }
       // }
   } 
}

pcmca_2007@yahoo.co.inpcmca_2007@yahoo.co.in

First Portion Of Class:

 

public with sharing class Update_OpportunityStageAndStatus_Class {

public static void updateOpenStatus(Map<Id, OpportunityLineItem> opplineitemMap)
  {
    System.debug('inside method');
    List <Opportunity> oppList = [Select id, StageName, INTL_Status__c from Opportunity where Id in :opplineitemMap.keySet()];
    System.debug('inside method' +oppList);
    if(oppList != null && oppList.size()>0)
    {
      for(Opportunity opp : oppList)
      {

        opp.INTL_Status__c = 'Open';
      }

      update oppList;
      System.debug('Opportunity are updated for status as open');
    }
  }

  private static integer assignWeight(String Stage)
  {
    Integer retString =0;
    if(Stage.contains('0') )
        retString =0;
    if(Stage.contains('1') )
        retString =1;
    if(Stage.contains('2') )
        retString =2;
    if(Stage.contains('3') )
        retString =3;
    if(Stage.contains('4') )
        retString =4;
    if(Stage.contains('5') )
        retString =5;
    if(Stage.contains('6') )
        retString =6;
    if(Stage.contains('7') )
        retString =7;
    if(Stage.contains('8') )
        retString =8;
    if(Stage.contains('9') )
        retString =9;
    return  retString;

  }

    private static  String getStage(integer Weight)
    {
      String retString ='';

    if(Weight== 0)
          retString ='0. Identify';
    if(Weight== 1)
          retString ='1. Qualify';
    if(Weight== 2)
          retString ='2. First Contact';
    if(Weight== 3)
          retString ='3. Assess Needs';
    if(Weight== 4)
          retString ='4. Formal Offer';
    if(Weight== 5)
          retString ='5. Verbal Win';
    if(Weight== 6)
          retString ='6. Complete';
    if(Weight== 7 || Weight== 8 || Weight== 9 )
          retString ='6. Complete';
      return  retString;

      }

  public static void updateOpenStatus_2(List<OpportunityLineItem> opplineitemList , List<Opportunity> oppList,Map<ID, Opportunity> oppMap)
  {
        List<Opportunity> LastUpdateOppList = new List<Opportunity>();
        List<OpportunityLineItem> LineItembyOpp = new List<OpportunityLineItem>();
        List<Opportunity> updateOppList = new List<Opportunity>();
        Map<ID , List<OpportunityLineItem>> MapOppandLineItem = new  Map<ID , List<OpportunityLineItem>>();
        System.debug('inside method');

            for(Opportunity opp : oppList)
            {
                 List<OpportunityLineItem> tempList = new List<OpportunityLineItem>();

                 for(OpportunityLineItem oppListitem2 : opplineitemList)
                 {
                    if(oppListitem2.OpportunityId == opp.ID)
                    {
                        tempList.add(oppListitem2);
                    }
                 }
            //This map contains opportunity and list of opportunity line items under it
             MapOppandLineItem.put(opp.ID , tempList);
             system.debug('Map' +MapOppandLineItem);
            }

             for(ID oppID :  MapOppandLineItem.keySet())
             {  system.debug('inside for1');
                Opportunity opptoUpdate=oppMap.get(oppID);
                opptoUpdate.Flag__c = true;
                String oppStage=opptoUpdate.StageName;
               
                Integer lineItemSize = MapOppandLineItem.get(oppID).size();
                Integer RejectCount = 0;
                Integer lineItemCount = 0;
                Integer oppStageWt = assignWeight(oppStage);
                Boolean lineItemOpen = false;
                Boolean lineItemSigned = false;
                Boolean lineitemrejected = false;
                system.debug('opptoUpdatebeforeupdate' +oppStage);
                system.debug('stagein opp' +oppStageWt);
                String lineItemSatge = MapOppandLineItem.get(oppID)[0].stage__c;
                integer lowest = assignWeight(lineItemSatge);
                system.debug('loweststagebeforeiteration' + lowest);
                for(OpportunityLineItem oppLineItem : MapOppandLineItem.get(oppID))
                {   system.debug('inside for2');
                    Integer lineItemWt = assignWeight(oppLineItem.Stage__c);
                    system.debug('stagein opplineitem' +lineItemWt);
                    //if(oppLineItem.Status__c!='Rejected')
                      // {
                            if(lineItemWt <= lowest)
                            {   system.debug('inside if for low stage');
                                lowest = lineItemWt;
                                //break;
                            }
                            if(oppLineItem.Status__c == 'Open')
                            {
                                lineItemOpen= true;
                                system.debug( 'inside open');
                                opptoUpdate.INTL_Status__c = 'Open';
                                system.debug('opp to be open' +opptoUpdate);
                                continue;
                            }
                             if(oppLineItem.Status__c == 'Signed')
                            {
                                lineItemSigned = true;

                            }

                      // }


pcmca_2007@yahoo.co.inpcmca_2007@yahoo.co.in

Second Portion Continues:

 

 // else if(oppLineItem.Status__c == 'Rejected')
                       if(oppLineItem.Status__c == 'Rejected')

                       {
                            System.debug('Reject Count' +  RejectCount);
                            RejectCount++;
                            System.debug('Reject Count after adding' +  RejectCount);
                            if(RejectCount == lineItemSize)
                            { 
                              opptoUpdate.INTL_Status__c = 'Rejected';
                             //lineitemrejected = true;
                               
                                //break;
                            }
                        }
                lineItemCount ++;
                }
                system.debug('loweststageafteriteration' + lowest);
                if(lineItemCount==lineItemSize && !lineItemOpen && lineItemSigned)
                {
                    system.debug('inside if for signed');
                    opptoUpdate.INTL_Status__c = 'Signed';
                    opptoUpdate.StageName = '6. Complete';
                    system.debug('opp to be signed' + opptoUpdate);
                }
               /* else if(lineitemrejected)
                {
                opptoUpdate.INTL_Status__c = 'Rejected';
                opptoUpdate.StageName = '6. Complete';
                }*/
               
                else
                {
                system.debug('Lowest stage is :::: '+ getStage(lowest));
                opptoUpdate.StageName = getStage(lowest);//ERROR OF NULL RETURNED BY THIS METHOD
                }
                system.debug('Updated Opportunity' + opptoUpdate);
                updateOppList.add(opptoUpdate);


             }

             if(updateOppList!=null && updateOppList.size()>0)
             update updateOppList;
            
             for(Opportunity LastUpdatedOpp : updateOppList)
             {
             LastUpdatedOpp.Flag__c = false;
             LastUpdateOppList.add(LastUpdatedOpp);
             }
            
             if(LastUpdateOppList!=null && LastUpdateOppList.size()>0)
             update LastUpdateOppList;
            

  }


}

 

In this Portion ERROR Is:-apex class Update_OpportunityStageAndStatus_Class in which if you see line number 186,187 you will find getStage(lowest) having null value

 

With Regards

Prabhash Mishra

pcmca_2007@yahoo.co.inpcmca_2007@yahoo.co.in

Hi,

    Yesterday I posted the code for Trigger and class but till now I have't got any response.Can anyone suggest me

    the solution to this problem as it is urgent.

 

  With Regards

Prabhash Mishra

 

ritika@developerforceritika@developerforce

Hi,

 

By looking into the method getStage , it seems it can never return null, or throw a null exception. Even if you pass null in the argument (which again seems not possible looking at assignWieght method).

 

Can you please post the Null pointer exception you are getting at that line. Before that, please also debug variable 'lowest' and current stageName.

 

Regards,

Ritika