- This is not a coding exam
The purpose of the developers exam is to measure how effectively you can describe how to use the various aspects of the platform to construct applications, not to prove how well you can code Visualforce pages or Apex classes. It is more important to be able to define when to use these tools, rather than how.
- Go back to basics
If like me, you have been working primarily on providing specific customization to applications for a while, it is a good idea to re-reference all the components available on the Force.com platform. Part of my preparation for the exam included building the recruitment application as described in Force.com Fundamentals, which really helped to re-enforce how to use every aspect of the platform.
- Learn to share
A substantial proportion of the questions in the test are centered around how to enable and restrict access to objects and records. Learn the different methods of sharing and appreciate in what kind of scenarios these should be implemented. You should understand the whole range, from object level CRUD permissions using profiles to sharing records using public groups and manual rules. Also, in a similar vein, you should be aware of the relationship that page layouts have with record sharing.
- Know the optional extras
Aside from the standard Force.com platform functionality, there are several additional features that can be included in an organization by contacting Salesforce. Examples of such features are encrypted fields to encrypt data shown to particular users and enabling the use of multiple currencies. Fortunately, all you need to know about these extras is included in the Study Guide.
- A report is more than just a table of data
The reporting tool included on the force.com platform is highly customizable, and you will need to be aware of how you can adapt reports to a specific purpose. It is essential to learn the various report types, and given a situation which one you would use. The same is also true of dashboard components, understand what each is used for and recognize when it is appropriate to use them. When revising the use of reports, rather than just read, I think the best approach is to get hands on. If you have a developer force account, construct several reports and dashboards and really experiment with the various ways of presenting data to users.
Monday, 4 April 2011
Top 5 tips for passing the Salesforce.com certified Force.com developer (SP11) exam
Tuesday, 22 March 2011
Working with Apex data tables: Confirming choices
I have built an example of such a menu based on the page and controller from my previous post. When the user selects contact records and clicks on "process selected contacts", they are taken to a confirmation page that displays the contacts that they have selected, and asks them to confirm that these are the records they wish to process. This confirmation page shares the same controller as the main selection page. They can choose to cancel, which will return them to the previous selection menu taking no action, or click confirm to accept the selections and then be returned to the selection menu. Here is a screenshot of the confirmation screen:
In terms of altering the controller code, I added two new actions to confirm and cancel processing the contact records. Users can be directed to a particular page by returning a page reference (of the form "Page.*Visualforce page name*") in the action, or null to remain on the same page. If no records are selected on the first page, then instead of being directed to the confirmation page, the user will remain on the selection page, and an error message will be displayed.
In order for menus like this to work, the two pages must share the same controller type. Also, ensure that all page references used to change the page do not have the redirect attribute set to true, otherwise the users selections will be lost as the controller is reset.
Below is the Apex controller and Visualforce page code for the example.
Controller:
public class WorkingWithApexDataTablesController {
public List<ContactWrapper> allContacts { get; set; }
public Boolean allChecked { get; set; }
public WorkingWithApexDataTablesController () {
allContacts = new List<ContactWrapper>();
allChecked = false;
for(Contact contact: [select Name, Title, Department, Email from Contact ]){
allContacts.add(new ContactWrapper(contact));
}
}
public PageReference CheckAll(){
for(ContactWrapper contact : allContacts){
contact.selected = allChecked;
}
return null;
}
public PageReference ProcessSelectedContacts(){
// If at least one contact has been selected,
// forward to confrimation page
for (ContactWrapper contactWrapper : allContacts ){
if(contactWrapper.selected == true){
return Page.WorkingWithApexDataTablesConfirmation;
}
}
// if no contacts have been selected, write an error message
Apexpages.addMessage(new ApexPages.Message (ApexPages.Severity.ERROR, 'No contacts selected'));
return null;
}
public PageReference confirmSelectedContacts(){
List<String> selectedContacts = new List<String>{};
for (ContactWrapper contactWrapper : allContacts ){
if(contactWrapper.selected == true){
selectedContacts.add(contactWrapper.con.Name);
}
}
// otherwise, write a confirmation message
Apexpages.addMessage(new ApexPages.Message (
ApexPages.Severity.CONFIRM, selectedContacts.size() +
' contacts selected ' + selectedContacts));
// If all contacts have been selected, write a warning message
if(selectedContacts.size() == allContacts.size()){
Apexpages.addMessage(new ApexPages.Message (
ApexPages.Severity.WARNING, 'All contacts selected'));
}
return Page.WorkingWithApexDataTables;
}
public PageReference cancelConfirmSelectedContacts(){
// If the users cancels the action at the confirmation screen,
// return them to the main screen with a cancellation message
Apexpages.addMessage(new ApexPages.Message (
ApexPages.Severity.CONFIRM, 'Action Cancelled'));
return Page.WorkingWithApexDataTables;
}
public List<Contact> getSelectedContactObjects(){
List<Contact> selectedContactObjects = new List<Contact>{};
for (ContactWrapper contactWrapper : allContacts ){
if(contactWrapper.selected == true){
selectedContactObjects.add(contactWrapper.con);
}
}
return selectedContactObjects;
}
public class ContactWrapper {
public Contact con{get; set;}
public Boolean selected {get; set;}
public ContactWrapper(Contact c){
con = c;
selected = false;
}
}
}
WorkingWithApexDataTables Page:
<apex:page controller="WorkingWithApexDataTablesController">
<apex:sectionHeader title="Working With Apex Data Tables"/>
<apex:pageMessages />
<apex:form >
<apex:dataTable value="{!allContacts}" var="c" id="contactsTable">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox value="{!allChecked}">
<apex:actionSupport event="onclick" action="{!CheckAll}"
rerender="contactsTable"/>
</apex:inputCheckbox>
</apex:facet>
<apex:inputCheckbox value="{!c.selected}"/>
</apex:column>
<apex:column value="{!c.con.Name}" headervalue="Full Name"/>
<apex:column value="{!c.con.Title}" headervalue="Title"/>
<apex:column value="{!c.con.Department}"
headervalue="Department"/>
<apex:column value="{!c.con.Email}" headervalue="Email"/>
</apex:dataTable>
<apex:commandButton action="{!ProcessSelectedContacts}"
value="Process Selected Contacts"/>
</apex:form>
</apex:page>
WorkingWithApexDataTablesConfirmation Page:
<apex:page controller="WorkingWithApexDataTablesController">
<apex:sectionHeader title="Working With Apex Data Tables (Confirmation)"/>
<apex:form >
<apex:outputText value="You have selected the following contacts for processing, are you sure?"/>
<apex:dataTable value="{!selectedContactObjects}" var="con" id="selectedContactsTable">
<apex:column value="{!con.Name}" headervalue="Full Name"/>
<apex:column value="{!con.Title}" headervalue="Title"/>
<apex:column value="{!con.Department}" headervalue="Department"/>
<apex:column value="{!con.Email}" headervalue="Email"/>
</apex:dataTable>
<apex:commandButton action="{!CancelConfirmSelectedContacts}"
value="Cancel"/>
<apex:commandButton action="{!ConfirmSelectedContacts}"
value="Confirm"/>
</apex:form>
</apex:page>
Thursday, 3 February 2011
Working with Apex data tables: Displaying selections and errors using page messages
The controller code to create a new page message and add it to the current page:
Apexpages.addMessage(new ApexPages.Message(ApexPages.severity, messageBody));
for example: Apexpages.addMessage(new ApexPages.Message (ApexPages.Severity.ERROR, 'Hello World Error'));
To display the messages on the page is simply a case of using the apex:pageMessages tag, like so:
<apex:pageMessages/>
In the following example I have taken the majority of code from a previous blog post concerning creating a check-all checkbox on a data table. I have added apex messages in the previously empty perform action method to illustrate how they can be used. The following logic is applied in this method:
- If no contacts are selected, an error message will be generated.
- If all contacts are selected, a warning message will warn that the maximum amount of contacts have been selected.
- In at least one contact has been selected, a confirmation message will be displayed, including a list of the selected contacts' names.
(Screen before interaction)
(No records Selected)
(4 contacts Selected)
Controller:
public class WorkingWithApexDataTablesController {
public List<ContactWrapper> allContacts { get; set; }
public Boolean allChecked { get; set; }
public WorkingWithApexDataTablesController () {
allContacts = new List<ContactWrapper>();
allChecked = false;
for(Contact contact: [select Name, Title, Department, Email from Contact ]){
allContacts.add(new ContactWrapper(contact));
}
}
public PageReference CheckAll(){
for(ContactWrapper contact : allContacts){
contact.selected = allChecked;
}
return null;
}
public PageReference ProcessSelectedContacts(){
List<String> selectedContacts = new List<String>{};
for (ContactWrapper contactWrapper : allContacts ){
if(contactWrapper.selected == true){
selectedContacts.add(contactWrapper.con.Name);
}
}
if(selectedContacts.isEmpty()){
// if no contacts have been selected, write an error message
Apexpages.addMessage(new ApexPages.Message ( ApexPages.Severity.ERROR, 'No contacts selected'));
}
else {
// otherwise, write a confirmation message
Apexpages.addMessage(new ApexPages.Message ( ApexPages.Severity.CONFIRM, selectedContacts.size() + ' contacts selected ' + selectedContacts));
// If all contacts have been selected, write a warning message
if(selectedContacts.size() == allContacts.size()){
Apexpages.addMessage(new ApexPages.Message ( ApexPages.Severity.WARNING, 'All contacts selected'));
}
}
return null;
}
public class ContactWrapper {
public Contact con{get; set;}
public Boolean selected {get; set;}
public ContactWrapper(Contact c){
con = c;
selected = false;
}
}
}Page:
<apex:page controller="WorkingWithApexDataTablesController">
<apex:sectionHeader title="Working With Apex Data Tables"/>
<apex:pageMessages />
<apex:form >
<apex:dataTable value="{!allContacts}" var="c" id="contactsTable">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox value="{!allChecked}">
<apex:actionSupport event="onclick" action="{!CheckAll}"
rerender="contactsTable"/>
</apex:inputCheckbox>
</apex:facet>
<apex:inputCheckbox value="{!c.selected}"/>
</apex:column>
<apex:column value="{!c.con.Name}" headervalue="Full Name"/>
<apex:column value="{!c.con.Title}" headervalue="Title"/>
<apex:column value="{!c.con.Department}"
headervalue="Department"/>
<apex:column value="{!c.con.Email}" headervalue="Email"/>
</apex:dataTable>
<apex:commandButton action="{!ProcessSelectedContacts}"
value="Process Selected Contacts"/>
</apex:form>
</apex:page>
This is just a brief exploration of messages, but still shows how they can greatly improve the user experience. For more about messages, see the full apex page messages class definition, which includes the full enumeration of severity values. Also note that individual apex:pageMessage tags can be used to split up the messages to display at different points on the page and control their content directly on the page, should you so desire.
Monday, 4 October 2010
Creating a picklist in a Visualforce page without a -none- value
When building a custom Visualforce page, the need may arise to include a combo-box input based on a picklist field inside a Salesforce object. This is easy to achieve using an apex:inputField, as in the following example, where an Invoice Statement object contains a picklist field called Status.
VisualForce Page:
<apex:page controller="NoNoneForPicklistController">
Please select required status:
<apex:form >
<apex:inputField value="{!invoiceStatement.Status__c}"/>
</apex:form>
</apex:page>
public class NoNoneForPicklistController{
public Invoice_Statement__c invoiceStatement {get;set;}
}
Screen-shot:
As you can see, the default value on the combo-box on the page is "-None-", which represents an empty value. It may be a preference to not display the empty value, but rather frustratingly, no configuration of the picklist object field can avoid this inclusion. There is no way to mark a picklist field as "required", and setting an option as default makes no difference either. That said, there are already ways to prevent an empty value being processed, using validation and feedback, but I have always been one to believe that prevention is better than cure.
Thankfully, there is a way to effectively create a picklist on a Visualforce list with no empty value. This can be achieved by using the Schema.DescribeFieldResult Salesforce standard class to retrieve all the possible field label value pairs for a picklist field. The retrieved value pairs are then stored inside a collection of select option objects, which can be used as the basis of a select list. Below is a snapshot of the code from the apex controller, and also the Visualforce page. As an added bonus, the default value specified in the picklist field object configuration can be used to set the initially selected value of the select list.
VisualForce Page:
<apex:page controller="NoNoneForPicklistController">
Please select required status:
<apex:form >
<apex:selectList size="1" value="{!invoiceStatement.Status__c}">
<apex:selectOptions value="{!statusOptions}"/>
</apex:selectList>
</apex:form>
</apex:page>
public class NoNoneForPicklistController{
public Invoice_Statement__c invoiceStatement {get;set;}
public List<SelectOption> statusOptions {get;set;}
// Constructor called when page is accessed.
public NoNoneForPicklistController() {
invoiceStatement = new Invoice_Statement__c();
statusOptions = new List<SelectOption>();
// Use DescribeFieldResult object to retrieve status field.
Schema.DescribeFieldResult statusFieldDescription = Invoice_Statement__c.Status__c.getDescribe();
// For each picklist value, create a new select option
for (Schema.Picklistentry picklistEntry: statusFieldDescription.getPicklistValues()){
statusOptions.add(new SelectOption( pickListEntry.getValue(),pickListEntry.getLabel()));
// obtain and assign default value
if (picklistEntry.defaultValue){
invoiceStatement.Status__c = pickListEntry.getValue();
}
}
}
}
Screen-shot:
Friday, 24 September 2010
Converting decimal value to integer (don't fall into the trap!!)
Decimal decimalValue = 12.0; Integer integerValue = Integer.valueOf(decimalValue);
Using code like this will compile without a problem, but upon execution, an error message "System.TypeException: Invalid Integer" will appear (see screen-shot for an example). This is because the input variable "decimalValue" contains more than just numbers, it also contains a decimal place, which causes the conversion to be rejected by the "valueOf" function.
The method that should always be used to perform this kind of conversion is *decimal variable*.intValue(). So in our example above the Apex code should look like this:
Decimal decimalValue = 12.0; Integer integerValue = decimalValue.intValue();
Now the conversion will work without error.
Wednesday, 18 August 2010
Displaying different date formats on Visualforce pages.
Varying the format of a dateTime field inside a Visualforce page is quite straightforward. It involves wrapping the field in a mask and then passing the data as a parameter, like so:
Page:
<apex:outputText value="{0,date,{!dateFormat}}">
<apex:param value="{!myDateTime}" />
</apex:outputText>
In order to illustrate how this works, I have constructed a page and controller with a few samples. Below is a screenshot of the page displaying a single date (31st December 2010, 23:59:59) in various different formats. The first column of the table shows the string used as the date format mask, whilst the second column shows how that date appears when the mask is applied to the date.
Controller:
public class DateFormattingController {
Datetime myDateTime = datetime.newInstance(2010, 12, 31, 23, 59, 59);
List<String> dateFormats = new List<String> {
'dd.MM.yy HH:mm:ss',
'MMM-dd-yyyy hh:mm a',
'EEEEE dd MMMMM yyyy G',
'E hh:mm:ss:SSS z',
'zzzzz (Z), \'Day of the year:\' D'
};
public DateTime getMyDateTime(){
return myDateTime;
}
public List<String> getDateFormats(){
return dateFormats;
}
}
Page:
<apex:page controller="DateFormattingController">
<apex:sectionHeader title="Date Formatting"/>
<apex:outputText value="Standard Output Format: {!myDateTime}"/>
<apex:pageBlock >
<apex:pageBlockTable value="{!dateFormats}" var="dateFormat">
<apex:column headerValue="Date Format" value="{!dateFormat}" width="50%"/>
<apex:column headerValue="Output" width="50%">
<apex:outputText value="{0,date,{!dateFormat}}">
<apex:param value="{!myDateTime}" />
</apex:outputText>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
See Paul's Salesforce Blog for the full date format letter table. Any missing formats or unsure how to construct a particular format, leave me a comment on the post and I'll see what I can do!
Friday, 30 July 2010
"Check All" checkbox in an apex:dataTable (without using scripts)
public class CheckboxCheckAllController {
public List<ContactWrapper> allContacts { get; set; }
public Boolean allChecked { get; set; }
public CheckboxCheckAllController () {
allContacts = new List<ContactWrapper>();
allChecked = false;
for(Contact contact: [select Name, Title, Department, Email from Contact ]){
allContacts.add(new ContactWrapper(contact));
}
}
public PageReference CheckAll(){
for(ContactWrapper contact : allContacts){
contact.selected = allChecked;
}
return null;
}
public PageReference ProcessSelectedContacts(){
for (ContactWrapper contactWrapper : allContacts ){
if(contactWrapper.selected == true){
/* Do Some Processing */
}
}
return null;
}
public class ContactWrapper {
public Contact con{get; set;}
public Boolean selected {get; set;}
public ContactWrapper(Contact c){
con = c;
selected = false;
}
}
}
<apex:page controller="CheckboxCheckAllController">
<apex:form>
<apex:dataTable value="{!allContacts}" var="c" id="contactsTable">
<apex:column>
<apex:facet name="header">
<apex:inputCheckbox value="{!allChecked}">
<apex:actionSupport event="onclick" action="{!CheckAll}"
rerender="contactsTable"/>
</apex:inputCheckbox>
</apex:facet>
<apex:inputCheckbox value="{!c.selected}"/>
</apex:column>
<apex:column value="{!c.con.Name}" headervalue="Full Name"/>
<apex:column value="{!c.con.Title}" headervalue="Title"/>
<apex:column value="{!c.con.Department}"
headervalue="Department"/>
<apex:column value="{!c.con.Email}" headervalue="Email"/>
</apex:dataTable>
<apex:commandButton action="{!ProcessSelectedContacts}"
value="Process Selected Contacts"/>
</apex:form>
</apex:page>
Thursday, 22 July 2010
Report Builder Developer Preview Webinar Feedback
To access the report builder, click on the Reports tab (can be included in an app through setup if not there already), and then on the “Create Report With Report Builder” button. The “Create New Custom Report” button allows you to use the old report wizard.
The report builder will be rolled out to all editions in the Winter ’11 release later this year, so is not immediately available to create and manipulate reports in Salesforce applications. However, because the underlying metadata for reports is the same no matter which composer is used, you could potentially use developer accounts to create the reports using the new builder and then copy the metadata to your production application. For this to work you must ensure that the underlying object models between the developer copy and your production org are the same.
Tuesday, 20 July 2010
Frustrations with the home page default view for objects
Thursday, 1 July 2010
Adding alphabetical lists in Salesforce PDFs
Page:
<apex:page showHeader="false" controller="LetterListController" standardStylesheets="false" sidebar="false">
<apex:dataList value="{!accounts}" type="a" var="account" id="theList" >
<apex:outputText value="{!account.name}"/>
</apex:dataList>
<ol type="a">
<li>First Item</li>
<li>Second Item</li>
<li>Third Item</li>
<li>Last Item</li>
</ol>
</apex:page>
public class LetterListController {
List<Account> accounts;
public List<Account> getAccounts() {
if(accounts == null) accounts = [select name from account limit 10];
return accounts;
}
}
When the Letter List page is rendered in Salesforce, the following output appears-
<apex:page showHeader="false" controller="LetterListController" standardStylesheets="false" sidebar="false" renderas="PDF">
<head>
<style>
.letterList{
list-style-type: lower-alpha;
}
</style>
</head>
<apex:dataList value="{!accounts}" var="account" id="theList" styleClass="letterList">
<apex:outputText value="{!account.name}"/>
</apex:dataList>
<ol class="letterList" type="a">
<li>First Item</li>
<li>Second Item</li>
<li>Third Item</li>
<li>Last Item</li>
</ol>
</apex:page>

