function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

How to get Host Name from an Apex Batch

Does anyone know how to get the hostname in an Apex Batch class?


Note that the following does not work (null pointer exception) because the process is not associated with a Visual Force page:




My use case:


      My batch program sends emails that display images that I've stored as static resources.  The email module utilizes VF Email Template.


There is no good way. Perhaps you can define the host in a custom setting and then access it from your code.


Also, vote for this:


Hi Friends,


I am new to salesforce. My requirement is that we are using our company LDAP authentication. Upon successful authentication it should redirect the user to salesforce free site URL but before it hits free site URL I wanted to check in  the header URL to grab the HOST so that I can determine from where the request is coming from and if I found the request  is coming from valid HOST then I will let the user to see our free site page otherwise will show him the error page.


Note : We want to use salesforce free site.


Here is the code i am trying  it seems that there is no event called onload in  <apex:actionSupport event tag:


<apex:page setup="true" controller="MyController" showHeader="false">
<apex:form >
 <apex:outputpanel id="counter">
 <apex:outputText value="Click Here To Generate Session Id and Server URL" />
 <apex:actionSupport event="onload" action="{!doLogin}" rerender="refreshId" status="counterStatus">
 <apex:param name="serverHostURL" assignTo="{!apiHostURL}" value="{!$Site.OriginalUrl}" />
 <apex:outputPanel id="refreshId">
  <apex:outputText value="API1 Server Host: {!apiHostURL}"/><br></br>



Any suggestions would be really help full.


Thanks Guys!