Tag Archives: Force.com

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.

Calculate Age from Date of Birth using Apex in Salesforce

Apex Class:

public class CalculateAge
{  
    public Integer age {get; set;}    
    public Date dt {get; set;}
    
    public void FindAge()
    {
        Integer days = dt.daysBetween(Date.Today());
        age = Integer.valueOf(days/365);
    }
}

Visualforce Page:

<apex:page doctype="html-5.0" controller="CalculateAge">
    <apex:form>
        <apex:pageblock title="Calculate Age From Date of Birth">
            <apex:pageblocksection>
                <apex:pageblocksectionitem>Date of Birth:
                    <apex:inputtext onfocus="DatePicker.pickDate(true, this , false);" value="{!dt}"></apex:inputtext></apex:pageblocksectionitem>
                    <apex:commandbutton value="Get Age" action="{!FindAge}"></apex:commandbutton>
                    <apex:pageblocksectionitem>Age:           
                    <apex:outputtext value="{!age}"></apex:outputtext>
                </apex:pageblocksectionitem>           
            </apex:pageblocksection>
        </apex:pageblock>
    </apex:form>   
</apex:page>

Output:

download

Process Builder in Salesforce

The Process Builder is a workflow tool that helps to easily automate the business processes by providing a powerful and user-friendly visual representation of the process as we build it. The Process Builder user interface has several functional areas that we should understand before creating a process.

This feature is available, as Beta, since Winter ’15 (Release Notes) and Generally Available since Spring ’15 (Release Notes). It available in Enterprise, Performance, Unlimited, and Developer Editions.

For example here is a scenario: Automatically create an Opportunity upon the creation of a Account for which Type = “Customer – Direct”
Step 1:
Go to Setup | App Setup | Create | Workflow & Approvals | Process Builder.

1

Step 2:
Review Process Builder start page and click ‘New” to start building.

2

Step 3:
Create new process.

3

Step 4:
Select the object to be evaluated (in this case, Account).

4

Step 5:
Review current process after object added.

5

Step 6:
Add criteria that will determine when action(s) will be triggered.

6

Step 7:
Name the criteria and select when actions should be evaluated.

7

Step 8:
Create filter condition.

8

Step 9:
Apply filter value (Type = “Customer – Direct”) and review your filter.

9

Step 10:
Save filter criteria.

10

Step 11:
Add a corresponding action.

11

Step 12:
Fill the action name and the required fields for the new Opportunity record.

12

Step 13:
Activate the process by clicking on “Activate” at the top right.

13

Review activated process.

13-1

Review all of your processes by navigating to “My Processes”.

13-2

Now you can create an account with type value “Customer – Direct”, and check automatically an Opportunity will create.