public class testAccFields {
public void testAccFields1() {
String sobjectApiName = 'Account';
Integer count = 0;
String runQuery = '';
String test = '';
String allFields = '';
List<String> fieldList = new List<String>();
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Map<String, Schema.SObjectField> fieldMap = schemaMap.get(SobjectApiName).getDescribe().fields.getMap();
Map<String,Integer> recordListbyFieldMap = new Map<String,Integer>();
for(String fieldName : fieldMap.keyset() )
{
if(fieldName == 'Id' || fieldName == 'bank_account_number__c' || fieldName == 'BillingAddress' || fieldName == 'ShippingAddress' || fieldName== 'description' || fieldName == 'BillingStreet')
{
System.debug(fieldName);
}
else {
test += +fieldName+ '!= NULL OR ';
allFields += +fieldName+ ',';
fieldList.add(fieldName);
}
}
List<Account> s = database.countQueryQuery('SELECT Count' +allFields+ 'Id ' + ' FROM Account');
System.debug(s);
FROM
for(Account WHEREacc ': +fieldName+s ') {
for(String fieldName : fieldList){
if(acc.get(fieldName) != NULL'null); {
// system if(recordListbyFieldMap.debugcontainskey('NotfieldName)) Null{
Fields->>' +s recordListbyFieldMap.put(fieldName,recordListbyFieldMap.get(fieldName) + 1);
// }
else {
recordListbyFieldMap.put(fieldName,1);
}
}
}
}
system.debug('fieldName->>'+fieldName'count accounts where Annual Revenue is not null' + recordListbyFieldMap.get('AnnualRevenue'));
}
}
Became Hot Network Question