Good day everyone,
Maybe this question is basic for everyone but I'm having a problem with it, so I'm asking for help. I have created a BATCH ITERABLE
.
global with sharing class batchProcessor implements Database.batchable<String>, Database.Stateful
{
global Iterable<String> start(Database.batchableContext batchableContext)
{
// m_csvFile is blob data in csv file
return new CSVIterator(m_csvFile.toString(), Parser.crlf);
}
global void execute(Database.BatchableContext batchableContext, List<String> scope)
{
// I want to get the first row of the csv or the header for mapping
System.debug(scope[0]);
}
}
This is also my CSVIterator.class
global with sharing class CSVIterator implements Iterator<String>, Iterable<String>
{
private String m_CSVData;
private String m_introValue;
public CSVIterator(String fileData, String introValue)
{
m_CSVData = fileData;
m_introValue = introValue;
}
global Boolean hasNext()
{
return m_CSVData.length() > 1 ? true : false;
}
global String next()
{
String row = m_CSVData.subString(0, m_CSVData.indexOf(m_introValue));
m_CSVData = m_CSVData.subString(m_CSVData.indexOf(m_introValue) + m_introValue.length(),m_CSVData.length());
return row;
}
global Iterator<String> Iterator()
{
return this;
}
}
What i want to get at the moment is the first row of the iterable which is the csv header. As you've seen in my batch class i try to System.debug the scope[0] but the result is not the csv header ? How will i do it ?
Pls help.
Thank you !!!