0

I'm trying to extract all the fields of an Account using a custom Apex webservice. As a first step, I wrote some sample code:

global class testweb{
    webservice static Account getAccount(){
        Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); 
        Map<String, Schema.SObjectField> fieldMap = schemaMap.get('Account').getDescribe().fields.getMap();
    }
}

Error: Compile Error: Variable does not exist: schemaMap at line 7 column 45

...

Update

global class AccountExtract{ 
   webservice static Account getallfieldsofaccount() { 
     Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); 
     Map<String,  Schema.SObjectField> fieldMap 
                   =gd.get('Account').getDescribe().fields.getMap();
     system.debug('object map'+gd); 
     system.debug('field map'+fieldMap); 
     return Account; 
   }
}
1
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); 
Map<String, Schema.SObjectField> fieldMap =gd.get('Account').getDescribe().fields.getMap(); 

 system.debug('object map'+gd);
 system.debug('field map'+fieldMap);
10
  • Do orgs still blow up after 100 getGlobalDescribes in a 24-hour period? Jan 20 '14 at 13:19
  • In a single transaction if 100 getGlobalDescribes i have seen governor limit being hit not sure on this org limit for 24 hours Jan 20 '14 at 13:42
  • i tried the same. here is the error that i get:: Compile Error: Non-void method might not return a value or might have statement after a return statement. at line 10 column 2
    – user4902
    Jan 21 '14 at 6:06
  • 1
    put your whole code your return type should be Map and if void then you should not return anything Jan 21 '14 at 7:13
  • 3
    No governor limits on describe callouts present anymore Dec 21 '15 at 6:51
0

Looks like you want to use all fields of Account to perform some query. You can do something like this:

global class AccountExtract { 
    webservice static List<String> getallfieldsofaccount() {
        List<String> Fields = new List<String>();
        Map<String,Schema.SObjectField> fMap = Schema.getGlobalDescribe().get('Account').getDescribe().Fields.getMap(); 
        for ( Schema.SObjectField ft : fMap.values() ) {
            Schema.DescribeFieldResult fd = ft.getDescribe(); 
            if ( fd.isCreateable() ){ 
                Fields.add(fd.getName());
            }
        }
        return Fields;
    }
}

You can then use this List of fields to create your query string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.