moving from clicks to code
Post on 24-Jan-2015
704 Views
Preview:
DESCRIPTION
TRANSCRIPT
From Clicks To Code
Adam Bataran: Iron Mountain salesforce.com Boston User GroupAndrés Pérez: salesforce.com
Administrators
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.
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
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
Visualforce& Apex
What is Visualforce?
Tag based language (HTML, XML)
Display information
What is Apex?
Object-oriented programming language (C#, Java)
Process Information
Visualforce or Apex?
Both!
Visualforce
Apex
MVC Pattern?
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
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
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
Developer Tools…
Browser Editor
Small changes
Quick fixes
Troubleshooting
Code must be
error free to
save!
Full Environment…
Force.com IDE– Eclipse
Imperfect code
saves locally
Also for
deployment
Deployment
Tools– Change Sets (beta)
– Force.com IDE
– Force.com Migration Tool• Advanced Users
Production
Sandbox
Governor Limits
Governor Limits
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm
Avoiding Common Governor Limits
Total number of records retrieved by SOQL queries
Total number of SOQL queries issued
Total number of DML statements issued
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.
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!
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
Code Coverage
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 _____()
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”
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
How to Cover Custom Controllers?
Create instance class being tested
Invoke methods / properties
Use assert methods (Optional)
How to Cover Triggers?
Perform DML operation
Use assert methods (optional)
How to Cover Extensions?
Instantiate record
Instantiate ApexPages.StandardController
Instantiate extension
Invoke methods / properties
Visualforce
Apex Extension
ApexTest Method
I’m not reaching 75% !!!
No failures!– Every test must
complete successfully
What else to cover?– Click % value
– Results• Blue = Covered
• Red = Not covered
Apex Samples
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
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)
You Can Do It!
Adam Bataran Iron MountainSalesforce.com Boston User Group
Final Thoughts
Do not hard-code IDs
User IDSELECT ID FROM User WHERE UserName = 'admin@company.com'
Profile IDSELECT ID FROM Profile WHERE Name = 'System Administrator'
RecordType IDSELECT ID FROM RecordType WHERE Name = 'Maintenance' AND
sObjectType = 'Opportunity'
Indent Your Code!
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, …
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 ;-)
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
Questions& Answers
Questions & Answers
Adam Bataran– Iron Mountain
– Salesforce.com Boston User Group
Andrés Pérez– Salesforce.com
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
From Clicks To Code
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
top related