You need to sign in to do that
Don't have an account?
iyappan kandasamy 4
Apex test class for fetch records from custom object
Hi,
one more doubt I have
For fetching custom object records I have written Apex code as:
Apex class for fetching Bank object custom records
-------------------------------------------------------------------
public class RetBank
{
public void retrievedata()
{
banks__c[] bk=[select Id,Name from banks__c];
for(banks__c bnk:bk)
{
system.debug('The records are:'+bnk);
}
}
}
Test class
-------------
@isTest
public class RetBanktest
{
static testmethod void banks()
{
RetBank fb=new RetBank();
fb.retrievedata();
}
}
It is WOrking properly but the test class is giving only 75% ..Y it is not giving 100%....Any guidance please....THanks in advance
one more doubt I have
For fetching custom object records I have written Apex code as:
Apex class for fetching Bank object custom records
-------------------------------------------------------------------
public class RetBank
{
public void retrievedata()
{
banks__c[] bk=[select Id,Name from banks__c];
for(banks__c bnk:bk)
{
system.debug('The records are:'+bnk);
}
}
}
Test class
-------------
@isTest
public class RetBanktest
{
static testmethod void banks()
{
RetBank fb=new RetBank();
fb.retrievedata();
}
}
It is WOrking properly but the test class is giving only 75% ..Y it is not giving 100%....Any guidance please....THanks in advance
You need to create test data for banks__c like below,
best regards
My code is only for fetching the data from the custom object ...then why i have to insert the record....Please guidance...thanks
In your apex class method you are quering through banks__c object.
By default pre-existing data cannot be access inside test classes(can be accessed using @isTest(SeeAllData=true) notation).
when executing the test method it is getting emty list for banks__c[] bk
In that case you have to create sample data inside the test class.
Salesforce records that are created in test methods aren’t committed to the database. They’re rolled back when the test finishes execution.
Regards