Webinar: Data Models,
Relationships and SOQL
April 8, 2014
Rob Woodward
Platform Solution Engineer
@robw116
Safe Harbor
Safe harbor statement under the Private Securities Litigation Reform Act of 1995:
This presentation may contai...
Agenda
Data Model & Relationships
Comparing Force.com with Relational DBMS
Relationship Types & the Predefined Join
Relati...
Assumptions
 A basic understanding of the Force.com Platform
including:
– Creating Custom Objects
– Adding Custom Fields
...
Data Model and Relationships
Relationships and SOQL
Agenda
Data Model and the Force.com Platform
 sObject:
– Table-like data structure
• Records
• Fields
– Extensible
– Queryable/U...
Standard Data Model
 Standard Objects
– Account
– Contact
– Lead
– Opportunity
– Case
– …
 Standard Fields
– Id
– Name
–...
Extensible Data Model
 Custom Objects
– Workshop__c
– Room__c
– …
 Custom Fields
– Status__c
– Type__c
– Start_Time__c
–...
Relationships: The Predefined Join
 RDBMS
– Join at runtime
with SQL or
view
 Force.com
– Predefined join
at design-time...
Master-DetailLookup
Relationship Types
NeverOptional
Cascade
Clear
Field/Block/Cascade*
Nullability
Delete Behavior
Child ...
Demo Use Case:
– Community Centre
– Workshops and Rooms
Data Model and Relationships
Relationships and SOQL
Agenda
SOQL
 Salesforce Object Query Language
 SQL-like syntax
 Queries the Force.com Object Layer
 Used in:
– Apex
– Develop...
From SQL to SOQL
 At first may look familiar
 Important differences
 Learn the differences
 Use good data design pract...
From SQL to SOQL: The Familiar Bits
 Table-like structure
 Similar query syntax
 Indexed
 Transactional
 Triggers
SEL...
From SQL to SOQL: Immediate Differences
 No select *
 No views
 SOQL is read-only
 Limited indexes
 Object-relational...
From SQL to SOQL: Differences To Learn
 sObjects are not actually tables – multi-tenant
environment
 Relationship metada...
The __c and __r Suffixes
Room__c
Workshop__c
Id
Id
Room__c
Room__r
Workshops__r Type:
List<Workshop__c>
Type: Id
Type: Roo...
Relationship Query: Child to Parent
SELECT Id, Name, Room__c,
Room__r.Id,
Room__r.Capacity__c
FROM Workshop__c
WHERE Statu...
Relationship Query: Parent to Child
SELECT Id, Name,
(SELECT Id, Status__c
FROM Workshops__r)
FROM Room__c
WHERE Capacity_...
Querying for Intersection
Select Id, Name,
Room__r.Name,
Room__r.Capacity__c
FROM Workshop__c
WHERE
Room__r.Capacity__c > ...
Aggregate Queries
SELECT
COUNT(Id) rmCount,
MAX(Capacity__c) maxRmCap,
Configuration__c
FROM Room__c
GROUP BY Configuratio...
Demo Use Case:
– Find a tally of empty spaces
being held for workshops that
are not actively enrolling
delegates
Recap
 Data Model &
Relationships
– Much that looks similar,
but
– Many important
differences
– Predefined Join
– Relatio...
Read More
 Article: From SQL to SOQL http://bit.ly/sql2soql
 SOQL-SOSL Guide http://bit.ly/soqlsosl
 Sharing http://bit...
Next Webinar:
May 15: Intro to building Mobile Apps with
Salesforce1 Platform – No code required
Upcoming SlideShare
Loading in …5
×

Salesforce1 Platform: Data Model, Relationships and Queries Webinar

2,529 views

Published on

In this webinar we will explore customizing your Salesforce1 data model. Different relationship types and utilisation in queries or in your custom Apex Code will be the main themes we will focus on. If you’ve ever wondered, “Lookup or Master Detail?”, or if even that question makes you scratch your head, this webinar is for you.

