Wednesday, August 23, 2017

Salesforce Site Template is Not Coming in Force.com Site

If your Site Template is not coming on your there might be the below issues.

1. Site Template page has not been added for Site Template on Site Detail Page



2. If your using any visual force page in your sites and if your not adding Template to visual force page you will not be able show the template.Please add the template to each and every page.


<apex:page standardController="Case" showHeader="false">
    <apex:composition template="{!$Site.Template}">
        <apex:define name="body">
    <head>
              <apex:includeScript value="{!$Resource.dataTableJS}"/>
       <apex:stylesheet value="{!$Resource.dataTableCSS}" />
     </head>
   <apex:form>
      ----
      ----
   </apex:form>
 </apex:define>
   </apex:composition>
</apex:page>

Hope this helps you...Enjoy!

CSS Styles/Scripts Are Not Working in Salesforce Force.com Sites

If your styles/scripts are working perfectly in Sandbox and Production preview but if it's not working on Force.com sites which has hosted publicly on Sales force server below points might be the issue.

Your page is referring to some external CSS/JS files:

<apex:page>
 <head>
 <apex:stylesheet value="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css" />
<apex:includescript value="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js" /> 
</head>
<apex:form>
  ----
  ----
</apex:form>
</apex:page>

If your referring any styles/scripts from external sources with out storing them in Static Resource you will end up with problem Please store that files in Statistic resource and then use it then it will work in Force.com sites as well.


<apex:page>
 <head>
  <apex:includeScript value="{!$Resource.dataTableJS}"/>
  <apex:stylesheet value="{!$Resource.dataTableCSS}" />
</head>
<apex:form>
  ----
  ----
</apex:form>
</apex:page>


Your Static Resource is File not accessible publicly



If your using any static resource in your page and if that static resource is not accessible publicly (Cache Control set to Private) then styles will not reflect in Force.com sites.So mark your Static resources cache control as Public



Hope this helps you...Enjoy!


How to Invoke the REST API from the Visual Force Page in Salesforce

Problem:
We usually making a lot of API calls from Salesforce to External systems to get the some data or to pass the some updates to External Systems.All these calls will be made from the Apex class to External systems. What if you have situation like where you need to make a call to external systems from the visual force page.

Solution:
No need to worry still we have option to make an REST API call from the page directly.How?As we already know that Salesforce has introduced a concept called AJAX ToolKit.This is an frame which will be used to make all the operations from JavaScript similar to APEX. With help of this tool kit you can make an REST API call from the Script in Visual Force Page

Flow Diagram:
 

Sample Source Code:

<apex:page standardController="Account">
<apex:includeScript value="//code.jquery.com/jquery-1.11.1.min.js" />
<script src="../../soap/ajax/40.0/connection.js" type="text/javascript"></script>

<script>
function makeAPICall() 
{
    var weblink = //Your API endpoint 'https://www.yourednpoint/';
 
    $j.ajax({
  url: weblink,
  type: 'GET', // Type POST or GET
  dataType: 'json',
  beforeSend: function(request) {
      // Add All your Headers Here if Any
   request.setRequestHeader('HeaderString','HeaderValue');
   //Sample Headers 
   request.setRequestHeader('Country', 'IND');
   request.setRequestHeader('Currency', 'INR');
  },

  crossDomain: true,
  
  //If Successfully executed 
  success: function(result) {
   
   //Response will be stored in result variable in the form of Object.Please use result variable for processing
    console.log('Response Result'+result); 
    
      //If you want to convert JSResponse Object to JSON response 
    var jsonResp = JSON.stringify(result));

  },
  
  //If any Error
  
  error: function(jqXHR, textStatus, errorThrown) {
   
   // alert('ErrorThrown: ' + errorThrown);
  }
    });
}
</script>
<apex:form>
  call javaScript method from here to make an api call invocation
</apex:form>
</apex:page>

Hope this helps you....Enjoy!