Download - Moving from Clicks to Code
![Page 1: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/1.jpg)
From Clicks To Code
Adam Bataran: Iron Mountain salesforce.com Boston User GroupAndrés Pérez: salesforce.com
Administrators
![Page 2: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/2.jpg)
Safe HarborSafe 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 outcome of intellectual property and other litigation, risks associated with possible mergers and acquisitions, 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, our limited history reselling non-salesforce.com products, 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 for the most recent fiscal year ended January 31, 2010. This documents and others 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.
![Page 3: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/3.jpg)
Agenda
1. Visualforce & Apex
2. Developer Tools
3. Governor Limits
4. Code Coverage
5. Apex Samples
6. You can do it!
7. Final Thoughts
8. Questions & Answers
![Page 4: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/4.jpg)
Who Are You?
Salesforce Administrators– Custom objects / fields, workflows, profiles / users, …
Some knowledge of programming– Java, C#, VB, PHP, Cobol, Pascal, Excel Macros (VBA),…
• Understand methods (functions), loops, conditions
• Have heard of OOP concepts (class, object, constructor, instance)
Querying databases– SELECT <fields> FROM <table>
Desire to create Visualforce and Apex code
![Page 5: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/5.jpg)
Visualforce& Apex
![Page 6: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/6.jpg)
What is Visualforce?
Tag based language (HTML, XML)
Display information
![Page 7: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/7.jpg)
What is Apex?
Object-oriented programming language (C#, Java)
Process Information
![Page 8: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/8.jpg)
Visualforce or Apex?
![Page 9: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/9.jpg)
Both!
Visualforce
Apex
![Page 10: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/10.jpg)
MVC Pattern?
![Page 11: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/11.jpg)
Standard Controllers for Visualforce
Provides basic logic without writing Apex code!
Standard or custom objects
Easy access to record fields
Methods provided: save, quicksave, edit, delete, cancel, list
Extensions– Write Apex code If additional functionality desired
Access page by passing ID of record– Example: /apex/Demo001?id=001A000000M41di
![Page 12: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/12.jpg)
Standalone Pages– Custom Tabs
– Wizards
Generate PDF files
Custom Components
Email Templates
Where can I use Visualforce?
Page Layout– Standard buttons
• Overriding actions
• Edit, Delete, …
– Custom buttons• Show Cases
– Embedded
![Page 13: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/13.jpg)
Where can I use Apex?
Controllers and
Extensions– Visualforce pages or
components
Triggers– Advanced Workflows
for complex logic
Test Code
Advanced Users– Web Services
• Inbound
• Outbound
– Helper Classes
– Email Handlers
– Batch jobs
– Scheduled jobs
![Page 14: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/14.jpg)
Developer Tools…
![Page 15: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/15.jpg)
Browser Editor
Small changes
Quick fixes
Troubleshooting
Code must be
error free to
save!
![Page 16: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/16.jpg)
Full Environment…
Force.com IDE– Eclipse
Imperfect code
saves locally
Also for
deployment
![Page 17: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/17.jpg)
Deployment
Tools– Change Sets (beta)
– Force.com IDE
– Force.com Migration Tool• Advanced Users
Production
Sandbox
![Page 18: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/18.jpg)
Governor Limits
![Page 19: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/19.jpg)
Governor Limits
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm
![Page 20: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/20.jpg)
Avoiding Common Governor Limits
Total number of records retrieved by SOQL queries
Total number of SOQL queries issued
Total number of DML statements issued
![Page 21: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/21.jpg)
Avoid: Total number of records retrieved
Need: Select many records
Problem: Querying over 10K records
Solutions– Good: Use LIMIT to reduce number of records retrieved
– Better: Add filtering criteria.
![Page 22: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/22.jpg)
Avoid: Total number of SOQL queries…
Need: Get parent and child records
Problem Querying child records per each parent
Solution:– Get all the accounts, then get all the contacts
– Only 2 queries!
![Page 23: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/23.jpg)
Need: Query and update many records
Problem: Updating one record at a time
Solution:– DML should be done on lists, not single objects!
Loop
Avoid: Total number of DML statements…
Loop
![Page 24: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/24.jpg)
Code Coverage
![Page 25: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/25.jpg)
What is Code Coverage?
Apex code written to test other Apex code (aka “Unit Testing”)
Test Class– Contains all test methods for one class being tested
– @isTest
– Name should be <Class>Test
Test Methods– private static testmethod void _____()
![Page 26: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/26.jpg)
Test Code: What should be covered?
Positive tests– “Must happen”
– Increment Account.TotalCases__c when case is created
Negative tests– “Can’t happen”
– Cases can’t be created if customer service has expired.
Aim to cover every “business use case”
![Page 27: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/27.jpg)
Code Coverage Requirements for Deployment
At least 75% of all your Apex scripts must be covered
Each trigger must have some coverage (at least 1%)
Every test must complete successfully– Deployment: Tests are run in the destination!
– Possible configuration differences: • Validation Rules
• Workflows
• Triggers
Visualforce is not covered
![Page 28: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/28.jpg)
How to Cover Custom Controllers?
Create instance class being tested
Invoke methods / properties
Use assert methods (Optional)
![Page 29: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/29.jpg)
How to Cover Triggers?
Perform DML operation
Use assert methods (optional)
![Page 30: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/30.jpg)
How to Cover Extensions?
Instantiate record
Instantiate ApexPages.StandardController
Instantiate extension
Invoke methods / properties
Visualforce
Apex Extension
ApexTest Method
![Page 31: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/31.jpg)
I’m not reaching 75% !!!
No failures!– Every test must
complete successfully
What else to cover?– Click % value
– Results• Blue = Covered
• Red = Not covered
![Page 32: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/32.jpg)
Apex Samples
![Page 33: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/33.jpg)
Triggers
Signature– sObject
– Event type:• Before: Update or validate record values before being saved
• After: Invoke other tasks or access final field values
– DML Operation: insert, update, delete, …
Context Variables:– trigger.new: List of records processed
– trigger.oldMap: Access old values
![Page 34: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/34.jpg)
SOQL Queries - Relationships
Relationships (going up)– SELECT Contact.Account.Name FROM Case
– SELECT MyContact__r.MyAccount__r.MyName__c FROM Case
Relationships (going down)– SELECT Name, (SELECT Name FROM Contacts) FROM Account
– SELECT ID, (SELECT ID FROM MyContacts__r) FROM Account
Filtering by other record IDs– SELECT Name FROM Account WHERE ID IN (SELECT AccountId
FROM Opportunity)
![Page 35: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/35.jpg)
You Can Do It!
Adam Bataran Iron MountainSalesforce.com Boston User Group
![Page 36: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/36.jpg)
Final Thoughts
![Page 37: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/37.jpg)
Do not hard-code IDs
User IDSELECT ID FROM User WHERE UserName = '[email protected]'
Profile IDSELECT ID FROM Profile WHERE Name = 'System Administrator'
RecordType IDSELECT ID FROM RecordType WHERE Name = 'Maintenance' AND
sObjectType = 'Opportunity'
![Page 38: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/38.jpg)
Indent Your Code!
![Page 39: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/39.jpg)
Are you stuck?
Call Developer Support!
It will be easier to help you if…– Reproduce issue in Sandbox
– Salesforce.com Organization ID• Setup > Administration Setup > Company Profile > Company Information
– Login access to user with System Administrator • Make sure access is for at least a month
– We’ll never take that long…
– If issue is specific to them• Provide login access to both (user + admin)
– Provide full steps to reproduce issue• Include URLs for pages, records, fields, code, …
![Page 40: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/40.jpg)
Next Steps…
Presentation & code in Dreamforce session page
Dreamforce– “Force.com Zone” ► Developer’s hideout
– Campground ► Training booth
Get a copy of the workbook– http://www.salesforce.com/us/developer/docs/workbook/index.ht
m
Obtain Developer ORG to learn code– http://developer.force.com
– Install sample code written for this session
Call Developer Support if you get stuck ;-)
![Page 41: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/41.jpg)
References / Links
For this presentation– Visualforce
– Apex
– Governor Limits
– SOQL
– Workbook
– OOP Concepts (
wikipedia)
– Deployment
Portals– developer.force.com
– Community Boards
Training– Portal
– Developer
Salesforce Support– (415) 901-7010
![Page 42: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/42.jpg)
Questions& Answers
![Page 43: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/43.jpg)
Questions & Answers
Adam Bataran– Iron Mountain
– Salesforce.com Boston User Group
Andrés Pérez– Salesforce.com
![Page 44: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/44.jpg)
D I S C O V E R
Visit Customer Success Team at Campground
Discover
Training
Learning Paths
Experience
Product
Demos
Learn about Customer
Resources
the products, services and resources
Meet Success Experts
S U C C E S S
Find us at the Customer Success Team area of Salesforce.com Campground at Moscone North
Learn about how to win prizes including 10 iPads & more!
that help you achieve
![Page 45: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/45.jpg)
From Clicks To Code
![Page 46: Moving from Clicks to Code](https://reader033.vdocument.in/reader033/viewer/2022061223/54c37b324a7959d2128b459d/html5/thumbnails/46.jpg)
How Could Dreamforce Be Better? Tell Us!
Log in to the Dreamforce app to submit
surveys for the sessions you attendedUse the
Dreamforce Mobile app to submit
surveysEvery session survey you submit is
a chance to win an iPod nano!
OR