27
D evelopm entw ith Force.com Luu Thanh Thuy CWI Team

Development withforce

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Development withforce

Development with Force.com

Luu Thanh Thuy

CWI Team

Page 2: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 2

Agenda

- Overview of Force.com- Overview of Force.com

-- Database Database

-- Business Logic Business Logic

- User interface- User interface

- Integration- Integration

Page 3: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 3

Overview of force.com

--Is part of Salesforce.comIs part of Salesforce.com-PaaS.PaaS.-Is free for developerIs free for developer-Relational database-Relational database-Apex language . Its syntax is blend of Java and database Apex language . Its syntax is blend of Java and database stored language.stored language.-Force.com IDEForce.com IDE

Page 4: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 4

Database

-Objects : related to database tables. Contains custom and standard object.-Objects : related to database tables. Contains custom and standard object.-Logical, not Physical, Object-Logical, not Physical, Object-Delegated Tuning and Operations-Delegated Tuning and Operations-Undelete Support-Undelete Support-Fields-Fields-Unique Identifiers-Unique Identifiers-Validation rules-Validation rules-Formula Fields-Formula Fields

Billable Revenue (Currency) = Week_Total_Hrs__c * Rate_Per_Hour__cBillable Revenue (Currency) = Week_Total_Hrs__c * Rate_Per_Hour__c-Rich Data TypesRich Data Types-History trackingHistory tracking-Relationships : one to one, one to many, many to manyRelationships : one to one, one to many, many to many

Page 5: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 5

Query Language

-Force.com has two query langue: Salesforce Object Query Language (SOQL)-Force.com has two query langue: Salesforce Object Query Language (SOQL)And Salesforce Object Search Language (SOSL)And Salesforce Object Search Language (SOSL) Select Name, Total_Billable_Revenue_Pending_Invoice__c Select Name, Total_Billable_Revenue_Pending_Invoice__c From Proj__cFrom Proj__c where Invoiced__c= FALSE and Start_Date__c = LAST_QUARTERwhere Invoiced__c= FALSE and Start_Date__c = LAST_QUARTER ORDER_BY Total_Billable_Revenue_Pending_Invoice__c DESC LIMIT 10ORDER_BY Total_Billable_Revenue_Pending_Invoice__c DESC LIMIT 10

FIND ‘java*’ in all fields returning Project__c, Resource__c, Assignment__c, FIND ‘java*’ in all fields returning Project__c, Resource__c, Assignment__c, Skill__cSkill__c

-No Function in Column list-No Function in Column list-Governor Limits-Governor Limits

Page 6: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 6

Object creation

Page 7: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 7

Database security

Security architectures as a funnelSecurity architectures as a funnel

Page 8: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 8

Security Architecture

Page 9: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 9

Implementing the Security Model

-1. Create Profiles 1. Create Profiles

-2. Configure Field Accessibility2. Configure Field Accessibility

-3. Set Organization-Wide default3. Set Organization-Wide default

-4. Establish Role hierarchy4. Establish Role hierarchy

-5. Adding Sharing Rule5. Adding Sharing Rule

Page 10: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 10

Database security

Page 11: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 11

Business Logic

-Force IDEForce IDE-Apex language basicApex language basic-Database triggerDatabase trigger-Debugging and TestingDebugging and Testing

Page 12: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 12

Database trigger

Triggers are Apex code working in concert with the Force.com database engine, Triggers are Apex code working in concert with the Force.com database engine, automatically invoked by Force.com when database records are modified.Trigger automatically invoked by Force.com when database records are modified.Trigger code can perform any necessary processing on the modified data before or after code can perform any necessary processing on the modified data before or after Force.comForce.com

Page 13: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 13

Business Logic

_Save points :Savepoints are markers indicating the state of the database at a _Save points :Savepoints are markers indicating the state of the database at a specific point in the execution of your Apex program.They specific point in the execution of your Apex program.They allow the database to the database to be restored to a known state in case of error or any scenario requiring a reversal be restored to a known state in case of error or any scenario requiring a reversal of all DML operations performed since the savepoint.of all DML operations performed since the savepoint.

