How to access Salesforce Data Model via Apex?

In this blog post, we will see how to access Salesforce Data Model via Apex. The describeSObjects Schema method, tokens and describe results can be utilized for describing sObjects programmatically. Metadata information, such as a list of top-level standard and custom objects and their fields can be retrieved.

  • Describe information provides metadata about sObject and field properties.
  • Information related to operations supported by sObjects, such as create or undelete, can be returned.
  • Information such as the sObject’s name, label, child objects, and fields can be returned.
  • Describe information provides information about objects and not records of the objects.
  • There are two data structures and a method available for sObject and field describe information:
    Token
    Describe result
    The describeSObjects method

Tokens:

Tokens are lightweight reference to an sObject or field which make code faster and more efficient. Both sObjects and fields can be described using tokens.

  • The getSObjectType method can be used to access the token for an object.
  • The getSObjectField method can be used to access the token for a field.
  • The sObjectType member variable can also be used on an sObject Type, such as Account, to access the token for the sObject.
  • The static member variable name of an sObject static type, such as Account.Name, can be used to access the token for the related field. The getDescribe method is used to return the describe result for the token.

Schema Method:

  • The describeSObjects Schema method can be used to describe sObjects.
  • The describeSObjects Schema method can be called and passed one or more sObject type names.
  • An object of the DescribeSObjectResult class can be used to store the results of the obtained describe information.

Describe Result

  • Methods available in the DescribeSObjectResult class can be used for describing sObjects.
  • Methods available in the DescribeFieldResult class can be used for describing sObject fields.
  • The describe result for an sObject or field can be accessed by calling the getDescribe method.
  • The Schema sObjectType static variable with the name of the sObject can also be used to access the describe result.

Schema Namespace Classes

A number of important classes are provided by the Schema namespace for Schema metadata information:

DescribeSobjectResult – Contains methods for describing sObjects
DescribeFieldResult – Contains methods for describing sObject fields
DescribeTabSetResult – Contains methods for obtaining metadata information about a
standard or custom app
DescribeTabResult– Contains methods for obtaining metadata information about a tab in a standard or custom app
RecordTypeInfo – Contains methods for obtaining metadata information about record types of an object
SObjectType – An object of this class is returned from the field describe result using the getReferenceTo() method, or from the sObject describe result using the getSobjectType() method
SObjectField – An object of this class is returned from the field describe result using the getController() and getSObjectField() methods.

To Learn more: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_describesobject.htm

This Post Has 8 Comments

  1. berkey

    It’s in fact very complicated in this full of activity life to listen news on Television, so I just use internet for that purpose, and obtain the most up-to-date news.|

  2. Chong Manor

    Your home is valueble for me. Thanks!? This web page is really a walk-via for all of the information you needed about this and didn know who to ask. Glimpse right here, and you l definitely uncover it.

  3. the feed

    It’s very simple to find out any matter on net as compared to textbooks, as I found this piece of writing at this website.|

  4. the feed

    If you are going for best contents like I do, only go to see this web site all the time for the reason that it gives feature contents, thanks|

  5. thefeed

    I really like your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to do it for you? Plz answer back as I’m looking to create my own blog and would like to know where u got this from. kudos|

  6. the feed

    Howdy! I’m at work surfing around your blog from my new iphone 4! Just wanted to say I love reading your blog and look forward to all your posts! Keep up the superb work!|

  7. feed

    What’s up i am kavin, its my first time to commenting anyplace, when i read this paragraph i thought i could also create comment due to this brilliant article.|

  8. Thank you for some other informative blog. The place else could I get that kind of info written in such an ideal method? I’ve a challenge that I’m just now running on, and I have been on the look out for such info.|

Leave a Reply