1

I am getting error while saving a record.

System.DmlException: Update failed. First exception on row 0 with id a0QM0000004dguSMAQ; first error: INVALID_TYPE_ON_FIELD_IN_RECORD, Approval Status2: value not of required type: : [Valid_for_approval2__c]

Valid_for_approval2__c is a check box.

Here is my piece of code.

public List<ZIS_Quote_Source__c> selectedItem(String quoteid,Integer idx)
     {

      List<ZIS_Quote_Source__c>  qtSource=[Select id,name,Item_Description__c,Valid_for_approval__c,Valid_for_approval2__c,Valid_for_approval3__c,Item_Line__c,Item__c,ZISQuote__c,ZISQuote__r.Total_Unit_price__c,ZISQuote__r.Status__c,ZISQuote__r.id,ZISQuote__r.name,ZISQuote__r.ZI_Supplier__r.Code__c,ZISQuote__r.ZI_Supplier__r.Supplier_Code__c,ZISQuote__r.ZI_Supplier__r.name,ZISQuote__r.ZI_Supplier__r.Performance_Rate__c,Unit_Price__c from ZIS_Quote_Source__c where ZISQuote__c=:quoteid  ORDER BY Item_Line__c];
                            Integer k=0;
        for(QuotedetailwrapperClass dw:detailwrapperList)
        { 
        try{

            if(idx==1)
            qtSource[k].Valid_for_approval__c=dw.supp1chkbx;
            qtSource[k].Valid_for_approval2__c=dw.supp1chkbx2;
            qtSource[k].Valid_for_approval3__c=dw.supp1chkbx3;
            if(idx==2)
            qtSource[k].Valid_for_approval__c=dw.supp2chkbx;
            qtSource[k].Valid_for_approval2__c=dw.supp2chkbx2;
            qtSource[k].Valid_for_approval3__c=dw.supp2chkbx3;
            if(idx==3)
            qtSource[k].Valid_for_approval__c=dw.supp3chkbx;
            qtSource[k].Valid_for_approval2__c=dw.supp3chkbx2;
            qtSource[k].Valid_for_approval3__c=dw.supp3chkbx3;
            if(idx==4)
            qtSource[k].Valid_for_approval__c=dw.supp4chkbx;
            qtSource[k].Valid_for_approval2__c=dw.supp4chkbx2;
            qtSource[k].Valid_for_approval3__c=dw.supp4chkbx3;
            if(idx==5)
            qtSource[k].Valid_for_approval__c=dw.supp5chkbx;
            qtSource[k].Valid_for_approval2__c=dw.supp5chkbx2;
            qtSource[k].Valid_for_approval3__c=dw.supp5chkbx3;
            if(idx==6)
            qtSource[k].Valid_for_approval__c=dw.supp6chkbx;
            qtSource[k].Valid_for_approval2__c=dw.supp6chkbx2;
            qtSource[k].Valid_for_approval3__c=dw.supp6chkbx3;
            if(idx==7)
            qtSource[k].Valid_for_approval__c=dw.supp7chkbx;
            qtSource[k].Valid_for_approval2__c=dw.supp7chkbx2;
            qtSource[k].Valid_for_approval3__c=dw.supp7chkbx3;
            if(idx==8)
            qtSource[k].Valid_for_approval__c=dw.supp8chkbx;
            qtSource[k].Valid_for_approval2__c=dw.supp8chkbx2;
            qtSource[k].Valid_for_approval3__c=dw.supp8chkbx3;
            if(idx==9)
            qtSource[k].Valid_for_approval__c=dw.supp9chkbx;
            qtSource[k].Valid_for_approval2__c=dw.supp9chkbx2;
            qtSource[k].Valid_for_approval3__c=dw.supp9chkbx3;
            if(idx==10)
            qtSource[k].Valid_for_approval__c=dw.supp10chkbx;
            qtSource[k].Valid_for_approval2__c=dw.supp10chkbx2;
            qtSource[k].Valid_for_approval3__c=dw.supp10chkbx3;
            if(idx==11)
            qtSource[k].Valid_for_approval__c=dw.supp11chkbx;
            if(idx==12)
            qtSource[k].Valid_for_approval__c=dw.supp12chkbx;
            if(idx==13)
            qtSource[k].Valid_for_approval__c=dw.supp13chkbx;
            if(idx==14)
            qtSource[k].Valid_for_approval__c=dw.supp14chkbx;
            if(idx==15)
            qtSource[k].Valid_for_approval__c=dw.supp15chkbx;
            if(idx==16)
            qtSource[k].Valid_for_approval__c=dw.supp16chkbx;
            if(idx==17)
            qtSource[k].Valid_for_approval__c=dw.supp17chkbx;
            if(idx==18)
            qtSource[k].Valid_for_approval__c=dw.supp18chkbx;
            if(idx==19)
            qtSource[k].Valid_for_approval__c=dw.supp19chkbx;
            if(idx==20)
            qtSource[k].Valid_for_approval__c=dw.supp20chkbx;

            system.debug('****dw.supp1chkbx****'+dw.supp1chkbx);
            system.debug('****dw.supp1chkbx2****'+dw.supp1chkbx2);
            system.debug('****dw.supp1chkbx3****'+dw.supp1chkbx3);
             }catch(Exception e){

             }
         k++;
        }

        system.debug('****&&&&&&&&&&&&****'+qtSource);

        update  qtSource;
            system.debug('****&&&&&&&&&&&&****');
            system.debug('****&&&&&&&&&&&****'+qtSource[0].Valid_for_approval2__c);
            system.debug('****&&&&&&&&&&&&****'+qtSource[0].Valid_for_approval3__c);   
     return qtSource;
     }

     ///////////////////////DoSave Method//////////////////////
     public void doSave(){
    // selectedItem();
     Integer c=0;

     for(ZI_Quote__c qtcmmnt:quotelst){
     c++;
         if(c==1){
        qtcmmnt.Approval_Comment__c =supplier1comment;   
                }
         if(c==2){
        qtcmmnt.Approval_Comment__c =supplier2comment;   
            }
            if(c==3){
        qtcmmnt.Approval_Comment__c =supplier3comment;   
            }
             if(c==4){
        qtcmmnt.Approval_Comment__c =supplier4comment;   
                }
         if(c==5){
        qtcmmnt.Approval_Comment__c =supplier5comment;   
            }
            if(c==6){
        qtcmmnt.Approval_Comment__c =supplier6comment;   
            }
             if(c==7){
        qtcmmnt.Approval_Comment__c =supplier7comment;   
                }
         if(c==8){
        qtcmmnt.Approval_Comment__c =supplier8comment;   
            }
            if(c==9){
        qtcmmnt.Approval_Comment__c =supplier9comment;   
            }
             if(c==10){
        qtcmmnt.Approval_Comment__c =supplier10comment;   
                }
         if(c==11){
        qtcmmnt.Approval_Comment__c =supplier11comment;   
            }
            if(c==12){
        qtcmmnt.Approval_Comment__c =supplier12comment;   
            }
             if(c==13){
        qtcmmnt.Approval_Comment__c =supplier13comment;   
                }
         if(c==14){
        qtcmmnt.Approval_Comment__c =supplier14comment;   
            }
            if(c==15){
        qtcmmnt.Approval_Comment__c =supplier15comment;   
            }
             if(c==16){
        qtcmmnt.Approval_Comment__c =supplier16comment;   
                }
         if(c==17){
        qtcmmnt.Approval_Comment__c =supplier17comment;   
            }
            if(c==18){
        qtcmmnt.Approval_Comment__c =supplier18comment;   
            }
            if(c==19){
        qtcmmnt.Approval_Comment__c =supplier19comment;   
            }
            if(c==20){
        qtcmmnt.Approval_Comment__c =supplier20comment;   
            }
            selectedItem(qtcmmnt.id,c);
     }
     update quotelst;




     }
0

Finally I am able to resolve the case. I had not mentioned curly bracket for each IF Statement in try block

That was giving error. Below code is error free.

public List<ZIS_Quote_Source__c> selectedItem(String quoteid,Integer idx)
         {

          List<ZIS_Quote_Source__c>  qtSource=[Select id,name,Item_Description__c,Valid_for_approval__c,Valid_for_approval2__c,Valid_for_approval3__c,Item_Line__c,Item__c,ZISQuote__c,ZISQuote__r.Total_Unit_price__c,ZISQuote__r.Status__c,ZISQuote__r.id,ZISQuote__r.name,ZISQuote__r.ZI_Supplier__r.Code__c,ZISQuote__r.ZI_Supplier__r.Supplier_Code__c,ZISQuote__r.ZI_Supplier__r.name,ZISQuote__r.ZI_Supplier__r.Performance_Rate__c,Unit_Price__c from ZIS_Quote_Source__c where ZISQuote__c=:quoteid  ORDER BY Item_Line__c];
                                Integer k=0;
            for(QuotedetailwrapperClass dw:detailwrapperList)
            { 
            try{

                if(idx==1){
                qtSource[k].Valid_for_approval__c=dw.supp1chkbx;
                qtSource[k].Valid_for_approval2__c=dw.supp1chkbx2;
                qtSource[k].Valid_for_approval3__c=dw.supp1chkbx3;
            }
                if(idx==2){
                qtSource[k].Valid_for_approval__c=dw.supp2chkbx;
                qtSource[k].Valid_for_approval2__c=dw.supp2chkbx2;
                qtSource[k].Valid_for_approval3__c=dw.supp2chkbx3;
            }
                if(idx==3){
                qtSource[k].Valid_for_approval__c=dw.supp3chkbx;
                qtSource[k].Valid_for_approval2__c=dw.supp3chkbx2;
                qtSource[k].Valid_for_approval3__c=dw.supp3chkbx3;
                }
                if(idx==4){
                qtSource[k].Valid_for_approval__c=dw.supp4chkbx;
                qtSource[k].Valid_for_approval2__c=dw.supp4chkbx2;
                qtSource[k].Valid_for_approval3__c=dw.supp4chkbx3;
            }
                if(idx==5){
                qtSource[k].Valid_for_approval__c=dw.supp5chkbx;
                qtSource[k].Valid_for_approval2__c=dw.supp5chkbx2;
                qtSource[k].Valid_for_approval3__c=dw.supp5chkbx3;
            }
                if(idx==6){
                qtSource[k].Valid_for_approval__c=dw.supp6chkbx;
                qtSource[k].Valid_for_approval2__c=dw.supp6chkbx2;
                qtSource[k].Valid_for_approval3__c=dw.supp6chkbx3;
            }
                if(idx==7){
                qtSource[k].Valid_for_approval__c=dw.supp7chkbx;
                qtSource[k].Valid_for_approval2__c=dw.supp7chkbx2;
                qtSource[k].Valid_for_approval3__c=dw.supp7chkbx3;
            }
                if(idx==8){
                qtSource[k].Valid_for_approval__c=dw.supp8chkbx;
                qtSource[k].Valid_for_approval2__c=dw.supp8chkbx2;
                qtSource[k].Valid_for_approval3__c=dw.supp8chkbx3;
            }
                if(idx==9){
                qtSource[k].Valid_for_approval__c=dw.supp9chkbx;
                qtSource[k].Valid_for_approval2__c=dw.supp9chkbx2;
                qtSource[k].Valid_for_approval3__c=dw.supp9chkbx3;
                }
            if(idx==10){
                qtSource[k].Valid_for_approval__c=dw.supp10chkbx;
                qtSource[k].Valid_for_approval2__c=dw.supp10chkbx2;
                qtSource[k].Valid_for_approval3__c=dw.supp10chkbx3;
            }            
            if(idx==11){
                qtSource[k].Valid_for_approval__c=dw.supp11chkbx;
            }            
            if(idx==12){
                qtSource[k].Valid_for_approval__c=dw.supp12chkbx;
            }
                if(idx==13){
                qtSource[k].Valid_for_approval__c=dw.supp13chkbx;
            }
                if(idx==14){
                qtSource[k].Valid_for_approval__c=dw.supp14chkbx;
            }
                if(idx==15){
                qtSource[k].Valid_for_approval__c=dw.supp15chkbx;
            }
                if(idx==16){
                qtSource[k].Valid_for_approval__c=dw.supp16chkbx;
            }
                if(idx==17){
                qtSource[k].Valid_for_approval__c=dw.supp17chkbx;
            }
                if(idx==18){
                qtSource[k].Valid_for_approval__c=dw.supp18chkbx;
            }
                if(idx==19){
                qtSource[k].Valid_for_approval__c=dw.supp19chkbx;
            }
                if(idx==20){
                qtSource[k].Valid_for_approval__c=dw.supp20chkbx;
            }
                system.debug('****dw.supp1chkbx****'+dw.supp1chkbx);
                system.debug('****dw.supp1chkbx2****'+dw.supp1chkbx2);
                system.debug('****dw.supp1chkbx3****'+dw.supp1chkbx3);
                 }catch(Exception e){

                 }
             k++;
            }

            system.debug('****&&&&&&&&&&&&****'+qtSource);

            update  qtSource;
                system.debug('****&&&&&&&&&&&&****');
                system.debug('****&&&&&&&&&&&****'+qtSource[0].Valid_for_approval2__c);
                system.debug('****&&&&&&&&&&&&****'+qtSource[0].Valid_for_approval3__c);   
         return qtSource;
         }

         ///////////////////////DoSave Method//////////////////////
         public void doSave(){
        // selectedItem();
         Integer c=0;

         for(ZI_Quote__c qtcmmnt:quotelst){
         c++;
             if(c==1){
            qtcmmnt.Approval_Comment__c =supplier1comment;   
                    }
             if(c==2){
            qtcmmnt.Approval_Comment__c =supplier2comment;   
                }
                if(c==3){
            qtcmmnt.Approval_Comment__c =supplier3comment;   
                }
                 if(c==4){
            qtcmmnt.Approval_Comment__c =supplier4comment;   
                    }
             if(c==5){
            qtcmmnt.Approval_Comment__c =supplier5comment;   
                }
                if(c==6){
            qtcmmnt.Approval_Comment__c =supplier6comment;   
                }
                 if(c==7){
            qtcmmnt.Approval_Comment__c =supplier7comment;   
                    }
             if(c==8){
            qtcmmnt.Approval_Comment__c =supplier8comment;   
                }
                if(c==9){
            qtcmmnt.Approval_Comment__c =supplier9comment;   
                }
                 if(c==10){
            qtcmmnt.Approval_Comment__c =supplier10comment;   
                    }
             if(c==11){
            qtcmmnt.Approval_Comment__c =supplier11comment;   
                }
                if(c==12){
            qtcmmnt.Approval_Comment__c =supplier12comment;   
                }
                 if(c==13){
            qtcmmnt.Approval_Comment__c =supplier13comment;   
                    }
             if(c==14){
            qtcmmnt.Approval_Comment__c =supplier14comment;   
                }
                if(c==15){
            qtcmmnt.Approval_Comment__c =supplier15comment;   
                }
                 if(c==16){
            qtcmmnt.Approval_Comment__c =supplier16comment;   
                    }
             if(c==17){
            qtcmmnt.Approval_Comment__c =supplier17comment;   
                }
                if(c==18){
            qtcmmnt.Approval_Comment__c =supplier18comment;   
                }
                if(c==19){
            qtcmmnt.Approval_Comment__c =supplier19comment;   
                }
                if(c==20){
            qtcmmnt.Approval_Comment__c =supplier20comment;   
                }
                selectedItem(qtcmmnt.id,c);
         }
         update quotelst;




         }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.