Wednesday, April 3, 2013

Execute Java Script On Every Screen Of SFDC


The aforementioned blog which I am posting was the severe demand of one of my client who was wondering if we could deliver some code that will be executed on every standard screen of Salesforce.

So ,  the theoretical requirement was cited on the fact that Mr. Client was in urge of some code which would run on every standard page load in salesforce. For this I made an recipe which I am sharing below. Hope that you like it .


For this, You can make one "Narrow Home Page Component". 

In that component you can simply use below JS code and alter according to your need.

<script type="text/javascript" language="javascript">
try    {
   var doc = window.top.document;
   var head = doc.head;
   var scriptElement = doc.createElement('script');
   scriptElement.async = true;
   scriptElement.innerHTML = "alert('test1')";
   head.appendChild(scriptElement); 
}
catch(e){  }
</script>

and add that to your home page layout.

Make sure you have enabled that sidebar component to show on all pages of your sfdc. 
Setup -> customize -> user Interface




You can also use this code by a deploying this package -

NOTE: After deployed this package please assign "JS on Every Screen Layout" to System Administraor Profile or profile that you want to use this functionility. 

Result - 
  

Monday, April 1, 2013

Required Information / Required Field Mark

This time I explore a small but useful code, Some time we have validate the input text boxes using Jave Script or using required attribute but we didn't mark as Required field like a Salesforce required field red mark -



Using this code you can mark any <apex:inputText />  , <apex:inputField/> , <apex:inputTextarea/> , <apex:selectCheckboxes> , <apex:selectList> ....etc.

I have written a code for only <apex:inputText />

<apex:page>
  <apex:form>
      <Apex:pageBlock>
          <Apex:pageBlockSection>
              <Apex:pageBlockSectionItem>
                    Field Label                     <!-----Enter here field label ------>
                    <apex:outputPanel >
                      <div class="requiredInput">
                             <div class="requiredBlock"></div>
                             <!---- APEX / HTML Tag which you marked a required------>
                            <apex:inputText required="true" id="reqField" />          
                     </div>
                   </apex:outputPanel>
             </Apex:pageBlockSectionItem>
         </Apex:pageBlockSection>
      </Apex:pageBlock>
  </apex:form>
</apex:page>