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

Converting DateTime to format YYYY-MM-DDThh:mm:ssZ in Salesforce

System.debug(DateTime.now().format(‘yyyy-MM-dd\’T\’hh:mm:ss\’z\”));

It can be used in SOQL query. SOSL query returns the datetime in format(YYYY-MM-DDThh:mm:ssZ) so for comparison we need to convert it into above format.