0

I am inserting records using excel file on VF page. So based on the values I want to map the product names while inserting.

I am trying the below code it is inserting all (I want to insert record if the ap or wc code matches only) and at the same time when i am mapping product name it is taking null value.

Here is my part of the code :

    List<custom_Object__c > CBList =[select Name,Product.Id,Product.Name,WcCode__c,ApCode__c from custom_Object__c Where (ApCode__c IN:PAp) OR (WcCode__c IN:PWc)];
    System.debug('CB List ::' + CBList);

     for(custom_Object__c co : CBList){
     apMap.put(co.ApCode__c,co.Product.Name);

     wcMap.put(co.WcCode__c,co.Product.Name);
         }         
     for (Integer i=1;i<filelines.size();i++){
                    String[] inputvalues = new String[]{};

                     for(custom_Object__c cobRec : CBList){               
                    VFProd__c VF = new VFProd__c();
                    VF.TranNum__c = inputvalues[0];
                    VF.VF_ApCode__c = inputvalues[1] ; 
                    VF.VF_WcCode__c = inputvalues[2]; 
                   if(apMap.ContainsKey(inputvalues[1])){
                    VF.Name = apMap.get(cobRec.Product.Name); 


                        }

                        if(wcMap.ContainsKey(inputvalues[2])){
                    VF.Name = wcMap.get(cobRec.Product.Name);

                        }


                    VFupload.add(VF);
                }
                }

                Insert VFupload; 
1

You are creating the map like this

  apMap.put(co.ApCode__c,co.Product.Name);

Later you are extracting as below:

  VF.Name = apMap.get(cobRec.Product.Name); 

Thats why it is giving null. You should use like this:

 VF.Name = apMap.get(inputvalues[1]); 
1
  • 1
    Can you please mark this answer if it solves your purpose Jun 28 '16 at 15:11

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.