2. Agenda
- Overview of Force.com
- Database
- Business Logic
- User interface
- Integration
www.exoplatform.com - Copyright 2012 eXo Platform 2
3. Overview of force.com
-Is part of Salesforce.com
-PaaS.
-Is free for developer
-Relational database
-Apex language . Its syntax is blend of Java and database
stored language.
-Force.com IDE
www.exoplatform.com - Copyright 2012 eXo Platform 3
4. Database
-Objects : related to database tables. Contains custom and standard object.
-Logical, not Physical, Object
-Delegated Tuning and Operations
-Undelete Support
-Fields
-Unique Identifiers
-Validation rules
-Formula Fields
Billable Revenue (Currency) = Week_Total_Hrs__c * Rate_Per_Hour__c
-Rich Data Types
-History tracking
-Relationships : one to one, one to many, many to many
www.exoplatform.com - Copyright 2012 eXo Platform 4
5. Query Language
-Force.com has two query langue: Salesforce Object Query Language (SOQL)
And Salesforce Object Search Language (SOSL)
Select Name, Total_Billable_Revenue_Pending_Invoice__c
From Proj__c
where Invoiced__c= FALSE and Start_Date__c = LAST_QUARTER
ORDER_BY Total_Billable_Revenue_Pending_Invoice__c DESC LIMIT 10
FIND ‘java*’ in all fields returning
Project__c, Resource__c, Assignment__c, Skill__c
-No Function in Column list
-Governor Limits
www.exoplatform.com - Copyright 2012 eXo Platform 5
11. Business Logic
-Force IDE
-Apex language basic
-Database trigger
-Debugging and Testing
www.exoplatform.com - Copyright 2012 eXo Platform 11
12. Database trigger
Triggers are Apex code working in concert with the Force.com database
engine, automatically invoked by Force.com when database records are
modified.Trigger code can perform any necessary processing on the modified
data before or after Force.com
www.exoplatform.com - Copyright 2012 eXo Platform 12
13. Business Logic
_Save points :Savepoints are markers indicating the state of the database at a
specific point in the execution of your Apex program.They allow the database to
be restored to a known state in case of error or any scenario requiring a reversal
of all DML operations performed since the savepoint.
void printRecordCount() {
System.debug([ SELECT COUNT() FROM Resource__c ] + ' records');
}
printRecordCount();
Savepoint sp = Database.setSavepoint();
delete [ SELECT Id FROM Resource__c ];
printRecordCount();
Database.rollback(sp);
printRecordCount();
Database.rollback(sp);
printRecordCount();
www.exoplatform.com - Copyright 2012 eXo Platform 13
14. Business Logic
_ Record Locking prevent updates by one program have been modified by a
second program running at the same time.The changes of the second program
are lost because the first program is operating with stale data.
Resource__c tim = [ SELECT Id, Hourly_Cost_Rate__c
FROM Resource__c
WHERE Name = 'Tim Barr' LIMIT 1
FOR UPDATE ];
tim.Hourly_Cost_Rate__c += 20;
update tim;
www.exoplatform.com - Copyright 2012 eXo Platform 14
15. Business Logic
The three ways to send email in Apex are the following:
1. SingleEmailMessage: Sends an email to up to ten receivers.The email addresses of
receivers are provided as strings. A string containing HTML or plain text is used as the
message body.
2. SingleEmailMessage with Template: Sends to up to ten receivers, but the unique
identifiers of Contact, Lead, or User objects must be used instead of strings
to provide the receivers’ email addresses.The message body is constructed from a
template.Templates are globally available to an organization as defined by an administrator
or private to an individual user.Templates can include merge fields to
dynamically substitute field values from the receiver’s record and, optionally, field
values from an additional, related object.
3. MassEmailMessage: Behaves like a SingleEmailMessage with template but can
send email to up to 250 receivers in a single call.
www.exoplatform.com - Copyright 2012 eXo Platform 15
16. User Interfaces
www.exoplatform.com - Copyright 2012 eXo Platform 16
17. User Interfaces
_Visualforce controller : Standard controller, custom controller, Controller
extension
1. Standard controller :Every database object has a standard controller. Its name
is simply the name of the object. The implement is already provided by
Force.com
2. Custom controller : no default functionality and consisting entirely of custom
Apex code
3. Controller extension : extends the standard controller
www.exoplatform.com - Copyright 2012 eXo Platform 17
18. User Interfaces :Modular Visualforce
Visualforce provide several features developer can use to create modular, highly
maintainable pages.
1. Static resources : reusable images, scripts, stylesheets and other static
content can be stored in resources, available for embeding in all Visualforce
pages in the Force.com organization
2. Inclusion the contents of one Visualforce page can be included in another
page. A common use for this is page headers and footers
3. Composition : Composition allows one Visualforce page to serve as a
template for another. The template specifies the static and dynamic portions of
a page
4. Custom Visualforce components: developers define their own custom
components, reusable in any page
www.exoplatform.com - Copyright 2012 eXo Platform 18
19. Batch Processing
Batch processing is used for processing data exceeding the governor limits of
triggers and controller, allow you keep the large, data-intensive processing task
within the platform, taking advantage of its close proximity to the data and
transactional integrity.
Some key concepts in Batch Apex
1.Scope : is the set of records that a Batch Apex process operates on. It can
consist of 1 record or up to 50 million records. Scope is expressed as a SOQL
statement
2. Batch job : a batch job is a Batch Apex program that have been submitted for
execution. Batch job run in background an can take many hours to complete the
jobs. Salesforce provide user interface for listing batch jobs and their status and
allow individual jobs to be canceled.
3. Transaction : is up to 200 records. When a batch job start, the scope is split
into a series of transactions.
www.exoplatform.com - Copyright 2012 eXo Platform 19
20. Batchable Interface
In order to execute Batch job, Apex class must inplement Batchable interface, the
logic processing following method
1. Start : run a QueryLocatior or an Iterable that describes the scope of the batch
job.
2. Execute: After execute start, Force splits the records set into sets of up to 200
records and invokes your execute method repeatedly
3. Finish ; the finish method is invoked once at the end of a batch job. You could
use this method tho clear up any working state or notify the user via email that
the batch job is completed
www.exoplatform.com - Copyright 2012 eXo Platform 20
21. Example
www.exoplatform.com - Copyright 2012 eXo Platform 21
22. Stateful Batch Apex
Batch apex is stateless by default, means for each execution of your execute
method, you receive a fresh copy of your object. If your batch process needs
information that is shared across the transactions, make the Batch Apex class
stateful by implementing Stateful inferface.
www.exoplatform.com - Copyright 2012 eXo Platform 22
23. Limit Of Batch Apex
1. The maximum heap size in Batch Apex is 6 MB
2. Calling out to external systems using the HTTP object or webservice methods
a limited to one for each invocation of start,execute and finish
3. Transactions run under the same governor limits as any Apex code
4. The maximum number of queued or active batch jobs within an entire
Salesforce organization is five
www.exoplatform.com - Copyright 2012 eXo Platform 23
24. Integration
_Force.com support both SOAP and REST (xml or json)
_Force provides five types of Web service APIs :
Enterprise, Partner, Metadata, Apex , and Delegated Authentication
_The Enterprise API provides a strongly typed representation of the objects in
your Force.com. When you redefine an object or add a new object, the WSDL is
automatically update. You need manually download
_ The Partner API is designed for independent software vendor. They cannot repy
on a single, static representation of standard and custom object. With the partner
API , you can write generic code to access any object in any Force.com
organization
www.exoplatform.com - Copyright 2012 eXo Platform 24
25. Generating Stub Code
Force advises that you use the Force.com Web Service Connector (WSC) with its
Web services . http://code.google.com/p/sfdc-wsc. Copy WSC jar and
enterprise.wsdl into same folder
www.exoplatform.com - Copyright 2012 eXo Platform 25
26. Custom web service
-Global class access modifier
-Web service method. These method must be static
-Supporting class : user-defined Apex class, inner and outer that are arguments
or return values for a Web services must be defined as global. Member variables
of these classes must be defined using webservice keyword
-No Overloading : overloading method result in a compile error
-Prohibited types : the Map, Set, Pattern , Matcher, Exception and Enum types
are not allowed in the arguments or return types of Apex Webservices
www.exoplatform.com - Copyright 2012 eXo Platform 26