How to load configuration from custom meta data












4















I'm new to Salesforce, though experienced Java developer and I'm trying to load my App's configuration using the recommended method of custom meta data.



I've found this quite poorly documented with most of the hits with Google being marketing material about how good it is, but lacking good concrete examples of usage. These are the approaches I've tried, pulled from online examples, none worked for various reasons. I have two configurations defined, Thing_REST_stable & Thing_REST_latest.



    Thing_REST_stable config;
System.debug('config : ' + config); // Null

Thing_REST__mdt config = new Thing_REST__mdt();
System.debug('config : ' + config); // Empty

Thing_REST__mdt config = new Thing_REST_stable();
System.debug('config : ' + config); // Empty

Thing_REST__mdt conf = [SELECT * FROM Thing_REST_stable];
System.debug('config : ' + config); // fails to compile.


These configurations contain details such as the endpoint, version & credentials for external REST connections. The documentation for this is very poor: https://trailhead.salesforce.com/en/content/learn/modules/custom_metadata_types




  • How do I load these configs with Apex code?

  • How do I select Thing_REST_stable in live code?

  • How do I select Thing_REST_latest in my test code?

  • Can you point out some good examples, documentation?










share|improve this question

























  • What are the "Thing_REST_stable" and "Thing_REST_latest: in your code? What do you want to achieve through custom metadata?

    – Naval Sharma
    Dec 28 '18 at 11:26













  • I am trying to 'load my configuration', as per first sentence, they are the custom metadata objects, created via the UI.

    – Martin of Hessle
    Dec 28 '18 at 12:11













  • What is your use case mate? Looks like you want to query Custom Metadata?

    – Naval Sharma
    Dec 28 '18 at 12:13











  • I have an external REST interface and I do not want credentials in the code, I'm trying to load those, custom metadata seems to be the recommended way to do this, but loading configurations seems a pita in salesforce. This would be trivially easy in most languages. One line in java, System.getenv('endpoint')

    – Martin of Hessle
    Dec 28 '18 at 12:29
















4















I'm new to Salesforce, though experienced Java developer and I'm trying to load my App's configuration using the recommended method of custom meta data.



I've found this quite poorly documented with most of the hits with Google being marketing material about how good it is, but lacking good concrete examples of usage. These are the approaches I've tried, pulled from online examples, none worked for various reasons. I have two configurations defined, Thing_REST_stable & Thing_REST_latest.



    Thing_REST_stable config;
System.debug('config : ' + config); // Null

Thing_REST__mdt config = new Thing_REST__mdt();
System.debug('config : ' + config); // Empty

Thing_REST__mdt config = new Thing_REST_stable();
System.debug('config : ' + config); // Empty

Thing_REST__mdt conf = [SELECT * FROM Thing_REST_stable];
System.debug('config : ' + config); // fails to compile.


These configurations contain details such as the endpoint, version & credentials for external REST connections. The documentation for this is very poor: https://trailhead.salesforce.com/en/content/learn/modules/custom_metadata_types




  • How do I load these configs with Apex code?

  • How do I select Thing_REST_stable in live code?

  • How do I select Thing_REST_latest in my test code?

  • Can you point out some good examples, documentation?










share|improve this question

























  • What are the "Thing_REST_stable" and "Thing_REST_latest: in your code? What do you want to achieve through custom metadata?

    – Naval Sharma
    Dec 28 '18 at 11:26













  • I am trying to 'load my configuration', as per first sentence, they are the custom metadata objects, created via the UI.

    – Martin of Hessle
    Dec 28 '18 at 12:11













  • What is your use case mate? Looks like you want to query Custom Metadata?

    – Naval Sharma
    Dec 28 '18 at 12:13











  • I have an external REST interface and I do not want credentials in the code, I'm trying to load those, custom metadata seems to be the recommended way to do this, but loading configurations seems a pita in salesforce. This would be trivially easy in most languages. One line in java, System.getenv('endpoint')

    – Martin of Hessle
    Dec 28 '18 at 12:29














4












4








4








I'm new to Salesforce, though experienced Java developer and I'm trying to load my App's configuration using the recommended method of custom meta data.



I've found this quite poorly documented with most of the hits with Google being marketing material about how good it is, but lacking good concrete examples of usage. These are the approaches I've tried, pulled from online examples, none worked for various reasons. I have two configurations defined, Thing_REST_stable & Thing_REST_latest.



    Thing_REST_stable config;
System.debug('config : ' + config); // Null

