sfdc data models for pros - simplifying the complexities

46
SFDC Data Models for Pros - Simplifying The Complexities Baruch Oxman R&D Manager, Implisit @implisithq, @baruchoxman

Upload: baruch-oxman

Post on 22-Jan-2018

3.553 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: SFDC Data Models For Pros - Simplifying The Complexities

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

Baruch OxmanR&D Manager

Page 3: SFDC Data Models For Pros - Simplifying The Complexities

Implisit – Intro & Motivation

Page 4: SFDC Data Models For Pros - Simplifying The Complexities

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

Connected App UI

Page 6: SFDC Data Models For Pros - Simplifying The Complexities

In this session

Object Relationship

Types

Polymorphic

Relations

Security &

PermissionsDeleted RecordsMetadata

History Records

Page 7: SFDC Data Models For Pros - Simplifying The Complexities

Objects Relationships

Page 8: SFDC Data Models For Pros - Simplifying The Complexities

• Master-Detail

• One-to-Many

• Lookup

• Many-to-Many

• Polymorphic relations

Object Relations

Page 9: SFDC Data Models For Pros - Simplifying The Complexities

• 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

One-to-Many

Opportunity

Opportunity

CompetitorOpportunity

Competitor

Opportunity

Competitor

Page 11: SFDC Data Models For Pros - Simplifying The Complexities

Lookup

Account

Contact Contact Contact

Page 12: SFDC Data Models For Pros - Simplifying The Complexities

Many-to-Many

Contact Lead

Campaign Campaign

Task Task

Contact Contact

Page 13: SFDC Data Models For Pros - Simplifying The Complexities

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

Tasks & Events

Page 15: SFDC Data Models For Pros - Simplifying The Complexities

Polymorphic Relations

Page 16: SFDC Data Models For Pros - Simplifying The Complexities

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

Challenge

Page 18: SFDC Data Models For Pros - Simplifying The Complexities

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

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

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

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

{ '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

SELECT Id, Who.Name FROM Task WHERE Who.Type = ‘Lead’

TYPE qualifier

Page 24: SFDC Data Models For Pros - Simplifying The Complexities

History records

Page 25: SFDC Data Models For Pros - Simplifying The Complexities

Motivation

Page 26: SFDC Data Models For Pros - Simplifying The Complexities

History records

Accounts

Cases

Products

Leads Contacts

Opportunities Contracts

Assets and more…

Page 27: SFDC Data Models For Pros - Simplifying The Complexities

• 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

{

"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

• 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

{

"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

Security & Permissions

Page 32: SFDC Data Models For Pros - Simplifying The Complexities

Security & Permissions

Objects Fields

Records Relations

Page 33: SFDC Data Models For Pros - Simplifying The Complexities

Objects Metadata

Page 34: SFDC Data Models For Pros - Simplifying The Complexities

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

(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

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

[(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

# 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

(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

Tracking deleted records

Page 41: SFDC Data Models For Pros - Simplifying The Complexities

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

Summary

Object Relationship

Types

Polymorphic

Relations

Security &

PermissionsDeleted RecordsMetadata

History Records

Page 44: SFDC Data Models For Pros - Simplifying The Complexities
Page 45: SFDC Data Models For Pros - Simplifying The Complexities
Page 46: SFDC Data Models For Pros - Simplifying The Complexities

Thank you