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
Bhu'1 salesforceBhu'1 salesforce 

PP_Map.get(CP_Map.get(c.email))) is getting null + need help ??

Program where am getting null in the PP_Map.get(CP_Map.get(c.email)))Debug Log displaying Null

Thanks 
Bhu'1
Best Answer chosen by Bhu'1 salesforce
Bhu'1 salesforceBhu'1 salesforce
Hi Suresh,

I guess this code should work for multiple contacts importing from csv., right, Correct me if am Wrong some where ??
I have got neither error nor debug log error. Successed but couldn't trace out whats fone wrong.

Code:
 public void importCSVFile(){
       try{
           csvAsString = csvFileBody.toString();
           csvFileLines = csvAsString.split('\n'); 
           for(Integer i=1;i<csvFileLines.size();i++){
               Contact conObj = new Contact() ;    
               string[] csvRecordData = csvFileLines[i].split(',');
               conObj.FirstName= csvRecordData[0];             
               conObj.LastName= csvRecordData[1];
               conObj.Email= csvRecordData[2];
               conObj.Phone= csvRecordData[3];                                                                              
               conlist.add(conObj);  
               CP_Map.put(conObj.Email.trim(),csvRecordData[4].trim()); 
               system.debug('@@@@@@@@@@@@@@@@@@@'+ CP_Map);
           }

Debug log : When inserting multiple contacts from csv and the error msg.
Debug log

All Answers

suresh sanneboina 4suresh sanneboina 4
Hi,

I could n't see any issues in the code. if possible can you use trim() when adding to map.
Amit Chaudhary 8Amit Chaudhary 8
hi Bhu'1 salesforce 

In your  PP_Map Key is program name but in for loop you are try to get map value from contact Email .
Is program name is email id ? if no then very time you will get null only
 
Bhu'1 salesforceBhu'1 salesforce
Hi Suresh & Amit,

Thanks for your prompt replies, Am trying to insert data from .CSV file, to insert contact, member with program name, but i am get null for program id, while inserting member.

Also this is inserting only for one row. Please let me know how to insert multiple rows in the csv. to insert contacts, members with programid.

Thanks in Advance,
Bhu'1


Please find the code,
suresh sanneboina 4suresh sanneboina 4
Hi,

In the code that you posted here will work for multiple records. since you are looping the csvFileLines. Code looks good and it has to work. use CP_Map.put(conObj,Email.trim(),csvRecordData[4].trim()); instead of CP_Map.put(conObj,Email,csvRecordData[4]);
Bhu'1 salesforceBhu'1 salesforce
Thank you Very much @suresh sanneboina 4 - its working for a single record row in csv file, but not for bulk contacts from csv file.

Please let me know, how to process bulk data..... from csv, Its throwing some error.

Thanks in Advance....

 
suresh sanneboina 4suresh sanneboina 4
Hi,

Try to follow the eg. mentioned in the link below. I am doing this reading the csv file from documents and loading data to objects.
http://sfdcintegration.blogspot.in/2016/07/read-csv-file-from-documents-and-create.html

can you please post the error what you are getting. so that i can get what exactly the issue you are facing.
 
Bhu'1 salesforceBhu'1 salesforce
Hi Suresh,

I guess this code should work for multiple contacts importing from csv., right, Correct me if am Wrong some where ??
I have got neither error nor debug log error. Successed but couldn't trace out whats fone wrong.

Code:
 public void importCSVFile(){
       try{
           csvAsString = csvFileBody.toString();
           csvFileLines = csvAsString.split('\n'); 
           for(Integer i=1;i<csvFileLines.size();i++){
               Contact conObj = new Contact() ;    
               string[] csvRecordData = csvFileLines[i].split(',');
               conObj.FirstName= csvRecordData[0];             
               conObj.LastName= csvRecordData[1];
               conObj.Email= csvRecordData[2];
               conObj.Phone= csvRecordData[3];                                                                              
               conlist.add(conObj);  
               CP_Map.put(conObj.Email.trim(),csvRecordData[4].trim()); 
               system.debug('@@@@@@@@@@@@@@@@@@@'+ CP_Map);
           }

Debug log : When inserting multiple contacts from csv and the error msg.
Debug log
This was selected as the best answer
suresh sanneboina 4suresh sanneboina 4
Hi 

public void importCSVFile(){
       try{
           csvAsString = csvFileBody.toString();
           csvFileLines = csvAsString.split('\n'); 
           System.debug('Total Lines:'+csvFileLines.size());
           for(Integer i=0;i<csvFileLines.size();i++){
                System.debug('Line No:'+csvFileLines[i]);
               Contact conObj = new Contact() ;    
               string[] csvRecordData = csvFileLines[i].split(',');
               conObj.FirstName= csvRecordData[0];             
               conObj.LastName= csvRecordData[1];
               conObj.Email= csvRecordData[2];
               conObj.Phone= csvRecordData[3];                                                                              
               conlist.add(conObj);  
               CP_Map.put(conObj.Email.trim(),csvRecordData[4].trim()); 
               system.debug('@@@@@@@@@@@@@@@@@@@'+ CP_Map);
           }

try this in the debug you can see all the lines in the debug.