Salesforce Developer CheatSheet
Salesforce Developer CheatSheet
• Navigation Menu — For pages that aren’t related to other objects or that require a full 4. Set the width to 100%; the element
3
screen, add the page to the navigation menu, or as a global action in the publisher. sizes automatically, minus some
padding on either side.
• Record Page — Pages that appear within the context of a record should go on the
object’s page layout. 5. Control the height of the Visualforce 5
page’s area by setting the height of
• Related Items — If you want a Visualforce page to appear on the related information the item in pixels in the page layout
page of an object record, add the page as a mobile card. Mobile cards are mobile only; editor. The Visualforce element uses
they don’t appear in the full Salesforce site. exactly that height, even if the content
• Global or Object-Specific Publisher Actions — If you want a Visualforce page is shorter. In that case, the extra area
to surface in the publisher, you can create it as a global or object-specific action. Custom is blank. If the page’s content is taller, the content is clipped. As a best practice, don’t set
actions aren’t specific to mobile users, and appear in both the Salesforce1 app and in the inline Visualforce pages to be taller than the smallest device screen you intend to support.
full Salesforce site. In the Salesforce1 app, custom actions appear in the publisher. In the
full Salesforce site, custom actions appear in the publisher menu.
Visualforce Pages on Record Related Items
These options are explained in more detail in the following sections
Mobile cards appear on the Record Information page of a record. It’s a best practice to add
Visualforce Pages in the Publisher only one or two cards, since users have to scroll past them to get to the other related items.
If you need a full screen to display your page, consider moving it to a custom action on the
When displayed in the Salesforce1 app, the standard Salesforce header and sidebar are object instead.
automatically removed. However, Visualforce pages used as custom actions in the publisher
are shared with the full Salesforce site, and pages added to the Salesforce1 navigation may 1. The record highlights header
or may not be shared. Pages shared with the full site shouldn’t have these items explicitly displays when a record is
removed, unless that’s the standard practice for all Visualforce pages in your organization. loaded, but can be scrolled up
and off the screen by the user. 1
When on screen, it’s 158
1. The Salesforce1 header, pixels tall on all devices, and
which provides access to the 1 takes the full width of the
main Salesforce1 menu, is 42 screen. You can’t control the
pixels tall. The contents of display of the record header. 3
the header can’t be changed. 2. Mobile cards display above 2
2. The rest of the device all of the related items on
screen is dedicated to the the record.
Visualforce page. 3. Set the width to 100%; the
4
Note: You must be sure to element sizes automatically,
select the Available for minus some padding on either
Salesforce mobile apps side. The content of mobile
2
checkbox. This designates cards can’t be scrolled, so make
that the page is mobile-ready sure it fits in the space you
and can be used in Salesforce1. provide it. 5
4. Control the height of the
mobile card by setting the
height in pixels in the page layout editor. The mobile card area uses exactly that height,
even if the mobile card’s content is shorter. In that case, the extra area is blank. If the
card’s content is taller, the content is clipped. As a best practice, don’t create mobile
cards taller than the smallest device screen you intend to support. Be sure to set the
height of screen elements relevant to your environment. So if you have an element
that’s always 300 pixels high, set the height to 300 pixels.
5. The record’s related items are displayed after all mobile cards.
http://developer.salesforce.com
Creating a Visualforce Custom Action Offline Caching Using the HTML5 Manifest Attribute
Creating a Visualforce custom action is the same process as global actions or object- Use the manifest attribute of the <apex:page> tag to set an HTML5 cache manifest
specific actions described on the Salesforce1 Admin Cheat Sheet. To use a Visualforce for offline caching of a page’s critical resources. You can use Visualforce to provide a page’s
page in a global or object-specific action, select Custom Visualforce for Action Type. cache manifest.
Note, when making an object-specific Visualforce publisher action, you need to set the The value of the manifest attribute is passed through to the generated HTML.
Standard Controller of your page to the SObject you want to create the action on. For example:
<apex:page showHeader="false" sidebar="false"
Styling a Mobile Visualforce Page for Salesforce1 standardStylesheets="false"
docType="html-5.0" manifest="/apex/CacheManifest">
Use Salesforce Mobile Design Templates as a starting point for your UI/UX design to <header>
dramatically shorten the time it takes to develop a great looking web/hybrid app on <h1>Congratulations!</h1>
the Salesforce Platform. Combine these open-source modular design templates with </header>
Salesforce1 Platform Mobile Services and your mobile app to view, edit and update
<article>
customer data, view backend reports, find nearby records, and more.
<p>This page looks almost like HTML5!</p>
The quickest way to get started with the Mobile Design Templates is via their interactive </article>
home page. As you scroll down the page, you’ll see each template broken down into its
</apex:page>
constituent HTML5/CSS3 components.
http://bit.ly/sfdcmobiletemplates
Setting Custom HTML Attributes on
Managing Navigation with the sforce.one Object Visualforce Components
You can add arbitrary attributes to many Visualforce components that will be “passed
The Salesforce1 Platform includes a strict event mechanism for navigation. This is through” to the rendered HTML. This is useful, for example, when using Visualforce with
exposed in Visualforce as a JavaScript object called sforce.one. It’s available in any JavaScript frameworks, such as jQuery Mobile, AngularJS, and Knockout, which use data-*
Visualforce page that appears in Salesforce1. or other attributes as hooks to activate framework functions. It can also be used to improve
usability with HTML5 features such as placeholder “ghost” text, pattern client-side
validation, and title help text attributes.
sforce.one.navigateToSObject Navigates to the record home of a particular
(recordId,view) SObject specified by recordId. view is To add a pass-through attribute to, for example, an <apex:outputPanel> component,
optional and can specify the view within prefix the attribute with "html-" and set the attribute value as normal.
record home to select.
<apex:page showHeader="false" standardStylesheets="false"
doctype="html-5.0">
sforce.one.navigateToURL Navigates to the specified URL. Relative urls <apex:outputPanel layout="block" html-data-role="panel"
(url, isredirect) will retain navigation history, absolute urls html-data-id="menu">
will open a new browser window.
<apex:insert name="menu"/>
isredirect indicates a history entry
should not be created. </apex:outputPanel>
<apex:outputPanel layout="block" html-data-role="panel"
sforce.one. Navigates to the specific feed subjectId. html-data-id="main">
navigateToFeed(subjectId,type) type is the expected feed type. <apex:insert name="main"/>
</apex:outputPanel>
sforce.one. Triggers a navigation to the specific feed item. </apex:page>
navigateToFeedItemDetail Check the Visualforce Developer’s Guide to see all of the Visualforce components that
(feedItemID) support pass-through attributes.
sforce.one. Triggers the record edit workflow for the Set the type Attribute for Input Widgets
editRecord(recordId) specified recordId.
Set the type attribute on input components to display UI widgets that help users enter data.
Each input adapts for the type of data expected: text fields show a keyboard, date fields show
sforce.one.back(refresh) Goes back to the previous state. Pass true to a date picker, etc. For example:
indicate the component should refresh
if possible. <apex:form >
<apex:outputLabel value="Phone" for="phone"/>
<apex:input id="phone" value="{!fPhone}" type="tel"/><br/>
Define an HTML5 Visualforce Page
<apex:outputLabel value="Email" for="email"/>
Use the docType="html-5.0" attribute in the <apex:page> tag to define the structure <apex:input id="email" value="{!fText}" type="email"/><br/>
of the rendered page. If html-5.0 is specified, you can utilize HTML5 browser features like
tags, JavaScript APIs (like drag and drop, local storage, and geolocation), and the useful <apex:outputLabel value="That Number" for="num"/>
Visualforce features as well. This will also relax the default HTML tidying in Visualforce <apex:input id="num" value="{!fNumber}" type="number"/><br/>
for HTML5 applications.
<apex:outputLabel value="The Big Day" for="date"/>
When building a custom styled mobile page, set standardStylesheets="false" on
<apex:input id="date" value="{!fDate}" type="date"/><br/>
the <apex:page> tag to eliminate any conflicts with the standard Salesforce stylesheets.
</apex:form>
These are added to the generated page header if the showHeader attribute is set to false.”
Use the applyHtmlTag and applyBodyTag attributes of the <apex:page> tag to
suppress the automatic generation of <html> and <body> tags, in favor of static markup
you add to the page yourself.
Input type Publisher Events continued.
You can also set type to auto, and the data type of the associated controller property or Visualforce Canvas Field Description
method is used. You can also explicitly set the following input types: publisher.failure Fired by the publisher when an
• date • datetime • datetime-local • month • week • time • email error condition is encountered
• number • range • search • tel • text • url such as when invalid data has
been submitted.
Client-Side Validation For example:
• The text in the feed is too long
Set HTML5 pass-through attributes to avoid sending a request to the server and waiting X • The page you’re attempting to
for a response. To enable client-side validation, set an html-pattern attribute on the publish to the feed doesn’t exist
<apex:input> tag to match expected form values. • The canvas app URL is invalid
If the input matches the regular expression validation pattern, the input is considered The canvas app should listen for
valid. If it doesn’t match, an error message displays and the form isn’t submitted to the this event and alert the user that an
server. The following example requires an email address from a specific domain. It uses the error occurred and the post didn’t
get created.
placeholder attribute to display sample ghost text.
publisher. Fired by the publisher when the
<apex:input id="email" value="{!fText}" type="email" getPayload Share button is clicked. The payload
html-placeholder="[email protected]" contains information such as the
html-pattern="^[a-zA-Z0-9._-][email protected]$" X text entered into the What are you
html-title="Please enter an example.com email address"/> working on? field and who the feed
You can also provide auto-suggestion by using <apex:input.list> to generate an item is being shared with.
HTML5 <datalist>. For example, the following will provide options based on what the publisher.post Fired by the publisher to indicate to
user types in the box: <apex:input.list="Aaa,Aabb,Aaacc"> X the page that the Submit button has
been pressed.
Navigation X publisher.refresh Fired by the page to refresh the feed.
publisher. Fired by the publisher when the feed
Salesforce1 provides a framework for handling various navigation controls and events, X X setupPanel is initially loaded.
that isn’t available to Visualforce pages when they run on the full Salesforce site. For
publisher. Fired by the canvas app to indicate
pages shared between the Salesforce1 app and the full site, use the sforce object when it’s
setPayload to the publisher that the content
available, and standard Visualforce navigation when it’s not. The following example runs
after a JavaScript remoting request successfully returns from the @RemoteAction method being sent to the publisher should
be shared in the feed item. This
that creates a quick order. This code is from a Visualforce page that’s used as a custom
event is in response to publisher.
action, which adds it to the publisher in the Salesforce1 app and the publisher menu in the
getPayload and contains
full site. The intent of the code is to navigate to the detail page for the account for whom
the order was placed, and it needs to work in both places:
X information about the feed item
you’re trying to create.
// Go back to the Account detail page
You can create three feed item types:
if( (typeof sforce != 'undefined') && (sforce != null) ) { • TextPost
// Salesforce1 navigation • LinkPost
sforce.one.navigateToSObject(aId); • CanvasPost
} publisher. Fired by the canvas app/page to
} else { setValidForSubmit indicate to the publisher that the
// Set the window's URL using a Visualforce expression
canvas app/page is ready to submit
window.location.href = '{!URLFOR($Action.Account.View, aId)}'; a payload. After this event fires, the
} Share/Submit button becomes active.