Thing_REST__mdt config = new Thing_REST__mdt();
System.debug('config : ' + config); // Empty

Thing_REST__mdt config = new Thing_REST_stable();
System.debug('config : ' + config); // Empty

Thing_REST__mdt conf = [SELECT * FROM Thing_REST_stable];
System.debug('config : ' + config); // fails to compile.


These configurations contain details such as the endpoint, version & credentials for external REST connections. The documentation for this is very poor: https://trailhead.salesforce.com/en/content/learn/modules/custom_metadata_types




  • How do I load these configs with Apex code?

  • How do I select Thing_REST_stable in live code?

  • How do I select Thing_REST_latest in my test code?

  • Can you point out some good examples, documentation?










share|improve this question
















I'm new to Salesforce, though experienced Java developer and I'm trying to load my App's configuration using the recommended method of custom meta data.



I've found this quite poorly documented with most of the hits with Google being marketing material about how good it is, but lacking good concrete examples of usage. These are the approaches I've tried, pulled from online examples, none worked for various reasons. I have two configurations defined, Thing_REST_stable & Thing_REST_latest.



    Thing_REST_stable config;
System.debug('config : ' + config); // Null

Thing_REST__mdt config = new Thing_REST__mdt();
System.debug('config : ' + config); // Empty

Thing_REST__mdt config = new Thing_REST_stable();
System.debug('config : ' + config); // Empty

Thing_REST__mdt conf = [SELECT * FROM Thing_REST_stable];
System.debug('config : ' + config); // fails to compile.


These configurations contain details such as the endpoint, version & credentials for external REST connections. The documentation for this is very poor: https://trailhead.salesforce.com/en/content/learn/modules/custom_metadata_types




  • How do I load these configs with Apex code?

  • How do I select Thing_REST_stable in live code?

  • How do I select Thing_REST_latest in my test code?

  • Can you point out some good examples, documentation?







apex configuration custom-metadata custom-metadata-types






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 11 at 10:19







Martin of Hessle

















asked Dec 28 '18 at 11:12









Martin of HessleMartin of Hessle

956




956













  • What are the "Thing_REST_stable" and "Thing_REST_latest: in your code? What do you want to achieve through custom metadata?

    – Naval Sharma
    Dec 28 '18 at 11:26













  • I am trying to 'load my configuration', as per first sentence, they are the custom metadata objects, created via the UI.

    – Martin of Hessle
    Dec 28 '18 at 12:11













  • What is your use case mate? Looks like you want to query Custom Metadata?

    – Naval Sharma
    Dec 28 '18 at 12:13











  • I have an external REST interface and I do not want credentials in the code, I'm trying to load those, custom metadata seems to be the recommended way to do this, but loading configurations seems a pita in salesforce. This would be trivially easy in most languages. One line in java, System.getenv('endpoint')

    – Martin of Hessle
    Dec 28 '18 at 12:29



















  • What are the "Thing_REST_stable" and "Thing_REST_latest: in your code? What do you want to achieve through custom metadata?

    – Naval Sharma
    Dec 28 '18 at 11:26













  • I am trying to 'load my configuration', as per first sentence, they are the custom metadata objects, created via the UI.

    – Martin of Hessle
    Dec 28 '18 at 12:11













  • What is your use case mate? Looks like you want to query Custom Metadata?

    – Naval Sharma
    Dec 28 '18 at 12:13











  • I have an external REST interface and I do not want credentials in the code, I'm trying to load those, custom metadata seems to be the recommended way to do this, but loading configurations seems a pita in salesforce. This would be trivially easy in most languages. One line in java, System.getenv('endpoint')

    – Martin of Hessle
    Dec 28 '18 at 12:29

















What are the "Thing_REST_stable" and "Thing_REST_latest: in your code? What do you want to achieve through custom metadata?

– Naval Sharma
Dec 28 '18 at 11:26







What are the "Thing_REST_stable" and "Thing_REST_latest: in your code? What do you want to achieve through custom metadata?

– Naval Sharma
Dec 28 '18 at 11:26















I am trying to 'load my configuration', as per first sentence, they are the custom metadata objects, created via the UI.

– Martin of Hessle
Dec 28 '18 at 12:11







I am trying to 'load my configuration', as per first sentence, they are the custom metadata objects, created via the UI.

– Martin of Hessle
Dec 28 '18 at 12:11















What is your use case mate? Looks like you want to query Custom Metadata?

– Naval Sharma
Dec 28 '18 at 12:13





What is your use case mate? Looks like you want to query Custom Metadata?