void printRecordCount() {void printRecordCount() {System.debug([ SELECT COUNT() FROM Resource__c ] + ' records');System.debug([ SELECT COUNT() FROM Resource__c ] + ' records');}}printRecordCount();printRecordCount();Savepoint sp = Database.setSavepoint();Savepoint sp = Database.setSavepoint();delete [ SELECT Id FROM Resource__c ];delete [ SELECT Id FROM Resource__c ];printRecordCount();printRecordCount();Database.rollback(sp);Database.rollback(sp);printRecordCount();printRecordCount();Database.rollback(sp);Database.rollback(sp);printRecordCount();printRecordCount();

Page 14: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 14

Business Logic

_ Record Locking prevent updates by one program have been modified by a _ 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 second program running at the same time.The changes of the second program are lost because the first program is operating with stale data.are lost because the first program is operating with stale data.

Resource__c tim = [ SELECT Id, Hourly_Cost_Rate__cResource__c tim = [ SELECT Id, Hourly_Cost_Rate__cFROM Resource__cFROM Resource__cWHERE Name = 'Tim Barr' LIMIT 1WHERE Name = 'Tim Barr' LIMIT 1FOR UPDATE ];FOR UPDATE ];tim.Hourly_Cost_Rate__c += 20;tim.Hourly_Cost_Rate__c += 20;update tim;update tim;

Page 15: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 15

Business Logic

The three ways to send email in Apex are the following:The three ways to send email in Apex are the following:1.1. SingleEmailMessage: Sends an email to up to ten receivers.The email addresses of 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 receivers are provided as strings. A string containing HTML or plain text is used as the message body.message body.

2. SingleEmailMessage with Template: Sends to up to ten receivers, but the unique 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 stringsidentifiers of Contact, Lead, or User objects must be used instead of strings

to provide the receivers’ email addresses.The message body is constructed from ato provide the receivers’ email addresses.The message body is constructed from atemplate.Templates are globally available to an organization as defined by an administratortemplate.Templates are globally available to an organization as defined by an administratoror private to an individual user.Templates can include merge fields toor private to an individual user.Templates can include merge fields todynamically substitute field values from the receiver’s record and, optionally, fielddynamically substitute field values from the receiver’s record and, optionally, fieldvalues from an additional, related object.values from an additional, related object.

3. MassEmailMessage: Behaves like a SingleEmailMessage with template but can3. MassEmailMessage: Behaves like a SingleEmailMessage with template but cansend email to up to 250 receivers in a single call.send email to up to 250 receivers in a single call.

Page 16: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 16

User Interfaces

Page 17: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 17

User Interfaces

_Visualforce controller : Standard controller, custom controller, Controller _Visualforce controller : Standard controller, custom controller, Controller extensionextension

1.1. Standard controller :Every database object has a standard controller. Its name Standard controller :Every database object has a standard controller. Its name is simply the name of the object. The implement is already provided by is simply the name of the object. The implement is already provided by Force.comForce.com

2.2. Custom controller : no default functionality and consisting entirely of custom Custom controller : no default functionality and consisting entirely of custom Apex codeApex code

3. Controller extension : extends the standard controller3. Controller extension : extends the standard controller

Page 18: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 18

User Interfaces :Modular Visualforce

Visualforce provide several features developer can use to create modular, highly Visualforce provide several features developer can use to create modular, highly maintainable pages.maintainable pages.

1.1. Static resources : reusable images, scripts, stylesheets and other static Static resources : reusable images, scripts, stylesheets and other static content can be stored in resources, available for embeding in all Visualforce content can be stored in resources, available for embeding in all Visualforce pages in the Force.com organizationpages in the Force.com organization

2.2. Inclusion the contents of one Visualforce page can be included in another Inclusion the contents of one Visualforce page can be included in another page. A common use for this is page headers and footerspage. A common use for this is page headers and footers

3.3. Composition : Composition allows one Visualforce page to serve as a Composition : Composition allows one Visualforce page to serve as a template for another. The template specifies the static and dynamic portions of template for another. The template specifies the static and dynamic portions of a pagea page

4.4. Custom Visualforce components: developers define their own custom Custom Visualforce components: developers define their own custom components, reusable in any pagecomponents, reusable in any page

Page 19: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 19

Batch Processing

