Search In This Blog

2016-08-18

Eclipse with Force.com IDE

Prerequisites
  • Eclipse
  • JDK, Runtime Environment 7 or later
Step 1.
Launch Eclipse, Help > Install New Software, click Add

Step 2.
Set Name as "Force.com IDE"
Set Location as "http://media.developerforce.com/force-ide/eclipse42"
Then click OK

Step 3.
At least select Force.com IDE from the download list. If you don't konw which one is needed, select all. Then click Next
If you want an older version, uncheck the "Show only the latest versions of available software".

Step 4.
Click Next in Install Details dialog. Then accept the terms and click Finish. When Eclipse finished installation, you will be prompted to restart Eclipse.

Step 5.
You can check is Force.com installed successful by Eclipse > Window > Perspective > Open Perspective > Other. If you can see Force.com in list, it means success.

Step 6.
Select Force.com and click OK. You can start to develop now.

2016-08-17

How to create a public website or application by Salesfore

Recently, I supported a few of  SFDC beginners build an online membership management system.

Then they asked me a question: how to create a public site and application with salesforce? No need to log in with a username and password.

Public website is available in Salesforce Classic Developer/Enterprise/Performance/Unlimited Edition. There are steps below.

Step 1.
Need a Manage User

Step 2.
Log in Salesforce with Manage User, click the setup link in right-top.

Step 3.
Use Quick Find box to search 'sites' and select 'Sites'. Or find it in left bar: Build > Develop > Sites
There will be a introduce to What is a Site? You can read it to get more information about Force.com site.

Step 4.
Choice a unique name for your site, you can check it by 'Check Availability' button. If the name is available, then check the agree checkbox and click 'Register My Force.com Domain' button to register a custom Force.com for your org.
Attention: This name can't be modified after be registered.

Step 5.
New a page for this site and input the fields. You can just input the necessary fields.
  • Site label: Appears in user interface.
  • Site Name: Will be used when referencing the site in the SOAP API
  • Site Description: An optional description.
  • Site Contact: The account to receive site-related communications.
  • Default Web Address: Public will use this URL to access your site.
  • Active: Publish the site right after save or not.
  • Active Site Home Page: The landing page, choice a Visualforce page
  • Inactive Site Home Page: Default is maintenance page, you can customize it.
  • Site Templates: Provide page layout and stylesheet.
  • Site Robots.txt: Help to be searched by Google.
  • Site Favorite Icon:
  • Analytics Tracking Code: Like Google Analytics Code ID
  • URL Rewriter Class: The Apex class used for URL rewriting on this site.
  • Enable Feeds
  • Clickjack Protection Level:
  • Require Secure Connections(HTTPS)
  • Guest Access to the Support API
Step 6.
Save and check the site.
If site is inactive, it will a maintenance page as below.

If license is trial edition, you can't find sites menu and unable to public the site.


How to display Visualforce page as PDF

Add renderAs="pdf" in <apex:page> tag as below.
<apex:page renderAs="pdf">
Add CSS style to set format of page.
@page {
size: letter;
@top-center {content: "PDF Sample";}
@bottom-center {content: "Page " counter(page) " of " counter(pages);}
}
*Most used page size: landscape/8.27in 11.69in (A4 width and height)

Attention:
@page must be inside of <html><head><style>, or include as a static resource.
<apex:page renderAs="pdf">
    <html>
        <head>
            <style>
                @page {...}
            </style>
        </head>
    </html>
</apex:page>

Use page-break to control when is next page. If you didn't set page break, it will only display in next page when out of bound.
<style>
.page-break {display:block; page-break-after:always;}
</style>
<body>
        <div class="page-break">
                <apex:outputText >Page 1</apex:outputText>
        </div>
        <div>Page 2</div>
</body>

2016-08-16

Solve MavensMate LOGIN_MUST_USE_SECURITY_TOKEN error

You may happened to LOGIN_MUST_USE_SECURITY_TOKEN error when you use MavensMate.

It is because the access is out of trusted networks. You can find the solution in warning.

Login to Salesforce, My Settings > Personal > Reset My Security Token > Reset Security Token

2016-08-15

How to develop SFDC project with Sublime Text and MavebsMate

To develop SFDC project with Sublime Text 2/3, you need to make some preparations.

Step 1.
In Mac:
Use Command+Shift+P to open 'Package Control' or Menu bar > Sublime Text > Preferences > Package Control

In Windows:
Menu bar > Preferences > Package Control

Step 2.
Input 'Package Control: Install Package', pull enter key.

Step 3.
Search 'Maven' and install it.

Step 4.
MavensMate > Settings > User
Find '"mm_workspace"' and set your workspace folder like:
"mm_workspace" : [
         "/my/workspace",
         "/my/other/workspace",
         // Input path to your workspace folder
]
Then save.

Step 5.
MavensMate > Project > New Project
Input your organization information and Create Project.

If you happened to 'LOGIN_MUST_USE_SECURITY_TOKEN' error, check here.

2016-08-12

Prevent double submission of forms.

When save customize form data with apex:commandButton, double submission is needed to be attention.

If you use standard control and standard save function, salesforce may help you to prevent double submission. But when you use a customize button action to save data, you will need to do by yourself.

Double submission can be prevented by JavaScript easily and efficiently.

Put code below inside <head></head>
<script type="text/javascript"> 
var isSave = false; 
function check(){ 
if (!isSave) { 
isSave = true; 
return true; 
} 
return false; 
} 
</script> 

Then put <apex:commandbutton> inside of <apex:form></apex:form>.
<apex:commandButton action="{!test}" value="Refresh" onclick="return check();"/>
*value is the button's name; when click this button, function check() will be called and return boolean value.