0
CsvAttach__c csv=new CsvAttach__c();
String[] fieldsData=readArray[1].split(‘,’);

For(Integer j=0;j<2 ;j++){
 if(String.isNotEmpty(fieldsData[j] &&  field[j]==‘Subject’){
csv.put(Schema.CsvAttach__c,fieldsData[j]);
}else if(String.isNotEmpty(fieldsData[j] &&  field[j]==‘Describe’){
csv.put(Schema.CsvAttach__c.Describe__c,fieldsData[j]);
}
listTobeUpdated.add(csv);
}

insert listTobeUpdated;
}

\no error from code side but Describe field is not getting inserted in object when I debug I got to know it is taking null value (‘Subject,Describe’) array is in this form

  • Should the first csv.put not also include the field token e.g. Schema.CsvAttach__c.Subject__c? It is hard to see what you are trying to accomplish here; it looks like perhaps store the CSV column headings if they match specific words, but the headings row would more likely be readArray[0].split(‘,’);. – Keith C Apr 26 at 10:40
  • yes String[] field=readArray[0].split(‘,’); which consists first row of the Attachment and i m comparing with static value. – Sowmya Kasam Apr 26 at 11:25
  • yes first csv.put (Schema.CsvAttach__c.Subject__c,fieldsData[j]) – Sowmya Kasam Apr 26 at 11:46
  • This code is rather confusing, and there's not enough information here to find a solution. I recommend (1) editing the code to use static field references instead of put() calls, use proper indentation; naming listToBeUpdated listToBeInserted instead. None of those things are the problem as such but they make what should be very simple code hard to read. And (2), please provide a complete, reproducible example of the problem, including CSV data and all of the code that parses it. – David Reed Apr 26 at 17:47

Your Answer

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

Browse other questions tagged or ask your own question.