+ Start a Discussion
randheer practiserandheer practise 

Can Anyone help me with an Ex of Apex Class and its Testclass using test.loaddata.

As per documentation iam cleared but how to do in practical to a basic Apex class and its Testclass using test.loaddata method
Its urgent please helpme anyone


Thanks in Advance
sfdcMonkey.comsfdcMonkey.com
hi randheer practise

User-added image
 
@isTest
public class StaticResourceTest {

      static testmethod void staticResourceLoad(){
        
        //Load CSV file saved in static resource  
        List<SObject> lstAcc = Test.loadData(Account.sObjectType,'AccountLoad_Test');
        List<SObject> lstCon = Test.loadData(Contact.sObjectType,'ContactLoad_Test');
        
        //Confirm that total number of accounts created are 5
        System.assertEquals(lstAcc.size(), 5);
        
        for(Account a : [SELECT Id, Name, (SELECT FirstName,LastName FROM Contacts) FROM Account where Id IN :lstAcc]){
            //confirm that every Account has associated child contact
            System.assertNotEquals(null, a.contacts);
            
            //confirm that every Account has exactly 2 contacts
            System.assertEquals(a.contacts.size(), 2);
        }
    }
}

thanks 
Please mark it as solved if this helps you so that it will make for others as a proper solution :)