– Naval Sharma
Dec 28 '18 at 12:13













I have an external REST interface and I do not want credentials in the code, I'm trying to load those, custom metadata seems to be the recommended way to do this, but loading configurations seems a pita in salesforce. This would be trivially easy in most languages. One line in java, System.getenv('endpoint')

– Martin of Hessle
Dec 28 '18 at 12:29





I have an external REST interface and I do not want credentials in the code, I'm trying to load those, custom metadata seems to be the recommended way to do this, but loading configurations seems a pita in salesforce. This would be trivially easy in most languages. One line in java, System.getenv('endpoint')

– Martin of Hessle
Dec 28 '18 at 12:29










2 Answers
2






active

oldest

votes


















7














Custom Metadata isn't just a drop-in configuration load/save system. It acts in most cases like other metadata objects and variables in Apex and is subject to exactly the same syntax and limitations. Most of the issues you have below have to do with Apex and SOQL syntax, rather than Custom Metadata as such.



If the API name of your Custom Metadata record is Thing_REST__mdt, you must always refer to it as such. If you're maintaining more than one configuration, and a single record defines a configuration, you can populate the name of that configuration (such as Thing_REST_stable) in the record's DeveloperName field, and then query based on that field to access a specific configuration.



Examples



Thing_REST_stable config;
System.debug('config : ' + config);


This is an uninitialized variable, and like any other in Apex is null. Thing_REST_stable isn't the name of the metadata record, but might be the name of a specific configuration (as above).



Thing_REST__mdt config = new Thing_REST_stable();
System.debug('config : ' + config);


Custom metadata objects instantiated in code are blank, much like sObjects. Custom metadata classes do not have static methods like Custom Settings that instantiate them for you. You'll get a syntax error here because Thing_REST_stable and Thing_REST__mdt aren't the same types.



Thing_REST__mdt conf = [SELECT * FROM Thing_REST_stable];
System.debug('config : ' + config);


This is closest to being correct, but SELECT * is not valid SOQL, and you must use the full name of your object (Thing_REST__mdt) in your FROM clause. You might do



Thing_REST__mdt conf = [SELECT My_Field__c, My_Preference__c FROM Thing_REST__mdt WHERE DeveloperName = 'Thing_REST_stable'];


to source two specific fields from a defined configuration.



Thing_REST__mdt config = new Thing_REST__mdt();
System.debug('config : ' + config);


This is the same as the one above, but it's closer to being valid because you use your object's API name Thing_REST__mdt in both locations.



Storing Credentials



The best place to store credentials in Salesforce is not Custom Metadata, which can be read by anyone who has View Setup and Configuration permission. It's a Named Credential, which securely protects the credentials and handles OAuth authentication for you.



Custom Metadata and Custom Settings records can only be secured from users and system administrators in the context of a Managed Package, where they can be set to Protected.






share|improve this answer


























  • Thanks a good answer, clear & too the point, sorry I don't have the score to up vote.

    – Martin of Hessle
    Dec 28 '18 at 13:30











  • The actual credentials have now been moved to apex 'Named Credentials' and retrieved using the same technique.

    – Martin of Hessle
    Jan 11 at 10:21



















2














You can query custom metadata records with a simple SOQL and here is the syntax -



SELECT (ALL FIELDS WITH COMMA SEPARATED) FROM Thing_REST__mdt WHERE DeveloperName = '*metadata_record_developer_name*'



You can not use * like sql syntax. You have to provide all fields API names in the query.




Example :



String devName = 'Thing_REST_stable';

Thing_REST__mdt thingsRestSetting = [ SELECT MasterLabel, DeveloperName FROM Thing_REST__mdt WHERE DeveloperName =:devName ];


You can pass the record developer name in the devName variable based on your environment. If the environment is testing then devName will be set to "Thing_REST_latest".




You can learn more about custom metadata from here.







