![Page 1: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/1.jpg)
SFDC Data Models for Pros -
Simplifying The Complexities
Baruch Oxman
R&D Manager, Implisit
@implisithq, @baruchoxman
![Page 2: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/2.jpg)
Baruch OxmanR&D Manager
![Page 3: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/3.jpg)
Implisit – Intro & Motivation
![Page 4: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/4.jpg)
Implisit – Intro & Motivation
Data Entry, Insights
& Analytics
Standalone UIReal-time SFDC
Data interaction
Offline SFDC Data
Processing
![Page 5: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/5.jpg)
Connected App UI
![Page 6: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/6.jpg)
In this session
Object Relationship
Types
Polymorphic
Relations
Security &
PermissionsDeleted RecordsMetadata
History Records
![Page 7: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/7.jpg)
Objects Relationships
![Page 8: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/8.jpg)
• Master-Detail
• One-to-Many
• Lookup
• Many-to-Many
• Polymorphic relations
Object Relations
![Page 9: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/9.jpg)
• Closely linked objects
• Detail extends the master
• Owner of master owns the child record
• Example:
• Custom “AccountDetails” object, extending Account
Master-Detail Relationship
Master
Detail
![Page 10: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/10.jpg)
One-to-Many
Opportunity
Opportunity
CompetitorOpportunity
Competitor
Opportunity
Competitor
![Page 11: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/11.jpg)
Lookup
Account
Contact Contact Contact
![Page 12: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/12.jpg)
Many-to-Many
Contact Lead
Campaign Campaign
Task Task
Contact Contact
![Page 13: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/13.jpg)
Many-to-Many
CampaignCampaign Contact Contact
Campaign
MemberCampaign
Member
Campaign
MemberTaskRelation TaskRelation TaskRelation
Task TaskLeadContact
![Page 14: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/14.jpg)
Tasks & Events
![Page 15: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/15.jpg)
Polymorphic Relations
![Page 16: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/16.jpg)
Polymorphic Relations
Task Attachment
Contact/LeadOpportunity/Case/Account Opportunity/Case/Account/Contact/Lead/…
WhatId WhoId ParentId
![Page 17: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/17.jpg)
Challenge
![Page 18: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/18.jpg)
SELECT Subject, Account.Name, Who.Company FROM Task
Error: “No such column 'Company' on entity 'Name'…”
Naïve Approach
![Page 19: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/19.jpg)
1.SELECT Subject, Account.Name, WhoId FROM Task
2.SELECT Company FROM Lead WHERE Id IN <WhoId list from previous query>
1st option: 2 SOQL queries
![Page 20: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/20.jpg)
SELECT Subject, Account.Name,
TYPEOF Who
WHEN Lead THEN Company
END
FROM Task
• Developer preview, to enable - contact Salesforce
2nd option: TYPEOF
![Page 21: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/21.jpg)
SELECT Id, Company,
(SELECT Id
FROM Tasks
WHERE <tasks filtering condition>)
FROM Lead
Nested SOQL Query
![Page 22: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/22.jpg)
{ 'totalSize': 2,
'records': [
{'Company': ‘Salesforce.com', u'Tasks': None, u'Id': u'00Qd0000007Q36GEAS'},
{'Company': ‘Implisit',
'Tasks': {'totalSize': 1, u'records': [{'Id': u'00Ti000000zM7rLEAS'}]},
'Id': u'00Qd0000007Q36GEAS'}
]}
Nested SOQL Query - result
![Page 23: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/23.jpg)
SELECT Id, Who.Name FROM Task WHERE Who.Type = ‘Lead’
TYPE qualifier
![Page 24: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/24.jpg)
History records
![Page 25: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/25.jpg)
Motivation
![Page 26: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/26.jpg)
History records
Accounts
Cases
Products
Leads Contacts
Opportunities Contracts
Assets and more…
![Page 27: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/27.jpg)
• Field Name
• Old Value
• New Value
• Id (AccountId / OpportunityId / ContactId / …)
• Who changed it and when ?
• Read-only records
Structure
![Page 28: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/28.jpg)
{
"Id" : "017200000GScFz0AQF",
"Field" : "StageName",
"OldValue" : "Intro",
"NewValue" : "Closed Lost",
"OpportunityId" : "0062000000W1QT6AAN",
"CreatedById" : "00520000003KQCNAA4",
"CreatedDate" : "2014-02-24T09:39:04.000+0000",
}
OpportunityFieldHistory record - example
![Page 29: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/29.jpg)
• Monitoring a subset of fields:
• Amount
• Probability
• Stage
• Close Date
• Few more…
• Each record contains the values for all these fields
• Useful for pipeline snapshots
OpportunityHistory
![Page 30: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/30.jpg)
{
"Id" : "00820000014EWPlAAO",
"Amount" : 5280.0,
"CloseDate" : "2014-12-31",
"ExpectedRevenue" : 5280.0,
"ForecastCategory" : "Closed",
"Probability" : 100.0,
"StageName" : "Closed Won",
"OpportunityId" : "0062000000W0TMNAA3",
"SystemModstamp" : "2015-01-22T08:41:32.000+0000",
"CreatedById" : "00520000003KQCNAA4",
"CreatedDate" : "2015-01-22T08:41:32.000+0000",
}
OpportunityHistory record - example
![Page 31: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/31.jpg)
Security & Permissions
![Page 32: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/32.jpg)
Security & Permissions
Objects Fields
Records Relations
![Page 33: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/33.jpg)
Objects Metadata
![Page 34: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/34.jpg)
from suds.client import Client
…
soap_api = Client(wsdl_url)
describe_global_res = soap_api.service.describeGlobal()
supported_obj_names = [sobject.name for describe_global_res['sobjects']]
describeGlobal() - list supported objects
![Page 35: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/35.jpg)
(DescribeGlobalSObjectResult){
activateable = False
createable = True
custom = False
customSetting = False
deletable = True
deprecatedAndHidden = False
feedEnabled = True
keyPrefix = "001"
label = "Account"
labelPlural = "Accounts"
layoutable = True
mergeable = True
name = "Account"
queryable = True
replicateable = True
retrieveable = True
searchable = True
triggerable = True
undeletable = True
updateable = True
},
describeGlobal() – output example
![Page 36: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/36.jpg)
get_desc_url = "https://na15.salesforce.com/services/data/v32/sobjects/Lead/describe"
desc_json = json.loads(perform_request(get_desc_url))
lead_fields_metadata = desc_json['fields']
// get all available field names
lead_field_names = [field['name'] for field in lead_fields_metadata]
Describe
![Page 37: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/37.jpg)
[(DescribeSObjectResult){
…
activateable = False
keyPrefix = "00Q"
label = "Lead"
labelPlural = "Leads"
layoutable = True
mergeable = True
name = "Lead"
queryable = True
replicateable = True
retrieveable = True
searchLayoutable = True
searchable = True
triggerable = True
undeletable = True
updateable = True
….
}]
Describe - output
![Page 38: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/38.jpg)
# get all picklist values for a field
def get_active_picklist_values(obj_fields_metadata, field_name):
for field_metadata in fields_metadata:
if field_metadata['name'] != field_name:
continue
picklist_values = field_metadata.get('picklistValues', [])
return [ picklist_val['value']
for picklist_val in picklist_values
if picklist_val['active'] ]
Describe
![Page 39: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/39.jpg)
(Field){
autoNumber = False
byteLength = 120
calculated = False
caseSensitive = False
createable = True
custom = False
defaultedOnCreate = False
deprecatedAndHidden = False
digits = 0
filterable = True
groupable = True
idLookup = False
label = "Lead Source"
length = 40
name = "LeadSource"
nameField = False
namePointing = False
nillable = True
permissionable = True
picklistValues[] =
(PicklistEntry){
active = True
defaultValue = False
label = "Advertisement"
value = "Advertisement"
},
...
precision = 0
restrictedPicklist = False
scale = 0
soapType = "xsd:string"
sortable = True
type = "picklist"
unique = False
updateable = True
},
Describe – single field output
![Page 40: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/40.jpg)
Tracking deleted records
![Page 41: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/41.jpg)
getDeleted()
• SOAP
• Single API call
queryAll(isDeleted = True)
• REST
• Multiple API calls
• Recycle Bin objects
Tracking deleted records
![Page 42: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/42.jpg)
Summary
Object Relationship
Types
Polymorphic
Relations
Security &
PermissionsDeleted RecordsMetadata
History Records
![Page 43: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/43.jpg)
• Object relationships types
• SFDC Sales Objects relationships diagram
• describeGlobal, describeSObject
• SFDC Task & Event objects
• SOQL Polymorphism
• Understanding Polymorphic Keys and
Relationships
• Polymorphic Lookups
• TYPEOF
Additional Resources
![Page 44: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/44.jpg)
![Page 45: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/45.jpg)
![Page 46: SFDC Data Models For Pros - Simplifying The Complexities](https://reader034.vdocuments.us/reader034/viewer/2022050613/58a455f71a28ab55068b5fa5/html5/thumbnails/46.jpg)
Thank you