Batch processing is used for processing data exceeding the governor limits of Batch processing is used for processing data exceeding the governor limits of triggers and controller, allow you keep the large, data-intensive processing task 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 within the platform, taking advantage of its close proximity to the data and transactional integrity. transactional integrity. Some key concepts in Batch ApexSome key concepts in Batch Apex1.Scope : is the set of records that a Batch Apex process operates on. It can 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 consist of 1 record or up to 50 million records. Scope is expressed as a SOQL statementstatement2. Batch job : a batch job is a Batch Apex program that have been submitted for 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 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 jobs. Salesforce provide user interface for listing batch jobs and their status and allow individual jobs to be canceled.allow individual jobs to be canceled.3. Transaction : is up to 200 records. When a batch job start, the scope is split 3. Transaction : is up to 200 records. When a batch job start, the scope is split into a series of transactions.into a series of transactions.

Page 20: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 20

Batchable Interface

In order to execute Batch job, Apex class must inplement Batchable interface, the In order to execute Batch job, Apex class must inplement Batchable interface, the logic processing following methodlogic processing following method

1.1. Start : run a QueryLocatior or an Iterable that describes the scope of the batch Start : run a QueryLocatior or an Iterable that describes the scope of the batch job.job.

2.2. Execute: After execute start, Force splits the records set into sets of up to 200 Execute: After execute start, Force splits the records set into sets of up to 200 records and invokes your execute method repeatedlyrecords and invokes your execute method repeatedly

3.3. Finish ; the finish method is invoked once at the end of a batch job. You could 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 use this method tho clear up any working state or notify the user via email that the batch job is completedthe batch job is completed

Page 21: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 21

Example

Page 22: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 22

Stateful Batch Apex

Batch apex is stateless by default, means for each execution of your execute 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 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 information that is shared across the transactions, make the Batch Apex class stateful by implementing Stateful inferface.stateful by implementing Stateful inferface.

Page 23: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 23

Limit Of Batch Apex

1.1. The maximum heap size in Batch Apex is 6 MBThe maximum heap size in Batch Apex is 6 MB2.2. Calling out to external systems using the HTTP object or webservice methods Calling out to external systems using the HTTP object or webservice methods

a limited to one for each invocation of start,execute and finisha limited to one for each invocation of start,execute and finish3.3. Transactions run under the same governor limits as any Apex codeTransactions run under the same governor limits as any Apex code4.4. The maximum number of queued or active batch jobs within an entire The maximum number of queued or active batch jobs within an entire

Salesforce organization is fiveSalesforce organization is five

Page 24: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 24

Integration_Force.com support both SOAP and REST (xml or json)_Force.com support both SOAP and REST (xml or json)_Force provides five types of Web service APIs : Enterprise, Partner, Metadata, _Force provides five types of Web service APIs : Enterprise, Partner, Metadata, Apex , and Delegated AuthenticationApex , and Delegated Authentication

_The Enterprise API provides a strongly typed representation of the objects in _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 your Force.com. When you redefine an object or add a new object, the WSDL is automatically update. You need manually download automatically update. You need manually download _ The Partner API is designed for independent software vendor. They cannot repy _ 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 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 API , you can write generic code to access any object in any Force.com organization organization

Page 25: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 25

Generating Stub Code

Force advises that you use the Force.com Web Service Connector (WSC) with its Force advises that you use the Force.com Web Service Connector (WSC) with its Web services . Web services . http://code.google.com/p/sfdc-wsc. Copy WSC jar and . Copy WSC jar and enterprise.wsdl into same folderenterprise.wsdl into same folder

Page 26: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 26

Custom web service

-Global class access modifier-Global class access modifier-Web service method. These method must be staticWeb service method. These method must be static-Supporting class : user-defined Apex class, inner and outer that are arguments 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 or return values for a Web services must be defined as global. Member variables of these classes must be defined using webservice keywordof these classes must be defined using webservice keyword-No Overloading : overloading method result in a compile errorNo Overloading : overloading method result in a compile error-Prohibited types : the Map, Set, Pattern , Matcher, Exception and Enum types Prohibited types : the Map, Set, Pattern , Matcher, Exception and Enum types are not allowed in the arguments or return types of Apex Webservicesare not allowed in the arguments or return types of Apex Webservices

Page 27: Development withforce

www.exoplatform.com - Copyright 2012 eXo Platform 27