You need to sign in to do that
Don't have an account?
SFDC_Learner
Code Coverage
public void m1(){
String fContent =fbody.toString(); List<String> Rows = fContent.split('\n'); DataLoad__c obj; List<DataLoad__c> lstD = new List<DataLoad__c>(); for(Integer i=0;i<Rows.size();i++){ List<String> ColsData = Rows[i].split(','); obj = new DataLoad__c(name=ColsData[0],city__c = ColsData[1],Country__c = ColsData[2]); lstD.add(obj); } system.debug('----> lstD'+lstD); insert lstD;
}
Can you please paste the test class for the above code
Hi,
You have to simply create the instance of class inside the test method and call the method through the instance of class.
public class TestCls
{
public void m1()
{
String fContent =fbody.toString();
List<String> Rows = fContent.split('\n');
DataLoad__c obj;
List<DataLoad__c> lstD = new List<DataLoad__c>();
for(Integer i=0;i<Rows.size();i++){
List<String> ColsData = Rows[i].split(',');
obj = new DataLoad__c(name=ColsData[0],city__c = ColsData[1],Country__c = ColsData[2]);
lstD.add(obj);
}
system.debug('----> lstD'+lstD);
insert lstD;
}
static testmethod void TestCoverage()
{
TestCls t=new TestCls();
t.m1();
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
Hi,
You have to simply create the instance of class inside the test method and call the method through the instance of class.
public class TestCls
{
public void m1()
{
String fContent =fbody.toString();
List<String> Rows = fContent.split('\n');
DataLoad__c obj;
List<DataLoad__c> lstD = new List<DataLoad__c>();
for(Integer i=0;i<Rows.size();i++){
List<String> ColsData = Rows[i].split(',');
obj = new DataLoad__c(name=ColsData[0],city__c = ColsData[1],Country__c = ColsData[2]);
lstD.add(obj);
}
system.debug('----> lstD'+lstD);
insert lstD;
}
static testmethod void TestCoverage()
{
TestCls t=new TestCls();
t.m1();
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Thanks for the reply.
But I got the below error.
Class.TestCls.m1: line 6, column 1 Class.TestCls.TestCoverage: line 25, column 1
System.NullPointerException: Attempt to de-reference a null object
Add null checks before accessing any List, Variable etc. eg.
if(fbody != null)
String fContent =fbody.toString();
List<String> Rows = fContent.split('\n');
if(Rows != null && Rows.size() > 0){
for(Integer i=0;i<Rows.size();i++){
}
}
Thanks,
Pragati