Key Takeaways
Tools for creating relationships
Key distinctions between Lookup and Master Detail relationships
Thinking beyond the database with relationships
Common query and Apex patterns when using relationship data

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,529
On SlideShare
0
From Embeds
0
Number of Embeds
1,195
Actions
Shares
0
Downloads
122
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Salesforce1 Platform: Data Model, Relationships and Queries Webinar

  1. 1. Webinar: Data Models, Relationships and SOQL April 8, 2014
  2. 2. Rob Woodward Platform Solution Engineer @robw116
  3. 3. 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 any litigation, risks associated with completed and any 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 and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These 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.
  4. 4. Agenda Data Model & Relationships Comparing Force.com with Relational DBMS Relationship Types & the Predefined Join Relationships & SOQL SOQL vs SQL Relationship Queries
  5. 5. Assumptions  A basic understanding of the Force.com Platform including: – Creating Custom Objects – Adding Custom Fields – Navigating the UI  Knowledge of relational database concepts – Tables – Primary/Foreign Keys – Joins
  6. 6. Data Model and Relationships Relationships and SOQL Agenda
  7. 7. Data Model and the Force.com Platform  sObject: – Table-like data structure • Records • Fields – Extensible – Queryable/Updatable – Relationships  Automatic Features: – User Interface – Security • CRUD • Field-level • Record-level (ACL) – REST & SOAP APIs
  8. 8. Standard Data Model  Standard Objects – Account – Contact – Lead – Opportunity – Case – …  Standard Fields – Id – Name – CreatedBy/Date – LastModifiedBy/Date – OwnerId – IsDeleted – …
  9. 9. Extensible Data Model  Custom Objects – Workshop__c – Room__c – …  Custom Fields – Status__c – Type__c – Start_Time__c – End_Time__c – …
  10. 10. Relationships: The Predefined Join  RDBMS – Join at runtime with SQL or view  Force.com – Predefined join at design-time – Similar to integrity constraints
  11. 11. Master-DetailLookup Relationship Types NeverOptional Cascade Clear Field/Block/Cascade* Nullability Delete Behavior Child Inherits from ParentIndependent Parent/Child 225 Record Sharing Access Max Allowed Fields
  12. 12. Demo Use Case: – Community Centre – Workshops and Rooms
  13. 13. Data Model and Relationships Relationships and SOQL Agenda
  14. 14. SOQL  Salesforce Object Query Language  SQL-like syntax  Queries the Force.com Object Layer  Used in: – Apex – Developer Tools (Developer Console, Eclipse, Workbench, …) – API (REST, SOAP, Bulk, …)
  15. 15. From SQL to SOQL  At first may look familiar  Important differences  Learn the differences  Use good data design practices
  16. 16. From SQL to SOQL: The Familiar Bits  Table-like structure  Similar query syntax  Indexed  Transactional  Triggers SELECT Id, Name, Capacity__c FROM Room__c WHERE Capacity__c > 10
  17. 17. From SQL to SOQL: Immediate Differences  No select *  No views  SOQL is read-only  Limited indexes  Object-relational mapping is automatic  Schema changes protected
  18. 18. From SQL to SOQL: Differences To Learn  sObjects are not actually tables – multi-tenant environment  Relationship metadata – Management of referential integrity – Predefines joins – Relationship query syntax  Query usage explicitly metered – API Batch Limits – Apex Governor Limits
  19. 19. The __c and __r Suffixes Room__c Workshop__c Id Id Room__c Room__r Workshops__r Type: List<Workshop__c> Type: Id Type: Room__c 1-M
  20. 20. Relationship Query: Child to Parent SELECT Id, Name, Room__c, Room__r.Id, Room__r.Capacity__c FROM Workshop__c WHERE Status__c = ’Open’ [ { "Id": "a0145000000aBf4AAE", "Name": "Yoga for Beginners", "Room__c": "a00vn000000dU3dAAE", "Room__r": { "Id": "a00vn000000dU3dAAE", "Capacity__c": 10 } }, { "Id": "a0145000000aBf4AAE", "Name": "Yoga for Beginners", "Room__c": "", "Room__r": "" }, ... ]
  21. 21. Relationship Query: Parent to Child SELECT Id, Name, (SELECT Id, Status__c FROM Workshops__r) FROM Room__c WHERE Capacity__c > 10 [ { "Id": "a00vn000000dU3dAAE", "Name": "Salon 1 West", "Workshops__r": [ { "Id": "a0145000000aBf4AAE", "Status__c": "Open" }, { "Id": "a0145000000aBd4AAE", "Status__c": "Full" } ] }, ... ]
  22. 22. Querying for Intersection Select Id, Name, Room__r.Name, Room__r.Capacity__c FROM Workshop__c WHERE Room__r.Capacity__c > 8 [ { "Id": "a0145000000aBf4AAE", "Name": "Yoga for Beginners", "Room__c": "a00vn000000dU3dAAE", "Room__r": { "Id": "a00vn000000dU3dAAE", "Capacity__c": 10 } }, {...}, ... ]
  23. 23. Aggregate Queries SELECT COUNT(Id) rmCount, MAX(Capacity__c) maxRmCap, Configuration__c FROM Room__c GROUP BY Configuration__c [ { "rmCount": 4, "maxRmCap": 6, "Configuration__c": "Classroom" }, { "rmCount": 2, "maxRmCap": 10, "Configuration__c": "Theatre" }, ... ]
  24. 24. Demo Use Case: – Find a tally of empty spaces being held for workshops that are not actively enrolling delegates
  25. 25. Recap  Data Model & Relationships – Much that looks similar, but – Many important differences – Predefined Join – Relationship Types  Relationships & SOQL – SOQL has relations but is not “relational” – Limits cannot be ignored – Good design principles still apply but check your assumptions
  26. 26. Read More  Article: From SQL to SOQL http://bit.ly/sql2soql  SOQL-SOSL Guide http://bit.ly/soqlsosl  Sharing http://bit.ly/sharingarch  Limits http://bit.ly/apexgovlim  Multi-Tenant Architecture http://bit.ly/sfmultiten
  27. 27. Next Webinar: May 15: Intro to building Mobile Apps with Salesforce1 Platform – No code required

×