Hey Salesforce Ohana, I am back with new blog post. In this blog I will explain How to create a Remote Site Setting through coding.
Most of developer or admin usually create Remote Site Setting through Remote Sites Section [Administer -> Security Control -> Remote Site Settings] in your Salesforce organization.
If you do not know what is Remote Site Setting?
Why we use Remote site setting?
You can refer this blog post for complete details.
Now it’s time for coding.
Before starting , you should know about MetaData API .
A Secrete key to access, create your salesforce.com Metadata like Workflows, Remote Site, Validation Rules.
Let’s download MetaData WSDL File [Build -> API -> MetaData WSDL] and generate apex class using this WSDL File [Build -> Develop -> Apex Classes -> Generate from WSDL] or you can refer this MetadataService apex class.
Add your Salesforce Organization domain name and your visualforce page domain name in Remote site setting by following steps.
[Administer -> Security Control -> Remote Site Settings]
Now, Create a Visualforce Page for input Remote site details and apex controller for business logic.
Below is your apex controller code which will call MetaDataPort Method in the MetaDataService apex class for generating of session Id your salesforce organization and enter remote site details and call createMetaData() method.
You can refer the complete code here.
Hope you find this helpful, in case of any queries/concerns, please post a reply or drop an email to me at firstname.lastname@example.org .
Happy Coding 🙂