Create Remote Site Setting through Visualforce Page

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 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.

- This Visualforce Page is created for Remote Site Creation
- using MetaDataService apex class.
- @author Sagar Sindhi
- @since 10.03.2018
- @revision N/A
<apex:page docType="html-5.0" sidebar="false" controller="RemoteSiteCreationExt">
<!-- Page Message to display success or error message -->
<apex:PageMessages id="msg" />
<apex:pageBlock title="Remote Site Setting" id="RmtBlck">
<apex:pageBlockSection columns="2" id="RblckSec">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Name"/>
<apex:inputText id="rmtname" value="{!RemoteName}"/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="URL"/>
<apex:inputText id="rmturl" value="{!RemoteUrl}"/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Descripton"/>
<apex:inputTextArea id="rmtdesc" value="{!RemoteDescription}"/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Active"/>
<apex:inputCheckbox id="rmtact" value="{!RemoteActive}"/>
<div align="center">
<apex:commandButton value="Create Remote Site" action="{!RemoteSiteCreation}" reRender="msg,RmtBlck" status="actStatusId"/>
<apex:actionStatus id="actStatusId">
<apex:facet name="start">
<div class="waitingSearchDiv" id="el_loading" style="background-color: #fbfbfb;height: 100%;opacity:0.75;width:100%;">
<div class="waitingHolder" style="top:150px; width: 40px;">
<img class="waitingImage" src="/img/loading.gif" title="Please Wait..." />
* This Apex class is used for bussiness logic
* with RemoteSiteCreation Visualforce Page to
* call the MetaDataService class for Remote
* Site Creation.
* @author Sagar Sindhi
* @since 10.03.2018
* @revision N/A
public with sharing class RemoteSiteCreationExt {
public String RemoteName {get;set;}
public String RemoteUrl {get;set;}
public String RemoteDescription {get;set;}
public Boolean RemoteActive {get;set;}
public void RemoteSiteCreation()
String resultMessage;
if(String.isEmpty(RemoteName) && String.isEmpty(RemoteUrl))
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please Enter Name and URL'));
else if(String.isEmpty(RemoteName))
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please Enter Name'));
else if(String.isEmpty(RemoteUrl))
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please Enter URL'));
MetadataService.MetadataPort ServiceCreation = new MetadataService.MetadataPort();
ServiceCreation.SessionHeader = new MetadataService.SessionHeader_element();
ServiceCreation.SessionHeader.sessionId = UserInfo.getSessionId();
MetadataService.RemoteSiteSetting remoteSiteSettings = new MetadataService.RemoteSiteSetting();
remoteSiteSettings.fullName = RemoteName;
remoteSiteSettings.url = RemoteUrl;
remoteSiteSettings.description= RemoteDescription;
remoteSiteSettings.isActive= RemoteActive;
MetadataService.SaveResult[] results = ServiceCreation.createMetadata(new List<MetadataService.Metadata> { remoteSiteSettings });
for(MetadataService.SaveResult sr : results)
if(sr.errors != NULL)
for(MetadataService.Error er : sr.errors)
resultMessage = er.message;
if(results[0].success == true)
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Remote Site Successfully created !!'));
RemoteName = '';
RemoteUrl = '';
RemoteDescription = '';
RemoteActive = false;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, resultMessage));
catch(Exception ex)
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, ex.getMessage()));

Hope you find this helpful, in case of any queries/concerns, please post a reply or drop an email to me at .

Happy Coding 🙂




Salesforce CRM Content – Brief Description about CRM Content and How can Developer and Admin Use CRM Content

Salesforce CRM Content Organize, share, search, and manage content within your organization .Content includes all file types, from traditional business documents such as Microsoft PowerPoint presentations to audio files, video files, Web pages, and Google docs.

It Simplifies content management by incorporating user-friendly features into the following :

  • Organizing
  • Searching
  • Subscribing
  • Contributing

Most of the People Think Why should I Use Salesforce CRM Content? what is the Benefits of using CRM Content ?


I Suggest to those People Please Refer the Below amazing Articles.

So After Understanding the concept let’s Move to the other Step

How to enable CRM Content in your Organization?

Refer Below Link and Enable CRM Content in your Organization Step by Step.

What Salesforce Admin Should Know about CRM Content?

  • Publish Files to Libraries –

Go to the Libraries Tab and click on Contribute .


Choose File from your Local system and Enter Description , Select Library in which you want to Publish the file and Click on Save .



You can Share File with your Standard OR Custom Object But you need to make Lookup field of that Object with Standard Object (Content Version) of CRM Content .

  • Create a New Library –

Click on New Button and enter Name, Description and Unique Name of the Library.


  • Update Content Version –

Select any file Uploaded in CRM Content  From the Top Content Section  Or you can View file from Library and Click on Edit and Select Update Content Version and Choose file and Update the Version of that Content.

Using this you can publish a new Version of the file and update file Properties.



  • CRM Content Permissions ,Custom fields ,Customization of content Page Layouts

Search Salesforce Files in the left side Search Bar.


You would These Options After clicking on Salesforce Files


So These are the all customization which you can do regarding Library Permissions for Users, Create, modify and Delete Fields on Content Version, Manage Validation Rules etc..

Create, modify and delete custom fields is the option where you can make Standard or custom objects Lookup with Content Version So that you can upload file with the object from libraries tab.

As you see in Below Picture I can Upload File with Lead Or Account Object.


What about Developers ?


What Developer should Know about CRM content for working with Apex ?

Below is the CRM Content Object Hierarchy or you can say Data Model . This is thing which Developer must know for working with CRM Content.



ContentWorkspace – ContentWorkspace is a Library which you can use for publish File . You can use Workspace(Library) Id while making Instance of Content Version so the File publish in that Workspace.


ContentWorkspaceDoc – ContentWorkspaceDoc  Represents a link between a document and a public library in Salesforce CRM Content . It allows a document to be shared with multiple libraries.

In the ContentWorkspaceDoc there are two lookup Fields that is ContentWorkspaceId and ContentDocumentId.


ContentDocument – ContentDocument is a document that has been uploaded in library in CRM Content.

For upload file as Content Document you have to Make Instance of Content Version Because Create() call not supported in Content Document.


ContentVersion – This is a Specific Version of a Content Document(File) in CRM Content.


So these are some things Developer or Admin should Know.

Please Refer the Below Links for Complete Details of Content Object.

Click to access salesforce_content_implementation_guide.pdf

Hope you find this helpful, in case of any queries/concerns, please post a reply or drop an email to me at .