share|improve this answer

























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "459"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f244900%2fhow-to-load-configuration-from-custom-meta-data%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    7














    Custom Metadata isn't just a drop-in configuration load/save system. It acts in most cases like other metadata objects and variables in Apex and is subject to exactly the same syntax and limitations. Most of the issues you have below have to do with Apex and SOQL syntax, rather than Custom Metadata as such.



    If the API name of your Custom Metadata record is Thing_REST__mdt, you must always refer to it as such. If you're maintaining more than one configuration, and a single record defines a configuration, you can populate the name of that configuration (such as Thing_REST_stable) in the record's DeveloperName field, and then query based on that field to access a specific configuration.



    Examples



    Thing_REST_stable config;
    System.debug('config : ' + config);


    This is an uninitialized variable, and like any other in Apex is null. Thing_REST_stable isn't the name of the metadata record, but might be the name of a specific configuration (as above).



    Thing_REST__mdt config = new Thing_REST_stable();
    System.debug('config : ' + config);


    Custom metadata objects instantiated in code are blank, much like sObjects. Custom metadata classes do not have static methods like Custom Settings that instantiate them for you. You'll get a syntax error here because Thing_REST_stable and Thing_REST__mdt aren't the same types.



    Thing_REST__mdt conf = [SELECT * FROM Thing_REST_stable];
    System.debug('config : ' + config);


    This is closest to being correct, but SELECT * is not valid SOQL, and you must use the full name of your object (Thing_REST__mdt) in your FROM clause. You might do



    Thing_REST__mdt conf = [SELECT My_Field__c, My_Preference__c FROM Thing_REST__mdt WHERE DeveloperName = 'Thing_REST_stable'];


    to source two specific fields from a defined configuration.



    Thing_REST__mdt config = new Thing_REST__mdt();
    System.debug('config : ' + config);


    This is the same as the one above, but it's closer to being valid because you use your object's API name Thing_REST__mdt in both locations.



    Storing Credentials



    The best place to store credentials in Salesforce is not Custom Metadata, which can be read by anyone who has View Setup and Configuration permission. It's a Named Credential, which securely protects the credentials and handles OAuth authentication for you.



    Custom Metadata and Custom Settings records can only be secured from users and system administrators in the context of a Managed Package, where they can be set to Protected.






    share|improve this answer


























    • Thanks a good answer, clear & too the point, sorry I don't have the score to up vote.

      – Martin of Hessle
      Dec 28 '18 at 13:30











    • The actual credentials have now been moved to apex 'Named Credentials' and retrieved using the same technique.

      – Martin of Hessle
      Jan 11 at 10:21
















    7














    Custom Metadata isn't just a drop-in configuration load/save system. It acts in most cases like other metadata objects and variables in Apex and is subject to exactly the same syntax and limitations. Most of the issues you have below have to do with Apex and SOQL syntax, rather than Custom Metadata as such.



    If the API name of your Custom Metadata record is Thing_REST__mdt, you must always refer to it as such. If you're maintaining more than one configuration, and a single record defines a configuration, you can populate the name of that configuration (such as Thing_REST_stable) in the record's DeveloperName field, and then query based on that field to access a specific configuration.



    Examples



    Thing_REST_stable config;
    System.debug('config : ' + config);


    This is an uninitialized variable, and like any other in Apex is null. Thing_REST_stable isn't the name of the metadata record, but might be the name of a specific configuration (as above).



    Thing_REST__mdt config = new Thing_REST_stable();
    System.debug('config : ' + config);


    Custom metadata objects instantiated in code are blank, much like sObjects. Custom metadata classes do not have static methods like Custom Settings that instantiate them for you. You'll get a syntax error here because Thing_REST_stable and Thing_REST__mdt aren't the same types.



    Thing_REST__mdt conf = [SELECT * FROM Thing_REST_stable];
    System.debug('config : ' + config);


    This is closest to being correct, but SELECT * is not valid SOQL, and you must use the full name of your object (Thing_REST__mdt) in your FROM clause. You might do



    Thing_REST__mdt conf = [SELECT My_Field__c, My_Preference__c FROM Thing_REST__mdt WHERE DeveloperName = 'Thing_REST_stable'];


    to source two specific fields from a defined configuration.



    Thing_REST__mdt config = new Thing_REST__mdt();
    System.debug('config : ' + config);


    This is the same as the one above, but it's closer to being valid because you use your object's API name Thing_REST__mdt in both locations.



    Storing Credentials



    The best place to store credentials in Salesforce is not Custom Metadata, which can be read by anyone who has View Setup and Configuration permission. It's a Named Credential, which securely protects the credentials and handles OAuth authentication for you.



    Custom Metadata and Custom Settings records can only be secured from users and system administrators in the context of a Managed Package, where they can be set to Protected.






    share|improve this answer


























    • Thanks a good answer, clear & too the point, sorry I don't have the score to up vote.

      – Martin of Hessle
      Dec 28 '18 at 13:30











    • The actual credentials have now been moved to apex 'Named Credentials' and retrieved using the same technique.

      – Martin of Hessle
      Jan 11 at 10:21














    7












    7








    7







    Custom Metadata isn't just a drop-in configuration load/save system. It acts in most cases like other metadata objects and variables in Apex and is subject to exactly the same syntax and limitations. Most of the issues you have below have to do with Apex and SOQL syntax, rather than Custom Metadata as such.



    If the API name of your Custom Metadata record is Thing_REST__mdt, you must always refer to it as such. If you're maintaining more than one configuration, and a single record defines a configuration, you can populate the name of that configuration (such as Thing_REST_stable) in the record's DeveloperName field, and then query based on that field to access a specific configuration.



    Examples



    Thing_REST_stable config;
    System.debug('config : ' + config);


    This is an uninitialized variable, and like any other in Apex is null. Thing_REST_stable isn't the name of the metadata record, but might be the name of a specific configuration (as above).



    Thing_REST__mdt config = new Thing_REST_stable();
    System.debug('config : ' + config);


    Custom metadata objects instantiated in code are blank, much like sObjects. Custom metadata classes do not have static methods like Custom Settings that instantiate them for you. You'll get a syntax error here because Thing_REST_stable and Thing_REST__mdt aren't the same types.



    Thing_REST__mdt conf = [SELECT * FROM Thing_REST_stable];
    System.debug('config : ' + config);


    This is closest to being correct, but SELECT * is not valid SOQL, and you must use the full name of your object (Thing_REST__mdt) in your FROM clause. You might do



    Thing_REST__mdt conf = [SELECT My_Field__c, My_Preference__c FROM Thing_REST__mdt WHERE DeveloperName = 'Thing_REST_stable'];


    to source two specific fields from a defined configuration.



    Thing_REST__mdt config = new Thing_REST__mdt();
    System.debug('config : ' + config);


    This is the same as the one above, but it's closer to being valid because you use your object's API name Thing_REST__mdt in both locations.



    Storing Credentials



    The best place to store credentials in Salesforce is not Custom Metadata, which can be read by anyone who has View Setup and Configuration permission. It's a Named Credential, which securely protects the credentials and handles OAuth authentication for you.



    Custom Metadata and Custom Settings records can only be secured from users and system administrators in the context of a Managed Package, where they can be set to Protected.






    share|improve this answer















    Custom Metadata isn't just a drop-in configuration load/save system. It acts in most cases like other metadata objects and variables in Apex and is subject to exactly the same syntax and limitations. Most of the issues you have below have to do with Apex and SOQL syntax, rather than Custom Metadata as such.



    If the API name of your Custom Metadata record is Thing_REST__mdt, you must always refer to it as such. If you're maintaining more than one configuration, and a single record defines a configuration, you can populate the name of that configuration (such as Thing_REST_stable) in the record's DeveloperName field, and then query based on that field to access a specific configuration.



    Examples



    Thing_REST_stable config;
    System.debug('config : ' + config);


    This is an uninitialized variable, and like any other in Apex is null. Thing_REST_stable isn't the name of the metadata record, but might be the name of a specific configuration (as above).



    Thing_REST__mdt config = new Thing_REST_stable();
    System.debug('config : ' + config);


    Custom metadata objects instantiated in code are blank, much like sObjects. Custom metadata classes do not have static methods like Custom Settings that instantiate them for you. You'll get a syntax error here because Thing_REST_stable and Thing_REST__mdt aren't the same types.



    Thing_REST__mdt conf = [SELECT * FROM Thing_REST_stable];
    System.debug('config : ' + config);


    This is closest to being correct, but SELECT * is not valid SOQL, and you must use the full name of your object (Thing_REST__mdt) in your FROM clause. You might do



    Thing_REST__mdt conf = [SELECT My_Field__c, My_Preference__c FROM Thing_REST__mdt WHERE DeveloperName = 'Thing_REST_stable'];


    to source two specific fields from a defined configuration.



    Thing_REST__mdt config = new Thing_REST__mdt();
    System.debug('config : ' + config);


    This is the same as the one above, but it's closer to being valid because you use your object's API name Thing_REST__mdt in both locations.



    Storing Credentials



    The best place to store credentials in Salesforce is not Custom Metadata, which can be read by anyone who has View Setup and Configuration permission. It's a Named Credential, which securely protects the credentials and handles OAuth authentication for you.



    Custom Metadata and Custom Settings records can only be secured from users and system administrators in the context of a Managed Package, where they can be set to Protected.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 28 '18 at 13:29

























    answered Dec 28 '18 at 12:32









    David ReedDavid Reed

    37.4k82256




    37.4k82256













    • Thanks a good answer, clear & too the point, sorry I don't have the score to up vote.

      – Martin of Hessle
      Dec 28 '18 at 13:30











    • The actual credentials have now been moved to apex 'Named Credentials' and retrieved using the same technique.

      – Martin of Hessle
      Jan 11 at 10:21



















    • Thanks a good answer, clear & too the point, sorry I don't have the score to up vote.

      – Martin of Hessle
      Dec 28 '18 at 13:30











    • The actual credentials have now been moved to apex 'Named Credentials' and retrieved using the same technique.

      – Martin of Hessle
      Jan 11 at 10:21

















    Thanks a good answer, clear & too the point, sorry I don't have the score to up vote.

    – Martin of Hessle
    Dec 28 '18 at 13:30





    Thanks a good answer, clear & too the point, sorry I don't have the score to up vote.

    – Martin of Hessle
    Dec 28 '18 at 13:30













    The actual credentials have now been moved to apex 'Named Credentials' and retrieved using the same technique.

    – Martin of Hessle
    Jan 11 at 10:21





    The actual credentials have now been moved to apex 'Named Credentials' and retrieved using the same technique.

    – Martin of Hessle
    Jan 11 at 10:21













    2














    You can query custom metadata records with a simple SOQL and here is the syntax -



    SELECT (ALL FIELDS WITH COMMA SEPARATED) FROM Thing_REST__mdt WHERE DeveloperName = '*metadata_record_developer_name*'



    You can not use * like sql syntax. You have to provide all fields API names in the query.




    Example :



    String devName = 'Thing_REST_stable';

    Thing_REST__mdt thingsRestSetting = [ SELECT MasterLabel, DeveloperName FROM Thing_REST__mdt WHERE DeveloperName =:devName ];


    You can pass the record developer name in the devName variable based on your environment. If the environment is testing then devName will be set to "Thing_REST_latest".




    You can learn more about custom metadata from here.







    share|improve this answer






























      2














      You can query custom metadata records with a simple SOQL and here is the syntax -



      SELECT (ALL FIELDS WITH COMMA SEPARATED) FROM Thing_REST__mdt WHERE DeveloperName = '*metadata_record_developer_name*'



      You can not use * like sql syntax. You have to provide all fields API names in the query.




      Example :



      String devName = 'Thing_REST_stable';

      Thing_REST__mdt thingsRestSetting = [ SELECT MasterLabel, DeveloperName FROM Thing_REST__mdt WHERE DeveloperName =:devName ];


      You can pass the record developer name in the devName variable based on your environment. If the environment is testing then devName will be set to "Thing_REST_latest".




      You can learn more about custom metadata from here.







      share|improve this answer




























        2












        2








        2







        You can query custom metadata records with a simple SOQL and here is the syntax -



        SELECT (ALL FIELDS WITH COMMA SEPARATED) FROM Thing_REST__mdt WHERE DeveloperName = '*metadata_record_developer_name*'



        You can not use * like sql syntax. You have to provide all fields API names in the query.




        Example :



        String devName = 'Thing_REST_stable';

        Thing_REST__mdt thingsRestSetting = [ SELECT MasterLabel, DeveloperName FROM Thing_REST__mdt WHERE DeveloperName =:devName ];


        You can pass the record developer name in the devName variable based on your environment. If the environment is testing then devName will be set to "Thing_REST_latest".




        You can learn more about custom metadata from here.







        share|improve this answer















        You can query custom metadata records with a simple SOQL and here is the syntax -



        SELECT (ALL FIELDS WITH COMMA SEPARATED) FROM Thing_REST__mdt WHERE DeveloperName = '*metadata_record_developer_name*'



        You can not use * like sql syntax. You have to provide all fields API names in the query.




        Example :



        String devName = 'Thing_REST_stable';

        Thing_REST__mdt thingsRestSetting = [ SELECT MasterLabel, DeveloperName FROM Thing_REST__mdt WHERE DeveloperName =:devName ];


        You can pass the record developer name in the devName variable based on your environment. If the environment is testing then devName will be set to "Thing_REST_latest".




        You can learn more about custom metadata from here.








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 28 '18 at 14:40









        codeyinthecloud

        3,5901428




        3,5901428










        answered Dec 28 '18 at 12:39









        Naval SharmaNaval Sharma

        1,167414




        1,167414






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Salesforce Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f244900%2fhow-to-load-configuration-from-custom-meta-data%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Wiesbaden

            To store a contact into the json file from server.js file using a class in NodeJS

            Marschland