moving from clicks to code

46
From Clicks To Code Adam Bataran: Iron Mountain salesforce.com Boston User Group Andrés Pérez: salesforce.com Administrators

Upload: salesforce

Post on 24-Jan-2015

704 views

Category:

Business


6 download

DESCRIPTION

Ready to intensify? If you've been a Salesforce administrator for a while and are looking to expand your knowledge, this is just the session for you. We'll introduce advanced concepts such as Force.com pages (Visualforce), Force.com code (Apex), platform fundamentals, and other relevant topics to help you better understand how you can go from admin to hero in 0 to 60.

TRANSCRIPT

Page 1: Moving from Clicks to Code

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

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

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

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

Visualforce& Apex

Page 6: Moving from Clicks to Code

What is Visualforce?

Tag based language (HTML, XML)

Display information

Page 7: Moving from Clicks to Code

What is Apex?

Object-oriented programming language (C#, Java)

Process Information

Page 8: Moving from Clicks to Code

Visualforce or Apex?

Page 9: Moving from Clicks to Code

Both!

Visualforce

Apex

Page 10: Moving from Clicks to Code

MVC Pattern?

Page 11: Moving from Clicks to Code

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

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

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

Developer Tools…

Page 15: Moving from Clicks to Code

Browser Editor

Small changes

Quick fixes

Troubleshooting

Code must be

error free to

save!

Page 16: Moving from Clicks to Code

Full Environment…

Force.com IDE– Eclipse

Imperfect code

saves locally

Also for

deployment

Page 17: Moving from Clicks to Code

Deployment

Tools– Change Sets (beta)

– Force.com IDE

– Force.com Migration Tool• Advanced Users

Production

Sandbox

Page 18: Moving from Clicks to Code

Governor Limits

Page 19: Moving from Clicks to Code

Governor Limits

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm

Page 20: Moving from Clicks to Code

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

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

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

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

Code Coverage

Page 25: Moving from Clicks to Code

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

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

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

How to Cover Custom Controllers?

Create instance class being tested

Invoke methods / properties

Use assert methods (Optional)

Page 29: Moving from Clicks to Code

How to Cover Triggers?

Perform DML operation

Use assert methods (optional)

Page 30: Moving from Clicks to Code

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

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

Apex Samples

Page 33: Moving from Clicks to Code

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

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

You Can Do It!

Adam Bataran Iron MountainSalesforce.com Boston User Group

Page 36: Moving from Clicks to Code

Final Thoughts

Page 37: Moving from Clicks to Code

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

Indent Your Code!

Page 39: Moving from Clicks to 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, …

Page 40: Moving from Clicks to 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 ;-)

Page 42: Moving from Clicks to Code

Questions& Answers

Page 43: Moving from Clicks to Code

Questions & Answers

Adam Bataran– Iron Mountain

– Salesforce.com Boston User Group

Andrés Pérez– Salesforce.com

Page 44: Moving from Clicks to Code

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

From Clicks To Code

Page 46: Moving 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