Category Archives: Salesforce

Salesforce – Field Update on Button Click Using Javascript

Here in below example, there is a custom field Active__c in Contact object. On a button click want to update Active__c field status to true.

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
 
if(confirm("Do you want to active this Contact?") == true) 
{
    var objC = new sforce.SObject("Contact");        
        objC.Id = '{!Contact.Id}';
        objC.Active__c = true;
        var result = sforce.connection.update([objC]); 
        window.location.reload();
}

Rendering a Visualforce Page in PDF Format

You can render any page as a PDF by adding the renderAs attribute to the component, and specifying pdf as the rendering service.

For example:

<apex:page renderas="pdf">
</apex:page>

Note: Visualforce pages rendered as PDFs will either display in the browser or download as a PDF file, depending on your browser settings.

Confirm Dialog box in Visualforce page

Visualforce Page:

<apex:page>
    <apex:form>
        <apex:pageblock>
            <apex:pageblocksection title="Confirm dialog box Demo" collapsible="false">
                 <apex:commandbutton value="Click to Confirm" onclick="return confirm('Do you want to submit');"></apex:commandbutton>
            </apex:pageblocksection>
        </apex:pageblock>
    </apex:form>
</apex:page>

download

Hide Current Date Link For Date Type Inputfield

The standard apex:inputfield component for a date field generates current date link next to the input field. Sometimes we need to hide this link.

Here is an example to hide the current date link for date type inputfield. Here I’ve added the visibility:hidden in dateFormat CSS class to hide the link.

<style type="text/css">
    .dateFormat{
    visibility:hidden;
    }
</style>

Visualforce Page:

<apex:page standardController="Opportunity"> 
    <style type="text/css">
        .dateFormat{
        visibility:hidden;
        }
    </style>
    <apex:form>  
        <apex:pageBlock title="Opportunity">  
            <apex:pageBlockSection title="Opportunity Information">  
                <apex:inputField value="{!Opportunity.Name}"/> 
                <apex:inputField value="{!Opportunity.Amount}"/>  
                <apex:inputField value="{!Opportunity.Type}"/> 
                <apex:inputField value="{!Opportunity.LeadSource}"/> 
                <apex:inputField value="{!Opportunity.CloseDate}"/>  
            </apex:pageBlockSection>  
        </apex:pageBlock>  
    </apex:form>  
</apex:page>  

Output: