Upload
salesforce-developers
View
403
Download
0
Tags:
Embed Size (px)
Citation preview
Apex Nirvana
Dan Appleman, Full Circle CRM, CTO
Author: “Advanced Apex Programming for Salesforce.com and Force.com”
@danappleman
Embracing Governor Limits
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
product or service availability, 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, new products and services, 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 l itigation, 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-Q for the most recent fiscal quarter ended July 31, 2012. This
documents and others containing important disclosures 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 presentations, 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.
Coding is Fun
Where do we come from?
What makes it fun?
This ol’ Programmer
1976: PDP11/45 - 256KB (8k/user)
1981: PC – 16K-256KB
1986: Mac Plus 1MB
1991: x486 – 64MB
2000: PIII – 256-512MB
Smartphone – 512MB – 1GB
Desktop computer – 16GB+
Two rules….
Rule #1 to Live By
Design First, Code Later. Limits are a first order factor in design
Rule #2 to Live By
There is no code
but bulk code
Challenge:
Match incoming leads to accounts by comparing
Email address to account website domain
Leads with Email domain
Matching accounts
Best match Black box
Cost N script lines * leads *
matching accounts/lead
To Much To Like
For each lead
Pull the domain from the Email address
Add to dynamic query string for accounts using ‘LIKE’ on the website field
Database.query ( ‘ Select Id, …. , from Account where website like ‘%xyz.com’ or …. ‘)
Run through black box
Update leads
Logic issues: LIKE isn’t reliable.
Mycompany.com, yourcompany.com matches %company.com
Fails for subdirectories: mysite.com/default.html
Limit issues:
Script lines?
Heap?
SOQL complexity?
Non-Selective query?
Captures extra accounts that need to be
filtered
= more script lines, more heap usage
Scripts and Heaps Account
Custom field
Domain__c
Account
Insert/update
trigger
For each lead
Pull the domain from the Email address and add to Set
[Select id, …, from Account where Domain__c in :theset]
Build Map from lead ID to list of accounts (possible Group By query)
Run through black box
Update leads
No wasted accounts captured
No extra filtering
Limit issues:
Script lines?
Heap?
SOQL complexity?
Non-Selective query?
Into the Future
For each lead insert trigger
Future call – pass lead IDs as parameters
Easy way to get more limits,
But look at the cost
For each lead
Pull the domain from the Email address and add to Set
[Select id, …, from Account where Domain__c in :theset]
Build Map from lead ID to list of accounts (possible Group By query)
Run through black box
Update leads
Limit issues:
Future calls
Script lines?
Heap?
SOQL complexity?
Non-Selective query?
B to C – Queue & Batch
Scheduled batch
Query leads where Match_Pending__c
For each lead
Pull the domain from the Email address and add to Set
[Select id, …, from Account where Domain__c in :theset]
Build Map from lead ID to list of accounts (possible Group By query)
Run through black box
Update leads
Imagine > 100K leads
And > 100K person accounts
Lead
Custom field
MatchPending__c
Ok - If you use custom indexes
(which are also limited)
Limit issues:
Script lines?
Heap?
SOQL complexity?
Non-Selective query?
B to C – In Reverse
Scheduled batch
Query all accounts with Domain__c, group by Domain__c
Build set of domains
Query all leads with domain (custom field / formula field?) that aren’t yet assigned
Build Map from lead ID to list of matching accounts
Run through black box
Update leads
Imagine > 100K leads
And > 100K person accounts
Ok with indexed custom field,
Or small # of leads
Or if date filter is ok
Limit issues:
Script lines?
Heap?
SOQL complexity?
Non-Selective query?
Custom Custom Index
Ok with managed apps
DomainIndexer__c
Domain__c
External/unique
Account
Lookup
DomainIndexer__c
For each lead
Pull the domain from the Email address and add to Set
[Select id, (Select ID from Accounts), from DomainIndexer__c where Domain__c in :theset]
Build Map from lead ID to list of accounts by way of DomainIndexer objects
Run through black box
Update leads
Limit issues:
Script lines?
Heap?
SOQL complexity?
Non-Selective query?
Custom object count?
Which Design is Best?
Which Design is Best?
That’s not the point
Choosing among multiple designs results in better solutions than
coding and iterating
Considering limits from the start makes you a better developer.
Solving limit issues at design time means you may never see a limit
issue.
Conclusion
• Limits are fun!
• Design first!
• There is no code but bulk code!
Next Steps
Question for chatter – tell us about a time you
overcame a limit issue.
Stop by and chat at the Full Circle CRM booth
btw… we’re hiring
www.AdvancedApex.com
No question?
Tell us about your favorite way to overcome a particular limit.
AdvancedApex.com