-1

I have a custom metadata which store some parameters which I need to pass in Post callout.I have stotred the Options in below JSON in that custom metadata

{
  "email": "[email protected]",
  "options": {
    "validateRegex": true,
    "validateMx": true,
    "validateTypo": true,
    "validateDisposable": true,
    "validateSMTP": false
  }
}

enter image description here I have a LWC which pass email from front end to back end. But I want to know, How can I add that email to a JSON in above with custom metadata and create a http request body with that? Is it a possible functionality in apex?

1 Answer 1

0

This is relatively easily achieved by using an Apex class/inner class to define the structure of the JSON.

public class EmailOptions {

    public static String email;
    public static EmailOptionAttributes options;

    public class EmailOptionAttributes {
        public static Boolean validateRegex;
        public static Boolean validateMx;
        public static Boolean validateType;
        public static Boolean validateDisposable;
        public static Boolean validateSMTP;
    }

}

In your Apex you can then create an instance of this based on your Custom Metadata Type and then use the JSON.serialize function to convert the object into a JSON string.

3
  • Thank you Callum MacErlich, Will try and get back to this.
    – Buhuni
    Commented Aug 28, 2023 at 2:13
  • @Buhuni how did you get along with this? Did it work for you? Commented Aug 30, 2023 at 6:01
  • Thank you for that. Thanks once again.
    – Buhuni
    Commented Sep 4, 2023 at 16:41

Not the answer you're looking for? Browse other questions tagged .