Utility API
The OrchestraCMS Utility API provides programmatic access to select OrchestraCMS metadata. The API offers three access approaches:
- Apex
- JavaScript
- API Endpoint (*Requires that permission to the OrchestraCMSRest Apex class be provided to the relevant profiles within Salesforce)
Examples of each approach are provided.
getBaseLink
Returns the domain portion of the URL of the site. A sample use case may involve the need to write code that will programatically build links to the root of the site regardless of the site the code is executed in. This could be used in conjunction with any of the other calls for getting links to build out fully qualified URLs.
Parameters
- apiVersion : String, The apiVersion that you want to use.
- sname : String, The name of the OrchestraCMS site.
Apex Example
This code example can be run in the Salesforce Developer Console.
Map<String,String> context_parameters = new Map<String,String>();
contect_parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
context_parameters.put('apiVersion','5.0');
cms.ApexServiceInterface oua = (cms.ApexServiceInterface) cms.ServiceEndpoint.getService('OrchestraUtilityAPI', context_parameters);
String response = (String) oua.executeApex('getBaseLink', null);
system.debug('<a href="' + response + '">Go Home</a>');
JavaScript Example
<script>
var parameters = {
sname: 'site_name',// Replace site_name with the name of your OrchestraCMS site
apiVersion: '5.0',
service: 'OrchestraUtilityAPI',
action: 'getBaseLink',
};
var callbackHandler = function(json, Success) {
var parsedJSON = JSON.parse(json);
var parsedResponse = JSON.parse(parsedJSON.responseObject);
$("#linkPlaceholder").html('<a href="'+ parsedResponse+ '">Click here to return Home</a>');
};
var cbComplete = function(textStatus) {
alert('Call has completed')
};
var options = {
cb: callbackHandler,
cbHandlerOnComplete: cbComplete,
readonly: true
};
function callAPI() {
doServiceRequest(parameters, options) ;
};
</script>
<input type="button" name="Call API" value="Test getBaseLink" onClick="callAPI()" /><br/>
<div id="linkPlaceholder"/>
API Endpoint Example
http://www.example.com/services/apexrest/cms/ocmsrest/?action=getBaseLink&service=OrchestraUtilityAPI&apiVersion=5.0
JSON-Serialized Response Example
{
type: "String",
timeNow: "2017-06-06T18:44:23.000Z",
isSuccess: true,
transactionId: null,
responseObject: ""https://www.example.com"",
message: "getBaseLink",
error: null
}
getConfiguration
Returns a boolean value indicating if the provided OrchestraCMS feature is enabled or disabled for the site. A sample use case for this call might involve the development of code that needs spans turrned off, for use across multiple sites/Orgs in such a way that a programmatic check could warn the user to contact their administrator if it is not.
Parameters
- apiVersion : String, The apiVersion that you want to use.
- sname : String, The name of the OrchestraCMS site.
- configName : String, Currently only 'OrchestraCMSSite' is a valid value.
- attribute : String, The attribute to query for the value of. Possible values include:
- alwaysUseUserLanguage - Corresponds to the "Always use Salesforce User Language to detemine language" checkbox found in OrchestraCMS Setup | Languages.
- enableCaseSensitiveURLs - Corresponds to the "Enable Case-sensitive URLs" checkbox found in OrchestraCMS Setup | Details.
- spansTurnedOff - Corresponds to the "Disable Superfluous Span Tags" checkbox found in OrchestraCMS Setup | Details.
Apex Example
This code example can be run in the Salesforce Developer Console.
Map<String, String> parameters = new Map<String, String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('apiVersion','5.0');
parameters.put('configName','OrchestraCMSSite');//Name of the Salesforce Custom Setting
parameters.put('attribute','spansTurnedOff');//Name of the record within the custom setting
cms.ApexServiceInterface oua = (cms.ApexServiceInterface) cms.ServiceEndpoint.getService('OrchestraUtilityAPI', parameters);
Object response = (Object) oua.executeApex('getConfiguration', parameters);
if(response == false){
system.debug('Superfluous Spans must be disabled.');
}
JavaScript Example
<script>
var parameters = {
sname: 'site_name',// Replace site_name with the name of your OrchestraCMS site
apiVersion: '5.0',
service: 'OrchestraUtilityAPI',
action: 'getConfiguration',
configName: 'OrchestraCMSSite',//name of the Salesforce Custom Setting
attribute: 'spansTurnedOff'//Name of the record within the Custom Setting
};
var callbackHandler = function(json, Success) {
var parsedJSON = JSON.parse(json);
if (parsedJSON.isSuccess && JSON.parse(parsedJSON.responseObject) === false) {
alert('Please alert your OrchestraCMS Administrator that Superfluous Spans must be disabled');
}
};
var cbComplete = function(textStatus) {
alert('Call had completed');
};
var options = {
cb: callbackHandler,
cbHandlerOnComplete: cbComplete,
readonly: true
};
function callAPI() {
doServiceRequest(parameters, options) ;
};
</script>
<input type="button" name="Call API" value="Test getConfiguration" onClick="callAPI()" /><br/>
API Endpoint Example
http://www.example.com/services/apexrest/cms/ocmsrest/?action=getConfiguration&service=OrchestraUtilityAPI&apiVersion=5.0&configName=OrchestraCMSSite&attribute=spansTurnedOff
JSON-Serialized Response Example
{
type: "Boolean",
timeNow: "2017-06-05T15:16:49.000Z",
isSuccess: true,
transactionId: null,
responseObject: "false",
message: "spansTurnedOff",
error: null
}
getConfigurationList
Returns boolean values indicating if the provided OrchestraCMS features are enabled or disabled for the site. A sample use case for this call might involve the development of code that needs spans turrned off and case-sensitive URLs turned on, for use across multiple sites/Orgs in such a way that a programmatic check could warn the user to contact their administrator if it is not. The features that can currently queried include:
Parameters
- apiVersion : String, The apiVersion that you want to use.
- sname : String, The name of the OrchestraCMS site.
- configName : String, OrchestraCMSSite or the name of another Salesforce Custom Setting.
- attribute : String, The attribute to query for the value of. Possible values include:
- alwaysUseUserLanguage - Corresponds to the "Always use Salesforce User Language to detemine language" checkbox found in OrchestraCMS Setup | Languages.
- enableCaseSensitiveURLs - Corresponds to the "Enable Case-sensitive URLs" checkbox found in OrchestraCMS Setup | Details.
- spansTurnedOff - Corresponds to the "Disable Superfluous Span Tags" checkbox found in OrchestraCMS Setup | Details.
Apex Example
This code example can be run in the Salesforce Developer Console.
Map<String,String> context_parameters = new Map<String,String>();
context_parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
context_parameters.put('apiVersion','5.0');
cms.ApexServiceInterface oua = (cms.ApexServiceInterface) cms.ServiceEndpoint.getService('OrchestraUtilityAPI', context_parameters);
Map<String,Object> parameters = new Map<String,Object>();
parameters.put('configName','OrchestraCMSSite');//Name of the Salesforce Custom Setting
parameters.put('attributes',new List<String>{'enableCaseSensitiveURLs','spansTurnedOff'});//Names of the records within the custom setting
Map <String,Object> response = (Map <String,Object>) oua.executeApex('getConfigurationList', parameters);
if (response.get('enableCaseSensitiveURLs') == false || response.get('spansTurnedOff') == false){
system.debug('Enable Case-sensitive URLs and Disable superfluous spans must both be enabled.');
}
JavaScript Example
<script>
var parameters = {
sname: 'site_name',// Replace site_name with the name of your OrchestraCMS site
apiVersion: '5.0',
service: 'OrchestraUtilityAPI',
action: 'getConfigurationList',
configName: 'OrchestraCMSSite',//Name of the Salesforce Custom Setting
attributes: JSON.stringify(['spansTurnedOff','enableCaseSensitiveURLs'])//Names of the records within the custom setting
};
var callbackHandler = function(json, Success) {
var parsedJSON = JSON.parse(json);
var parsedResponse = JSON.parse(parsedJSON.responseObject);
if (parsedResponse.enableCaseSensitiveURLs === false || parsedResponse.spansTurnedOff === false) {
alert('Superfluous Spans must be disabled and Case-sensitive URLs must be enabled');
}
};
var cbComplete = function(textStatus) {
alert('Call had completed');
};
var options = {
cb: callbackHandler,
cbHandlerOnComplete: cbComplete,
readonly: true
};
function callAPI() {
doServiceRequest(parameters, options) ;
};
</script>
<input type="button" name="Call API" value="Test getConfigurationList" onClick="callAPI()" /><br/>
API Endpoint Example
http://www.example.com/services/apexrest/cms/ocmsrest/?action=getConfigurationList&service=OrchestraUtilityAPI&apiVersion=5.0&configName=OrchestraCMSSite&attributes=["spansTurnedOff","enableCaseSensitiveURLs"]
JSON-Serialized Response Example
{
type: "Map<String,Boolean>",
timeNow: "2017-06-06T20:31:58.000Z",
isSuccess: true,
transactionId: null,
responseObject: "{"enableCaseSensitiveURLs":false,"spansTurnedOff":false}",
message: "getConfigurationList",
error: null
}
getCurrentLink
Returns a string containing the relative URL of the current page. A sample use case may involve combining this call with the getCurrentPage to retrieve the language codes for languages assigned to the page so they can be presented as languages for the visitor to select from for their preferred language translation.
Parameters
- apiVersion : String, The apiVersion that you want to use.
- sname : String, The name of the OrchestraCMS site.
global virtual with sharing class LangPickerContentTemplate extends cms.ContentTemplateController {
cms.ApexServiceInterface oua;
global LangPickerContentTemplate (cms.CreateContentController cc) {
super(cc);
}
global LangPickerContentTemplate(){
Map<String,String> context_parameters = new Map<String,String>();
context_parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
context_parameters.put('apiVersion','5.0');
oua = (cms.ApexServiceInterface) cms.ServiceEndpoint.getService('OrchestraUtilityAPI', context_parameters);
}
public String baseLink(){
return (String) oua.executeApex('getBaseLink', null);
}
public String currentLink(){
return (String) oua.executeApex('getCurrentLink', null);
}
public OrchestraPage page(){
String thePage = (String) oua.executeApex('getCurrentPage',null);
return (OrchestraPage) JSON.deserialize(thePage, OrchestraPage.class);
}
public class OrchestraPage {
public String accessLevel;
public List<String> availableLanguages;
public String description;
public String masterPageName;
public String pageName;
public DateTime previewStartDate;
public DateTime previewEndDate;
public DateTime publishedStartDate;
public DateTime publishedEndDate;
public Boolean isPublished;
public String SITENAME;
public String title;
public Decimal versionNumber;
public Decimal revisionNumber;
}
global virtual override String getHTML() {
String html = '';
String theBaseLink = baseLink() + currentLink();
OrchestraPage thePage = page();
for (String x : thePage.availableLanguages){
html += '<a href="' + theBaseLink + '&ocmsLang=' + x + '">' + x + '</a> | ';
}
return html;
}
}
JavaScript Example
<script>
var currentURL = '';
var currentLinkParameters = {
sname: 'site_name',// Replace site_name with the name of your OrchestraCMS site
apiVersion: '5.0',
service: 'OrchestraUtilityAPI',
action: 'getCurrentLink'
};
var currentLinkCallbackHandler = function(json, Success) {
var currentLinkParsedJSON = JSON.parse(json);
var currentLinkParsedResponse = JSON.parse(currentLinkParsedJSON.responseObject);
currentURL = currentLinkParsedResponse;
};
var currentLinkcbComplete = function(textStatus) {
alert('Current Link Call Back Complete');
};
var currentLinkOptions = {
cb: currentLinkCallbackHandler,
cbHandlerOnComplete: currentLinkcbComplete,
readonly: true
};
var currentPageParameters = {
sname: 'SITENAME',//replace SITENAME with the name of your OrchestraCMS site
apiVersion: '5.0',
service: 'OrchestraUtilityAPI',
action: 'getCurrentPage'
};
var currentPageCallbackHandler = function(json, Success) {
var currentPageParsedJSON = JSON.parse(json);
var currentPageParsedResponse = JSON.parse(currentPageParsedJSON.responseObject);
var langListString = JSON.stringify(currentPageParsedResponse.availableLanguages);
var langs = JSON.parse(langListString);
for (x in langs){
$('#placeholder').append('[<a href="' + currentURL + '?ocmsLang=' + langs[x] + '">' + langs[x] + '</a>] | ');
};
};
var currentPagecbComplete = function(textStatus) {
alert('Current Page Call Back Complete');
};
var currentPageOptions = {
cb: currentPageCallbackHandler,
cbHandlerOnComplete: currentPagecbComplete,
readonly: true
};
function callAPI() {
doServiceRequest(currentLinkParameters, currentLinkOptions) ;
doServiceRequest(currentPageParameters, currentPageOptions) ;
};
</script>
<input type="button" name="Call API" value="Test getCurrentLink" onClick="callAPI()" /><br/>
Pick a language:<br/>
<div id="placeholder"/>
API Endpoint Example
JSON-Serialized Response Example
{
error: null,
isSuccess: true,
message: "getCurrentLink",
responseObject: ""/prefix/pageURL"",
timeNow: "2017-06-09T15:17:17.000Z",
transactionId: null,
type: "String"
}
getCurrentMultilingualLinks
Returns a map of all the translated URLs for the page with the language code as the key to the map and the values as the translated relative URLs of the current page. A sample use case may involve creating a menu on the page presented as languages for the visitor to select from for their preferred language translation.
Parameters
- apiVersion : String, The apiVersion that you want to use.
- sname : String, The name of the OrchestraCMS site.
global virtual with sharing class LangMenuContentTemplate extends cms.ContentTemplateController {
cms.ApexServiceInterface oua;
global LangMenuContentTemplate (cms.CreateContentController cc) {
super(cc);
}
global LangMenuContentTemplate(){
Map<String,String> context_parameters = new Map<String,String>();
context_parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
context_parameters.put('apiVersion','5.0');
oua = (cms.ApexServiceInterface) cms.ServiceEndpoint.getService('OrchestraUtilityAPI', context_parameters);
}
public Map<String,String> currentMultilingualLinks(){
return (Map<String,String>) oua.executeApex('getCurrentMultilingualLinks', null);
}
global virtual override String getHTML() {
String html = '';
for (String x : currentMultilingualLinks().values()){
html += '<a href="' + x + '">' + x + '</a> | ';
}
return html;
}
}
JavaScript Example
<script>
var parameters = {
sname: 'site_name',// Replace site_name with the name of your OrchestraCMS site
apiVersion: '5.0',
service: 'OrchestraUtilityAPI',
action: 'getCurrentMultilingualLinks'
};
var callbackHandler = function(json, Success) {
var parsedJSON = JSON.parse(json);
var parsedResponse = JSON.parse(parsedJSON.responseObject);
for (x in parsedResponse){
$('#placeholder').append('[<a href="' + parsedResponse[x] + '">' + parsedResponse[x] + '</a>] | ');
};
};
var cbComplete = function(textStatus) {
alert('Call Back Complete');
};
var options = {
cb: callbackHandler,
cbHandlerOnComplete: cbComplete,
readonly: true
};
function callAPI() {
doServiceRequest(parameters, options) ;
};
</script>
<input type="button" name="Call API" value="Test getCurrentMultilingualLinks" onClick="callAPI()" /><br/>
Pick a language:<br/>
<div id="placeholder"/>
API Endpoint Example
JSON-Serialized Response Example
{
"type":"Map<String,String>",
"timeNow":"2017-06-09T17:49:45.000Z",
"isSuccess":true,
"transactionId":null,
"responseObject":"{\"es\":\"/spanishPageURL&ocmsLang=es\",\"fr\":\"/frechPageURL&ocmsLang=fr\",\"en_US\":\"/englishPageURL&ocmsLang=en_US\"}",
"message":"getCurrentMultilingualLinks",
"error":null
}
getCurrentPage
Returns a string containing some of the properties of the current page. A sample use case may involve retrieving the language codes for languages assigned to the page so they can be presented as languages for the visitor to select from for their preferred language translation.
Parameters
- apiVersion : String, The apiVersion that you want to use.
- sname : String, The name of the OrchestraCMS site.
Apex Example
global virtual with sharing class LangPickerContentTemplate extends cms.ContentTemplateController {
cms.ApexServiceInterface oua;
global LangPickerContentTemplate (cms.CreateContentController cc) {
super(cc);
}
global LangPickerContentTemplate(){
Map<String,String> context_parameters = new Map<String,String>();
context_parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
context_parameters.put('apiVersion','5.0');
oua = (cms.ApexServiceInterface) cms.ServiceEndpoint.getService('OrchestraUtilityAPI', context_parameters);
}
public String baseLink(){
return (String) oua.executeApex('getBaseLink', null);
}
public String currentLink(){
return (String) oua.executeApex('getCurrentLink', null);
}
public OrchestraPage page(){
String thePage = (String) oua.executeApex('getCurrentPage',null);
return (OrchestraPage) JSON.deserialize(thePage, OrchestraPage.class);
}
public class OrchestraPage {
public String accessLevel;
public List<String> availableLanguages;
public String description;
public String masterPageName;
public String pageName;
public DateTime previewStartDate;
public DateTime previewEndDate;
public DateTime publishedStartDate;
public DateTime publishedEndDate;
public Boolean isPublished;
public String SITENAME;
public String title;
public Decimal versionNumber;
public Decimal revisionNumber;
}
global virtual override String getHTML() {
String html = '';
String theBaseLink = baseLink() + currentLink();
OrchestraPage thePage = page();
for (String x : thePage.availableLanguages){
html += '<a href="' + theBaseLink + '&ocmsLang=' + x + '">' + x + '</a> | ';
}
return html;
}
}
JavaScript Example
<script>
var parameters = {
sname: 'site_name',// Replace site_name with the name of your OrchestraCMS site
apiVersion: '5.0',
service: 'OrchestraUtilityAPI',
action: 'getCurrentPage'
};
var callbackHandler = function(json, Success) {
var parsedJSON = JSON.parse(json);
var parsedResponse = JSON.parse(parsedJSON.responseObject);
var langListString = JSON.stringify(parsedResponse.availableLanguages);
var currentURL = location.href;
var langs = JSON.parse(langListString);
for (x in langs){
$('#placeholder').append('[<a href="' + currentURL + '?ocmsLang=' + langs[x] + '">' + langs[x] + '</a>] | ');
};
};
var cbComplete = function(textStatus) {
alert('Call has completed');
};
var options = {
cb: callbackHandler,
cbHandlerOnComplete: cbComplete,
readonly: true
};
function callAPI() {
doServiceRequest(parameters, options) ;
};
</script>
<input type="button" name="Call API" value="Test getCurrentPage" onClick="callAPI()" /><br/>
Pick a language:<br/>
<div id="placeholder"/>
API Endpoint Example
JSON-Serialized Response Example
{
"versionNumber":8,
"title":null,
"SITENAME":"sitename",
"revisionNumber":0,
"publishedStartDate":"2017-06-07T18:20:29.000Z",
"publishedEndDate":null,
"previewStartDate":null,
"previewEndDate":null,
"pageName":"HRForms",
"masterPageName":null,
"isPublished":false,
"description":null,
"availableLanguages":["en_US","fr","es"],
"accessLevel":null
}
getHomeLink
Returns the relative root portion of the URL of the site, including prefix if the site has one configured. A sample use case may involve the need to write code that will programatically build links to the root of the site regardless of the site the code is executed in. The OrchestraCMS mode is respected so that a link viewed in Preview mode will be different than one viewed on the live site. This could be used in conjunction with any of the other calls for getting links to build out fully qualified URLs.
Parameters
- apiVersion : String, The apiVersion that you want to use.
- sname : String, The name of the OrchestraCMS site.
Apex Example
This code example can be run in the Salesforce Developer Console.
Map<String,String> context_parameters = new Map<String,String>();
context_parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
context_parameters.put('apiVersion','5.0');
cms.ApexServiceInterface oua = (cms.ApexServiceInterface) cms.ServiceEndpoint.getService('OrchestraUtilityAPI', context_parameters);
String response = (String) oua.executeApex('getHomeLink', null);
system.debug('<a href="' + response + '">Go Home</a>');
JavaScript Example
<script>
var parameters = {
sname: 'site_name',// Replace site_name with the name of your OrchestraCMS site
apiVersion: '5.0',
service: 'OrchestraUtilityAPI',
action: 'getHomeLink',
};
var callbackHandler = function(json, Success) {
var parsedJSON = JSON.parse(json);
var parsedResponse = JSON.parse(parsedJSON.responseObject);
$("#linkPlaceholder").html('<a href="'+ parsedResponse+ '">Click here to return Home</a>');
};
var cbComplete = function(textStatus) {
alert('Call has completed')
};
var options = {
cb: callbackHandler,
cbHandlerOnComplete: cbComplete,
readonly: true
};
function callAPI() {
doServiceRequest(parameters, options) ;
};
</script>
<input type="button" name="Call API" value="Test getHomeLink" onClick="callAPI()" /><br/>
<div id="linkPlaceholder"/>
API Endpoint Example
http://www.example.com/services/apexrest/cms/ocmsrest/?action=getHomeLink&service=OrchestraUtilityAPI&apiVersion=5.0
JSON-Serialized Response Example
{
type: "String",
timeNow: "2017-06-06T18:52:07.000Z",
isSuccess: true,
transactionId: null,
responseObject: ""/prefix/"",
message: "getHomeLink",
error: null
}
getLanguage
Returns a string for the language configuration of the current page context. A sample use case may include the limited execution of a code block based on the language the page is being viewed in.
Parameters
- apiVersion : String, The apiVersion that you want to use.
- sname : String, The name of the OrchestraCMS site.
global virtual with sharing class getLanguageContentTemplate extends cms.ContentTemplateController {
cms.ApexServiceInterface oua;
global getLanguageContentTemplate (cms.CreateContentController cc) {
super(cc);
}
global getLanguageContentTemplate(){
Map<String,String> context_parameters = new Map<String,String>();
context_parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
context_parameters.put('apiVersion','5.0');
oua = (cms.ApexServiceInterface) cms.ServiceEndpoint.getService('OrchestraUtilityAPI', context_parameters);
}
public String getLanguage(){
cms.OrchestraLanguageObject lang = (cms.OrchestraLanguageObject) oua.executeApex('getLanguage', null);
String langName = lang.getName();
return langname;
}
global virtual override String getHTML() {
String html = '';
if (getLanguage() == 'English'){
html += 'You are viewing English';
}
return html;
}
}
JavaScript Example
<script>
var parameters = {
sname: 'site_name',// Replace site_name with the name of your OrchestraCMS site
apiVersion: '5.0',
service: 'OrchestraUtilityAPI',
action: 'getLanguage'
};
var callbackHandler = function(json, Success) {
var parsedJSON = JSON.parse(json);
var parsedResponse = JSON.parse(parsedJSON.responseObject);
var currentLang = parsedResponse.LanguageName;
if (currentLang === 'English'){
alert('This code will only execute when the current language is English');
}
};
var cbComplete = function(textStatus) {
alert('Call Back Complete');
};
var options = {
cb: callbackHandler,
cbHandlerOnComplete: cbComplete,
readonly: true
};
function callAPI() {
doServiceRequest(parameters, options) ;
};
</script>
<input type="button" name="Call API" value="Test getLanguage" onClick="callAPI()" /><br/>
API Endpoint Example
JSON-Serialized Response Example
{
type: "OrchestraLanguageObject",
timeNow: "2017-06-09T19:58:33.000Z",
isSuccess: true,
transactionId: null,
responseObject: "{"Priority":0,"LanguageName":"English","LanguageCode":"en_US","Id":"a0Si00000090DkVEAU","Description":null,"AllowFallback":false,"Active":true}",
message: "getLanguage",
error: null
}
getLanguageCodes
Returns a list of strings for the active language codes of the site. A sample use case may include displaying a list of languages the current site is available in.
Parameters
- apiVersion : String, The apiVersion that you want to use.
- sname : String, The name of the OrchestraCMS site.
This example can be run in the Salesforce Developer Console.
Map<String, String> context_parameters = new Map<String, String >();
context_parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
context_parameters.put('apiVersion', '5.0');
cms.ApexServiceInterface oua = (cms.ApexServiceInterface) cms.ServiceEndpoint.getService('OrchestraUtilityAPI', context_parameters);
List <String> response = (List<String>) oua.executeApex('getLanguageCodes', null);
System.Debug(response);
JavaScript Example
<script>
var parameters = {
sname: 'siteName',
apiVersion: '5.0',
service: 'OrchestraUtilityAPI',
action: 'getLanguageCodes'
};
var callbackHandler = function(json, Success) {
var parsedJSON = JSON.parse(json);
var parsedResponse = JSON.parse(parsedJSON.responseObject);
for (x in parsedResponse){
$('#languageCodesPlaceholder').append(parsedResponse[x]+' | ');
};
};
var cbComplete = function(textStatus) {
alert('Call Back Complete');
};
var options = {
cb: callbackHandler,
cbHandlerOnComplete: cbComplete,
readonly: true
};
function callAPI() {
doServiceRequest(parameters, options) ;
};
</script>
<input type="button" name="Call API" value="Test getLanguageCodes" onClick="callAPI()" /><br/>
This site is available in: <br/>
<div id="languageCodesPlaceholder"/>
API Endpoint Example
https://www.example.com/services/apexrest/cms/ocmsrest/?action=getLanguageCodes&service=OrchestraUtilityAPI&apiVersion=5.0
JSON-Serialized Response Example
{
type: "List<String>",
timeNow: "2017-06-12T14:03:19.000Z",
isSuccess: true,
transactionId: null,
responseObject: "["en_US","fr","es"]",
message: "getLanguageCodes",
error: null
}
getLinks
Returns the relative URL of the specified page. A sample use case may involve the need to write code that will programatically build links to specific pages in the site regardless of the site the code is executed in. The OrchestraCMS mode is respected so that a link viewed in Preview mode will be different than one viewed on the live site. This could be used in conjunction with any of the other calls for getting links to build out fully qualified URLs.
Parameters
- apiVersion : String, The apiVersion that you want to use.
- sname : String, The name of the OrchestraCMS site.
- pageNames : List<String>, A list of the OrchestraCMS page names you want to return the URLs for.
Apex Example
This code example can be run in the Salesforce Developer Console.
Map<String,String> context_parameters = new Map<String,String>();
context_parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
context_parameters.put('apiVersion','5.0');
cms.ApexServiceInterface oua = (cms.ApexServiceInterface) cms.ServiceEndpoint.getService('OrchestraUtilityAPI', context_parameters);
Map<String,Object> parameters = new Map<String,Object>();
parameters.put('pageNames',new List<String>{'pageName1','pageName2'});
Map <String,String> response = (Map <String,String>) oua.executeApex('getLinks', parameters);
for (String x : response.values()){
system.debug('<a href="' + x + '">' + x + '</a>');
}
JavaScript Example
<script>
var parameters = {
sname: 'site_name',// Replace site_name with the name of your OrchestraCMS site
apiVersion: '5.0',
service: 'OrchestraUtilityAPI',
action: 'getLinks',
pageNames: JSON.stringify(['pageName1','pagename2'])
};
var callbackHandler = function(json, Success) {
var parsedJSON = JSON.parse(json);
var parsedResponse = JSON.parse(parsedJSON.responseObject);
for (x in parsedResponse){
$("#linkPlaceholder").append('<a href="'+ parsedResponse[x] + '">'+ parsedResponse[x] + '</a><br/>');
};
};
var cbComplete = function(textStatus) {
alert('Call has completed')
};
var options = {
cb: callbackHandler,
cbHandlerOnComplete: cbComplete,
readonly: true
};
function callAPI() {
doServiceRequest(parameters, options) ;
};
</script>
<input type="button" name="Call API" value="Test getLinks" onClick="callAPI()" /><br/>
<div id="linkPlaceholder"/>
API Endpoint Example
https://www.example.com/services/apexrest/cms/ocmsrest/?action=getLinks&service=OrchestraUtilityAPI&apiVersion=5.0&pageNames=["pageName1","pageName2"]
JSON-Serialized Response Example
{
type: "Map<String,String>",
timeNow: "2017-06-06T19:24:08.000Z",
isSuccess: true,
transactionId: null,
responseObject: "{"pageName1":"/prefix/cms__Main?name=pageURL1","pageName2":"/prefix/cms__Main?name=pageURL2"}",
message: "getLinks",
error: null
}
getLinksSetParams
Returns a list of the relative URLs of the specified pages and appends the specified parameters to the URL. A sample use case may involve the need to write code that will programatically build links to specific pages in the site regardless of the site the code is executed in and then append the programatically populated parameters to the URL. The OrchestraCMS mode is respected so that a link viewed in Preview mode will be different than one viewed on the live site. This could be used in conjunction with any of the other calls for getting links to build out fully qualified URLs. The parameter it takes is params. This would be a map of maps with the outer map key being the page names and the inner map key being the parameters.
Parameters
- apiVersion : String, The apiVersion that you want to use.
- sname : String, The name of the OrchestraCMS site.
- params : Map<String, Map<String, String>>, The name(s) of the pages followed by the parameter(s) to be appended to the URL
Apex Example
This code example can be run in the Salesforce Developer Console.
Map<String,String> context_parameters = new Map<String,String>();
context_parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
context_parameters.put('apiVersion','5.0');
cms.ApexServiceInterface oua = (cms.ApexServiceInterface) cms.ServiceEndpoint.getService('OrchestraUtilityAPI', context_parameters);
Map<String,String> firstPageParameters = new Map<String,String> {'parameter1'=>'value'};
Map<String,String> secondPageParameters = new Map<String,String> {'parameter2'=>'value'};
Map<String,Map<String,String>> pagesWithParameters = new Map<String,Map<String,String>>();
pagesWithParameters.put('pageName1',firstPageParameters);
pagesWithParameters.put('pageName2',secondPageParameters);
Map<String,Object> parameters = new Map<String,Object>();
parameters.put('params',pagesWithParameters);
Map <String,String> response = (Map <String,String>) oua.executeApex('getLinksSetParams', parameters);
for (String x : response.values()){
system.debug('<a href="' + x + '">' + x + '</a>');
}
JavaScript Example
<script>
var parameters = {
sname: 'site_name',// Replace site_name with the name of your OrchestraCMS site
apiVersion: '5.0',
service: 'OrchestraUtilityAPI',
action: 'getLinksSetParams',
params: JSON.stringify({'pageName1': {'parameter': 'value'},'pagename2':{'parameter':'value'}})
};
var callbackHandler = function(json, Success) {
var parsedJSON = JSON.parse(json);
var parsedResponse = JSON.parse(parsedJSON.responseObject);
for (x in parsedResponse){
$("#linkPlaceholder").append('<a href="'+ parsedResponse[x] + '">'+ parsedResponse[x] + '</a><br/>');
};
};
var cbComplete = function(textStatus) {
alert('Call has completed')
};
var options = {
cb: callbackHandler,
cbHandlerOnComplete: cbComplete,
readonly: true
};
function callAPI() {
doServiceRequest(parameters, options) ;
};
</script>
<input type="button" name="Call API" value="Test getLinksSetParams" onClick="callAPI()" /><br/>
<div id="linkPlaceholder"/>
API Endpoint Example
https://www.example.com/services/apexrest/cms/ocmsrest/?action=getLinksSetParams&service=OrchestraUtilityAPI&apiVersion=5.0&configName=OrchestraCMSSite¶ms={"pageName1":{"parameter":"value"},"pageName2":{"parameter":"value"}}
JSON-Serialized Response Example
{
type: "Map<String,String>",
timeNow: "2017-06-07T13:32:03.000Z",
isSuccess: true,
transactionId: null,
responseObject: "{"pageName1":"/cms__Main?name=pageURL1¶meter=value","pageName2":"/cms__Main?name=pageURL2¶meter=value"}",
message: "getLinksSetParams",
error: null
}
getMediaLinks
Returns a map of the relative URLs of the specified files from the OrchestraCMS media library with the file names as the key. A sample use case may involve the need to write code that will programatically build links to media files in the library regardless of the site the code is executed in. The OrchestraCMS mode is respected so that the URL for a file viewed in Preview mode will be different than one viewed on the live site. This could be used in conjunction with any of the other calls for getting links to build out fully qualified URLs. The parameters it takes are mediaNames. This would be a list of file names from the media library or mediaIds which would be a list of Salesforce record Ids of the Library Content records for those files. If mediaNames is used and more than one file with the same name is found, links will be returned for each of the files with that name found in the media library. The return is a map with a key of filename with the URL of the file as the value.
Parameters
- apiVersion : String, The apiVersion that you want to use.
- sname : String, The name of the OrchestraCMS site.
- mediaNames : List<String>, The names of the files from the OrchestraCMS media library.
- mediaIds : List<Id>, The Salesforce record Ids of Library Content records for the files.
Apex Example
This code example can be run in the Salesforce Developer Console.
Map<String,String> context_parameters = new Map<String,String>();
context_parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
context_parameters.put('apiVersion','5.0');
cms.ApexServiceInterface oua = (cms.ApexServiceInterface) cms.ServiceEndpoint.getService('OrchestraUtilityAPI', context_parameters);
Map <String,Object> parameters = new Map <String,Object>();
parameters.put('mediaNames',new List<String> {'fileName1.ext','fileName2.ext'});
Map<String,String> response = (Map<String,String>) oua.executeApex('getMediaLinks', parameters);
for (String x : response.values()){
system.debug('<img src="' + x + '"/>');
}
JavaScript Example
<script>
var parameters = {
sname: 'site_name',// Replace site_name with the name of your OrchestraCMS site
apiVersion: '5.0',
service: 'OrchestraUtilityAPI',
action: 'getMediaLinks',
mediaNames: JSON.stringify(['fileName1.ext','fileName2.ext'])
//Or you can use mediaIds instead of, but not with mediaNames
//mediaIds: JSON.stringify(['a0Ti0000017O97WEAS','00Pi000000RQYDGEA5'])
};
var callbackHandler = function(json, Success) {
var parsedJSON = JSON.parse(json);
var parsedResponse = JSON.parse(parsedJSON.responseObject);
for (x in parsedResponse){
$("#imagePlaceholder").append('<img src="'+ parsedResponse[x] + '"/>');
};
};
var cbComplete = function(textStatus) {
alert('Call has completed')
};
var options = {
cb: callbackHandler,
cbHandlerOnComplete: cbComplete,
readonly: true
};
function callAPI() {
doServiceRequest(parameters, options) ;
};
</script>
<input type="button" name="Call API" value="Test getMediaLinks" onClick="callAPI()" /><br/>
<div id="imagePlaceholder"/>
API Endpoint Example
https://www.example.com/services/apexrest/cms/ocmsrest/?action=getLinksSetParams&service=OrchestraUtilityAPI&apiVersion=5.0&configName=OrchestraCMSSite¶ms={"pageName1":{"parameter":"value"},"pageName2":{"parameter":"value"}}
JSON-Serialized Response Example
{
type: "Map<String,String>",
timeNow: "2017-06-07T15:10:56.000Z",
isSuccess: true,
transactionId: null,
responseObject: "{"fileName1.ext:a0Ti0000017O97WEAS":"https://s3.amazonaws.com/ourBucket/OrchestraCMS/a0Ti0000017O97WEAS.ext","filename1.ext":"/servlet/servlet.FileDownload?file=00Pi000000RQYDGEA5","fileName2.ext":"/servlet/servlet.FileDownload?file=00Pi000000s1wCHEAY"}",
message: "getMediaLinks",
error: null
}
getPageMode
Returns the mode of the current OrchestraCMS context as a string. A sample use case for this information is to allow for the limited execution of code based on whether the page is being previewed in OrchestraCMS or viewed on the live site.
Parameters
- apiVersion : String, The apiVersion that you want to use.
- sname : String, The name of the OrchestraCMS site.
Apex Example
This code example can be run in the Salesforce Developer Console. Typically this call would only be executed within an OrchestraCMS site context as the context is relevant only within an OrchestraCMS site context:
Map<String,String> parameters = new Map<String,String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('apiVersion','5.0');
cms.ApexServiceInterface oua = (cms.ApexServiceInterface) cms.ServiceEndpoint.getService('OrchestraUtilityAPI', parameters);
String pageMode = (String) oua.executeApex('getPageMode', null);
if(pageMode == 'production'){
system.debug('This is live site code');
}else{
system.debug('This is preview code');
}
JavaScript Example
<script>
var parameters = {
sname: 'site_name',// Replace site_name with the name of your OrchestraCMS site
apiVersion: '5.0',
service: 'OrchestraUtilityAPI',
action: 'getPageMode'
};
var callbackHandler = function(json, Success) {
var parsedJSON = JSON.parse(json);
if (parsedJSON.isSuccess && JSON.parse(parsedJSON.responseObject) == 'production') {
alert('This is live site code');
}else{
alert('This is preview code')
}
};
var cbComplete = function(textStatus) {
alert('Call had completed');
};
var options = {
cb: callbackHandler,
cbHandlerOnComplete: cbComplete,
readonly: true
};
function callAPI() {
doServiceRequest(parameters, options) ;
};
</script>
<input type="button" name="Call API" value="Test getPageMode" onClick="callAPI()" /><br/>
API Endpoint Example
http://www.example.com/services/apexrest/cms/ocmsrest/?action=getPageMode&service=OrchestraUtilityAPI&apiVersion=5.0
JSON-Serialized Response Example
{
type: "String",
timeNow: "2017-06-02T16:12:52.000Z",
isSuccess: true,
transactionId: null,
responseObject: "production",
message: "getPageMode",
error: null
}
Values for responseObject could be:
- prev - Returned when the page is being previewed.
- secureprev - Returned when the page is being previewed by an external previewer.
- production - Returned when a page is being viewed in the live site.
getSiteName
Returns the OrchestraCMS name of the current site as a string. A sample use case for this information is to allow for the limited execution of code from a common source when there are mulitple sites configured in OrchestraCMS. This would allow the developer to ensure the code block only executed when it was within the context of a specific site.
Parameters
- apiVersion : String, The apiVersion that you want to use.
- sname : String, The name of the OrchestraCMS site.
Apex Example
The sname parameter is provided in the following example only so that the following code can be run in the Salesforce Developer Console. Typically this call would only be executed within an OrchestraCMS site context:
Map<String,String> parameters = new Map<String,String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('apiVersion','5.0');
cms.ApexServiceInterface oua = (cms.ApexServiceInterface) cms.ServiceEndpoint.getService('OrchestraUtilityAPI', parameters);
String SITENAME = (String) oua.executeApex('getSiteName', null);
if(siteName == 'site_name'){// Replace site_name with the name of your OrchestraCMS site
system.debug('This is the Sample Community');
}else{
system.debug('This is not the Sample Community');
}
JavaScript Example
<script>
var parameters = {
sname: 'site_name',// Replace site_name with the name of your OrchestraCMS site
apiVersion: '5.0',
service: 'OrchestraUtilityAPI',
action: 'getSiteName'
};
var callbackHandler = function(json, Success) {
var parsedJSON = JSON.parse(json);
if (parsedJSON.isSuccess && JSON.parse(parsedJSON.responseObject) == 'SampleCommunity') {
alert('This is the Sample Community');
}else{
alert('This is not the Sample Community')
}
};
var cbComplete = function(textStatus) {
alert('Call had completed');
};
var options = {
cb: callbackHandler,
cbHandlerOnComplete: cbComplete,
readonly: true
};
function callAPI() {
doServiceRequest(parameters, options) ;
};
</script>
<input type="button" name="Call API" value="Test getSiteName" onClick="callAPI()" /><br/>
API Endpoint Example
http://www.example.com/services/apexrest/cms/ocmsrest/?action=getSiteName&service=OrchestraUtilityAPI&apiVersion=5.0
JSON-Serialized Response Example
{
type: "String",
timeNow: "2017-06-02T15:03:41.000Z",
isSuccess: true,
transactionId: null,
responseObject: "sitename",
message: "getSiteName",
error: null
}
getUserType
A sample use case for this information returned by this API may involve the limited execution of a code block so it only runs when the user is logged in and not a Guest.
Parameters
- apiVersion : String, The apiVersion that you want to use.
- sname : String, The name of the OrchestraCMS site.
Apex Example
If the Apex code is going to be running outside the context of the OrchestraCMS managed site, the sname parameter is required; otherwise, the site context is inherited from the current session. The following code can be run in the Salesforce Developer Console:
Map<String,String> parameters = new Map<String,String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('apiVersion','5.0');
cms.ApexServiceInterface oua = (cms.ApexServiceInterface) cms.ServiceEndpoint.getService('OrchestraUtilityAPI', parameters);
String userType = (String) oua.executeApex('getUserType', null);
if(userType == 'Salesforce'){
system.debug('We can execute this code for Salesforce users');
}else{
system.debug('We can execute this code for all other users');
}
JavaScript Example
<script>
var parameters = {
sname: 'site_name',// Replace site_name with the name of your OrchestraCMS site
apiVersion: '5.0',
service: 'OrchestraUtilityAPI',
action: 'getUserType'
};
var callbackHandler = function(json, Success) {
var parsedJSON = JSON.parse(json);
if (parsedJSON.isSuccess && JSON.parse(parsedJSON.responseObject) != 'Salesforce') {
alert('You are not a Salesforce user!');
};
};
var cbComplete = function(textStatus) {
alert('Call had completed');
};
var options = {
cb: callbackHandler,
cbHandlerOnComplete: cbComplete,
readonly: true
};
function callAPI() {
doServiceRequest(parameters, options) ;
};
</script>
<input type="button" name="Call API" value="Test getUserType" onClick="callAPI()" /><br/>
API Endpoint Example
http://www.example.com/services/apexrest/cms/ocmsrest/?action=getUserType&service=OrchestraUtilityAPI&apiVersion=5.0
JSON-Serialized Response Example
{
type: "String",
timeNow: "2017-06-01T19:28:31.000Z",
isSuccess: true,
transactionId: null,
responseObject: "Guest",
message: "getUserType",
error: null
}
The responseObject returns a normalized value for the current user's Salesforce license type within your OrchestraCMS managed site as a string. Values could be:
- Salesforce
- Portal
- High Volume Portal
- Guest
- Unknown
isCurrentPage
Returns a boolean indicating if the provided parameter is the same as the current OrchestraCMS page. This accepts the link parameter which is the case sensitive page URL to check for. A sample use case may include the limited execution of a code block only on a specific page or pages.
Parameters
- apiVersion : String, The apiVersion that you want to use.
- sname : String, The name of the OrchestraCMS site.
- link : String, Case sensitive URL to compare the current page URL to.
Apex Example
global virtual with sharing class isCurrentPageContentTemplate extends cms.ContentTemplateController {
cms.ApexServiceInterface oua;
global isCurrentPageContentTemplate (cms.CreateContentController cc) {
super(cc);
}
global isCurrentPageContentTemplate(){
Map<String,String> context_parameters = new Map<String,String>();
context_parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
context_parameters.put('apiVersion','5.0');
oua = (cms.ApexServiceInterface) cms.ServiceEndpoint.getService('OrchestraUtilityAPI', context_parameters);
}
public Boolean isCurrentPage(){
return (Boolean) oua.executeApex('isCurrentPage', new Map<String,Object>{'link'=>'/NewURL'});
}
global virtual override String getHTML() {
String html = '';
if (isCurrentPage()){
html += 'This is the correct page for the code to execute on';
}else{
html += 'This is the not correct page for the code to execute on';
}
return html;
}
}
JavaScript Example
<script>
var parameters = {
sname: 'site_name',// Replace site_name with the name of your OrchestraCMS site
apiVersion: '5.0',
service: 'OrchestraUtilityAPI',
action: 'isCurrentPage',
link: '/pageURL' //this is case sensitve and must start with a /
};
var callbackHandler = function(json, Success) {
var parsedJSON = JSON.parse(json);
var parsedResponse = JSON.parse(parsedJSON.responseObject);
if (parsedResponse === true){
alert('This is the page');
}
};
var cbComplete = function(textStatus) {
alert('Call Back Complete');
};
var options = {
cb: callbackHandler,
cbHandlerOnComplete: cbComplete,
readonly: true
};
function callAPI() {
doServiceRequest(parameters, options) ;
};
</script>
<input type="button" name="Call API" value="Test isCurrentPage" onClick="callAPI()" /><br/>
API Endpoint Example
JSON-Serialized Response Example
{
"type":"Boolean",
"timeNow":"2017-06-09T19:33:50.000Z",
"isSuccess":true,
"transactionId":null,
"responseObject":"true",
"message":"isCurrentPage",
"error":null
}
refreshUserTargets
User targets are used by OrchestraCMS to personalize what content is visible to a site visitor based on criteria on a user's Salesforce User record. When a user is logged into a community the targets are calculated and cached in the browser for the duration of a session. If the details on the user's Salesforce User record change during the course of the session (eg. using a My Profile page to update the user's record or having them register content subscriptions) the new values would not be used to filter the content as the calculated targets were cached at the beginning of the user's session.
The refreshUserTargets Javascript method provides a way to refresh the cached targets without the need to have the user end the current session (logout) and begin a new session.
function targetsRefreshedSuccessfully(result, response) {
if (result === true ) {
console.log('The users targets were refreshed successfully: ' + response);
} else {
console.log('The users targets failed to refresh: ' + response);
}
};
function onTargetRefreshComplete(result, response) {
console.log('The target refresh has completed.');
};
ocmsUtil.targets.refreshUserTargets(targetsRefreshedSuccessfully, onTargetRefreshComplete);