Professional Documents
Culture Documents
Intro Apex Code Webinar
Intro Apex Code Webinar
Pat Patterson Principal Developer Evangelist @metadaddy Taggart Matthiesen Director of Product Management @tmatthiesensfdc
Safe Harbor
Safe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services. The risks and uncertainties referred to above include but are not limited to risks associated with developing and delivering new functionality for our service, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K filed on February 24, 2011 and in other filings with the Securities and Exchange Commission. These documents are available on the SEC Filings section of the Investor Information section of our Web site. Any unreleased services or features referenced in this or other press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
P Join the conversation on Twitter: #forcewebinar @forcedotcom
Agenda
What is Apex Code? When should I use Apex, and when shouldnt I?
Database Triggers UI Controllers Web Services
Force.com Technologies
Declarative Logic (point and click)
Required/Unique Fields Audit History Tracking Workflows Rules & Approval Processes
Code must have unit test coverage before going live Augments the Declarative (point-and-click) UI
But doesnt replace it!
A Major Milestone
An Apex Class
public class StoreFront { DisplayMerchandise[] products;
Class Definition Member Variable
Automatic Property
public DisplayMerchandise[] getProducts() { if (products == null) { List Iteration products = new DisplayMerchandise[]{}; Instance for Loop Method for (Merchandise__c item : [SELECT id, name, description__c, price__c FROM Merchandise__c WHERE Total_Inventory__c > 0]) { products.add(new DisplayMerchandise(item)); SOQL Query } } return products; } }
Programmatic second
Complex transactions Integrations (email, web services) Asynchronous processing Custom controllers (custom UI & logic)
Apex Triggers
before
Can update or validate data, or even abort event
after
Can create links to newly created fields, records
An Apex Trigger
Trigger Events
trigger HandleProductPriceChange on Merchandise__c (after update) { List<Line_Item__c> openLineItems = SOQL Query [SELECT j.Unit_Price__c, j.Merchandise__r.Price__c FROM Line_Item__c j Trigger Definition WHERE j.Invoice_Statement__r.Status__c = 'Negotiating' AND j.Merchandise__r.id IN :Trigger.new Trigger FOR UPDATE]; Context
Variable
for (Line_Item__c li: openLineItems) { if ( li.Merchandise__r.Price__c < li.Unit_Price__c ){ li.Unit_Price__c = li.Merchandise__r.Price__c; } } update openLineItems; }
P Join the conversation on Twitter: #forcewebinar @forcedotcom DML Operation
Model
View
P Join the conversation on Twitter: #forcewebinar @forcedotcom
Controller
An Apex Controller
Visualforce page the view
<apex:page standardStylesheets="false" showHeader="false"
sidebar="false" controller="StoreFront" > <apex:stylesheet value="{!URLFOR($Resource.styles, 'styles.css')}"/> <h1>Store Front</h1>
Custom Controller Reference
';
Inbound
Currently SOAP only Use webService keyword Generate WSDL for web service consumer
Outbound
SOAP
Import WSDL, Apex stubs generated
HTTP
Developer responsible for creating request, parsing response Apex JSON parser available via open source project
P Join the conversation on Twitter: #forcewebinar @forcedotcom
products[0].price__c = 20; // raise price products[1].price__c = 5; // lower price Test.startTest(); update products; Test.stopTest();
lineItems = [SELECT id, unit_price__c FROM Line_Item__c WHERE id IN :lineItems]; System.assert(lineItems[0].unit_price__c == 10); // unchanged System.assert(lineItems[1].unit_price__c == 5); // changed!! } }
P Join the conversation on Twitter: #forcewebinar @forcedotcom
Governor Limits
Runtime limits protect the multi-tenant environment from runaway code 18 limits covering database access, execution environment, callouts Follow best practice to get the most out of your code
Example batch DML operations to minimize consumption of DML statement resource
Your Resource
http://developer.force.com/
Force.com Workbook
Basic Visualforce, Apex
Chatter Workbook
Get Started with the Collaboration Cloud
Visualforce Workbook
Focus on the UI
http://developer.force.com/workbook
Boards for Apex, Visualforce, Chatter, Integration with Java, .NET, Ruby, Jobs, and more.
http://boards.developerforce.com/
Terms:
Selection process three times/year MVPs will have a one year term, at which point they are re-evaluated
http://developer.force.com/mvp
P Join the conversation on Twitter: #forcewebinar @forcedotcom
http://salesforce.com/training
http://bit.ly/apex_testing
P Join the conversation on Twitter: #forcewebinar @forcedotcom