Activity Forums Salesforce® Discussions How To Get The List Of All Available Sobject In Salesforce Database Using Apex (dynamic Apex)?

  • How To Get The List Of All Available Sobject In Salesforce Database Using Apex (dynamic Apex)?

    Posted by Aman on September 20, 2018 at 3:05 pm

    How To Get The List Of All Available Sobject In Salesforce Database Using Apex (dynamic Apex)?

    shariq replied 6 years, 2 months ago 3 Members · 4 Replies
  • 4 Replies
  • shariq

    Member
    September 20, 2018 at 3:07 pm

    Hi,

    Map<String, Schema.SObjectType> m =  Schema.getGlobalDescribe();

    Thanks

  • Parul

    Member
    September 20, 2018 at 5:57 pm

    Try this code snippet:

    public class ControllerClassName
    {
    public List<String> strList { get;set; }

    public void autoRun()
    {
    Map<String, Schema.SObjectField> objectFields = Schema.getGlobalDescribe().get('Account').getDescribe().fields.getMap();

    strList = new List<String>(objectFields.keySet());

    }
    }

     

    Thanks

  • Parul

    Member
    September 20, 2018 at 6:05 pm

    Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe() ;
    Schema.SObjectType s = m.get('API_Name_Of_SObject') ;
    Schema.DescribeSObjectResult r = s.getDescribe() ;
    Map<String,Schema.SObjectField> fields = r.fields.getMap() ;

     

    Try this code to get all fields dynamically.

     

    Thanks

  • shariq

    Member
    September 20, 2018 at 11:08 pm

    Hi,

    Adding  more -

    You not only get the sobject name but also its properties. You can use properties in your logic.

    Hope this helps

Log In to reply.

Popular Salesforce Blogs