You need to sign in to do that
Don't have an account?
venkatsforce
Testcases
how to write test case for this code?
public Account retrieveOrganisation(String orgId) {
Account retOrg = new Account();
String strQuery = 'SELECT ';
Map<String, Schema.sObjectField> mpFields = Schema.sObjectType.Account.fields.getMap();
Set<String> geoFieldPrefixes = new Set<String>();
for (Schema.sObjectField fld: mpFields.values()) if (fld.getDescribe().getName().contains('Longitude') || fld.getDescribe().getName().contains('Latitude')) geoFieldPrefixes.add(fld.getDescribe().getName().split('__',2)[0]);
for (Schema.sObjectField fld: mpFields.values()) {
String fldName=fld.getDescribe().getName();
if (!geoFieldPrefixes.contains(fldName.split('__',2)[0])) strQuery+=fldName+',';
}
if (strQuery.endsWith(',')) strQuery = strQuery.substring(0, strQuery.length() - 1);
strQuery+=' FROM Account WHERE Id=\''+orgId+'\' LIMIT 1';
System.debug('### OUTPUT >>>>> retrieveOrganisation: strQuery: '+strQuery);
retOrg = Database.query(strQuery);
return retOrg;
}
Hi venkat,
You have to make some changes to your controller then after write test class. below is the changed code whose code coverage is 93%.
Apex class:
Test class:
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thanks,
Hitesh Patel
SFDC Certified Developer & Administrator