Object Sync for Salesforce Code Documentation

Object_Sync_Sf_Salesforce

Object_Sync_Sf_Salesforce class.

Table of Contents

$authorize_path  : string
Path for the Salesforce authorize URL
$callback_url  : string
Callback URL for the Salesforce API
$consumer_key  : string
Salesforce consumer key
$consumer_secret  : string
Salesforce consumer secret
$debug  : string
Whether the plugin is in debug mode
$file  : string
The main plugin file
$logging  : object
Object_Sync_Sf_Logging class
$login_credentials  : array<string|int, mixed>
Login credentials for the Salesforce API; comes from wp-config or from the plugin settings
$login_url  : string
Login URL for the Salesforce API
$option_prefix  : string
The plugin's prefix when saving options to the database
$options  : array<string|int, mixed>
API call options
$refresh_code  : int
API refresh return code
$response  : array<string|int, mixed>
API response from Salesforce
$rest_api_version  : string
REST API version for Salesforce
$schedulable_classes  : array<string|int, mixed>
Array of what classes in the plugin can be scheduled to occur with `wp_cron` events
$slug  : string
The plugin's slug so we can include it when necessary
$success_codes  : array<string|int, mixed>
API success return codes
$success_or_refresh_codes  : array<string|int, mixed>
API success or refresh return codes
$token_path  : string
Path for the Salesforce token URL
$version  : string
Current version of the plugin
$wordpress  : object
Object_Sync_Sf_WordPress class
__construct()  : mixed
Constructor for Salesforce class
analytics_api()  : object
Make a call to the Analytics API. Part of core API calls.
api_call()  : mixed
Make a call to the Salesforce REST API.
convert_id()  : string
Converts a 15-character case-sensitive Salesforce ID to 18-character case-insensitive ID. If input is not 15-characters, return input unaltered.
get_access_token()  : mixed
Get the access token.
get_api_endpoint()  : string
Get the API end point for a given type of the API.
get_api_versions()  : mixed
Get REST API versions available on this Salesforce organization This is not an authenticated call, so it would not be a helpful test
get_authorization_code()  : mixed
OAuth step 1: Redirect to Salesforce and request and authorization code.
get_deleted()  : mixed
Retrieves the list of individual objects that have been deleted within the given timespan for a specified object type.
get_identity()  : array<string|int, mixed>
Return the Salesforce identity, which is stored in a variable.
get_instance_url()  : mixed
Get the SF instance URL. Useful for linking to objects.
get_record_type_id_by_developer_name()  : string
Given a DeveloperName and SObject Name, return the SFID of the corresponding RecordType. DeveloperName doesn't change between Salesforce environments, so it's safer to rely on compared to SFID.
get_sobject_type()  : string
Given a Salesforce ID, return the corresponding SObject name. (Based on keyPrefix from object definition,
get_updated()  : array<string|int, mixed>
Return a list of SFIDs for the given object, which have been created or updated in the given timeframe. Part of core API calls.
is_authorized()  : mixed
Determine if this SF instance is fully configured.
list_resources()  : array<string|int, mixed>
Return a list of available resources for the configured API version. Part of core API calls.
object_create()  : array<string|int, mixed>
Create a new object of the given type. Part of core API calls.
object_delete()  : array<string|int, mixed>
Delete a Salesforce object. Part of core API calls
object_describe()  : array<string|int, mixed>
Retrieve all the metadata for an object. Part of core API calls.
object_read()  : object
Return a full loaded Salesforce object. Part of core API calls.
object_readby_external_id()  : object
Return a full loaded Salesforce object from External ID. Part of core API calls.
object_update()  : array<string|int, mixed>
Update an existing object. Part of core API calls.
object_upsert()  : array<string|int, mixed>
Create new records or update existing records.
objects()  : array<string|int, mixed>
Available objects and their metadata for your organization's data.
query()  : array<string|int, mixed>
Use SOQL to get objects based on query string. Part of core API calls.
request_token()  : mixed
OAuth step 2: Exchange an authorization code for an access token.
run_analytics_report()  : object
Run a specific Analytics report. Part of core API calls.
api_http_request()  : array<string|int, mixed>
Private helper to issue an SF API request.
get_refresh_token()  : mixed
Get refresh token.
http_request()  : array<string|int, mixed>
Make the HTTP request. Wrapper around curl().
refresh_token()  : mixed
Refresh access token based on the refresh token. Updates session variable.
set_access_token()  : mixed
Set the access token.
set_identity()  : mixed
Retrieve and store the Salesforce identity given an ID url.
set_instance_url()  : mixed
Set the SF instance URL.
set_refresh_token()  : mixed
Set refresh token.
cache_expiration()  : mixed
If there is a WordPress setting for how long to keep the cache, return it and set the object property Otherwise, return seconds in 24 hours.

Properties

$login_credentials

Login credentials for the Salesforce API; comes from wp-config or from the plugin settings

public array<string|int, mixed> $login_credentials

$schedulable_classes

Array of what classes in the plugin can be scheduled to occur with `wp_cron` events

public array<string|int, mixed> $schedulable_classes

Methods

analytics_api()

Make a call to the Analytics API. Part of core API calls.

public analytics_api(string $name, string $id[, string $route = '' ][, array<string|int, mixed> $params = array() ][, string $method = 'GET' ]) : object
Parameters
$name : string

Object type name, E.g., Report.

$id : string

Salesforce id of the object.

$route : string = ''

What comes after the ID? E.g. instances, ?includeDetails=True.

$params : array<string|int, mixed> = array()

Params to put with the request.

$method : string = 'GET'

GET or POST.

Return values
object

Object of the requested Salesforce object.

api_call()

Make a call to the Salesforce REST API.

public api_call(string $path[, array<string|int, mixed> $params = array() ][, string $method = 'GET' ][, array<string|int, mixed> $options = array() ][, string $type = 'rest' ]) : mixed
Parameters
$path : string

Path to resource.

$params : array<string|int, mixed> = array()

Parameters to provide.

$method : string = 'GET'

Method to initiate the call, such as GET or POST. Defaults to GET.

$options : array<string|int, mixed> = array()

Any method can supply options for the API call, and they'll be preserved as far as the curl request. They get merged with the class options.

$type : string = 'rest'

Type of call. Defaults to 'rest' - currently we don't support other types. Other exammple in Drupal is 'apexrest'.

Tags
throws
Object_Sync_Sf_Exception

The plugin's exception class.

Return values
mixed

The requested response.

convert_id()

Converts a 15-character case-sensitive Salesforce ID to 18-character case-insensitive ID. If input is not 15-characters, return input unaltered.

public static convert_id(string $sf_id_15) : string
Parameters
$sf_id_15 : string

15-character case-sensitive Salesforce ID.

Return values
string

18-character case-insensitive Salesforce ID

get_api_endpoint()

Get the API end point for a given type of the API.

public get_api_endpoint([string $api_type = 'rest' ]) : string
Parameters
$api_type : string = 'rest'

E.g., rest, partner, enterprise.

Return values
string

Complete URL endpoint for API access.

get_api_versions()

Get REST API versions available on this Salesforce organization This is not an authenticated call, so it would not be a helpful test

public get_api_versions() : mixed
Return values
mixed

get_authorization_code()

OAuth step 1: Redirect to Salesforce and request and authorization code.

public get_authorization_code() : mixed
Return values
mixed

get_deleted()

Retrieves the list of individual objects that have been deleted within the given timespan for a specified object type.

public get_deleted(string $type, string $start_date, string $end_date) : mixed
Parameters
$type : string

Object type name, E.g., Contact, Account.

$start_date : string

Start date to check for deleted objects (in ISO 8601 format).

$end_date : string

End date to check for deleted objects (in ISO 8601 format).

Return values
mixed

$result

get_identity()

Return the Salesforce identity, which is stored in a variable.

public get_identity() : array<string|int, mixed>
Return values
array<string|int, mixed>

Returns false if no identity has been stored.

get_instance_url()

Get the SF instance URL. Useful for linking to objects.

public get_instance_url() : mixed
Return values
mixed

get_record_type_id_by_developer_name()

Given a DeveloperName and SObject Name, return the SFID of the corresponding RecordType. DeveloperName doesn't change between Salesforce environments, so it's safer to rely on compared to SFID.

public get_record_type_id_by_developer_name(string $name, string $devname[, bool $reset = false ]) : string
Parameters
$name : string

Object type name, E.g., Contact, Account.

$devname : string

RecordType DeveloperName, e.g. Donation, Membership, etc.

$reset : bool = false

whether this is resetting the cache.

Return values
string

SFID The Salesforce ID of the given Record Type, or null.

get_updated()

Return a list of SFIDs for the given object, which have been created or updated in the given timeframe. Part of core API calls.

public get_updated(string $type[, int $start = null ][, int $end = null ]) : array<string|int, mixed>
Parameters
$type : string

Object type name, E.g., Contact, Account.

$start : int = null

unix timestamp for older timeframe for updates. Defaults to "-29 days" if empty.

$end : int = null

unix timestamp for end of timeframe for updates. Defaults to now if empty.

Tags
see
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_getupdated.htm
Return values
array<string|int, mixed>

return array has 2 indexes: "ids": a list of SFIDs of those records which have been created or updated in the given timeframe. "latestDateCovered": ISO 8601 format timestamp (UTC) of the last date covered in the request.

list_resources()

Return a list of available resources for the configured API version. Part of core API calls.

public list_resources() : array<string|int, mixed>
Return values
array<string|int, mixed>

Associative array keyed by name with a URI value.

object_create()

Create a new object of the given type. Part of core API calls.

public object_create(string $name, array<string|int, mixed> $params) : array<string|int, mixed>
Parameters
$name : string

Object type name, E.g., Contact, Account, etc.

$params : array<string|int, mixed>

Values of the fields to set for the object.

Return values
array<string|int, mixed>

json: {"id":"00190000001pPvHAAU","success":true,"errors":[]} code: 201 data: "id" : "00190000001pPvHAAU", "success" : true "errors" : [ ], from_cache: cached: is_redo:

object_delete()

Delete a Salesforce object. Part of core API calls

public object_delete(string $name, string $id) : array<string|int, mixed>
Parameters
$name : string

Object type name, E.g., Contact, Account.

$id : string

Salesforce id of the object.

Return values
array<string|int, mixed>

object_describe()

Retrieve all the metadata for an object. Part of core API calls.

public object_describe(string $name[, bool $reset = false ]) : array<string|int, mixed>
Parameters
$name : string

Object type name, E.g., Contact, Account, etc.

$reset : bool = false

Whether to reset the cache and retrieve a fresh version from Salesforce.

Return values
array<string|int, mixed>

All the metadata for an object, including information about each field, URLs, and child relationships.

object_read()

Return a full loaded Salesforce object. Part of core API calls.

public object_read(string $name, string $id[, array<string|int, mixed> $options = array() ]) : object
Parameters
$name : string

Object type name, E.g., Contact, Account.

$id : string

Salesforce id of the object.

$options : array<string|int, mixed> = array()

Optional options to pass to the API call.

Return values
object

Object of the requested Salesforce object.

object_readby_external_id()

Return a full loaded Salesforce object from External ID. Part of core API calls.

public object_readby_external_id(string $name, string $field, string $value[, array<string|int, mixed> $options = array() ]) : object
Parameters
$name : string

Object type name, E.g., Contact, Account.

$field : string

Salesforce external id field name.

$value : string

Value of external id.

$options : array<string|int, mixed> = array()

Optional options to pass to the API call.

Return values
object

Object of the requested Salesforce object.

object_update()

Update an existing object. Part of core API calls.

public object_update(string $name, string $id, array<string|int, mixed> $params) : array<string|int, mixed>
Parameters
$name : string

Object type name, E.g., Contact, Account.

$id : string

Salesforce id of the object.

$params : array<string|int, mixed>

Values of the fields to set for the object.

Return values
array<string|int, mixed>

json: {"success":true,"body":""} code: 204 data: success: 1 body: from_cache: cached: is_redo:

object_upsert()

Create new records or update existing records.

public object_upsert(string $name, string $key, string $value, array<string|int, mixed> $params) : array<string|int, mixed>

The new records or updated records are based on the value of the specified field. If the value is not unique, REST API returns a 300 response with the list of matching records. Part of core API calls.

Parameters
$name : string

Object type name, E.g., Contact, Account.

$key : string

The field to check if this record should be created or updated.

$value : string

The value for this record of the field specified for $key.

$params : array<string|int, mixed>

Values of the fields to set for the object.

Return values
array<string|int, mixed>

json: {"id":"00190000001pPvHAAU","success":true,"errors":[]} code: 201 data: "id" : "00190000001pPvHAAU", "success" : true "errors" : [ ], from_cache: cached: is_redo:

objects()

Available objects and their metadata for your organization's data.

public objects([array<string|int, mixed> $conditions = array('updateable' => true, 'triggerable' => true) ][, bool $reset = false ]) : array<string|int, mixed>

part of core API calls. this call does require authentication, and the basic url it becomes is like this: https://instance.salesforce.com/services/data/v#.0/sobjects note: updateable is really how the api spells it

Parameters
$conditions : array<string|int, mixed> = array('updateable' => true, 'triggerable' => true)

Associative array of filters to apply to the returned objects. Filters are applied after the list is returned from Salesforce.

$reset : bool = false

Whether to reset the cache and retrieve a fresh version from Salesforce.

Return values
array<string|int, mixed>

Available objects and metadata.

query()

Use SOQL to get objects based on query string. Part of core API calls.

public query(string $query[, array<string|int, mixed> $options = array() ][, bool $all = false ][, bool $explain = false ]) : array<string|int, mixed>
Parameters
$query : string

The SOQL query.

$options : array<string|int, mixed> = array()

Allow for the query to have options based on what the user needs from it, ie caching, read/write, etc.

$all : bool = false

Whether this should get all results for the query.

$explain : bool = false

If set, Salesforce will return feedback on the query performance.

Return values
array<string|int, mixed>

Array of Salesforce objects that match the query.

request_token()

OAuth step 2: Exchange an authorization code for an access token.

public request_token(string $code) : mixed
Parameters
$code : string

Code from Salesforce.

Tags
throws
Object_Sync_Sf_Exception

The plugin's exception class.

Return values
mixed

run_analytics_report()

Run a specific Analytics report. Part of core API calls.

public run_analytics_report(string $id[, bool $async = true ][, bool $clear_cache = false ][, array<string|int, mixed> $params = array() ][, string $method = 'GET' ][, string $report_cache_expiration = '' ][, bool $cache_instance = true ][, string $instance_cache_expiration = '' ]) : object
Parameters
$id : string

Salesforce id of the object.

$async : bool = true

Whether the report is asynchronous.

$clear_cache : bool = false

Whether the cache is being cleared.

$params : array<string|int, mixed> = array()

Params to put with the request.

$method : string = 'GET'

GET or POST.

$report_cache_expiration : string = ''

How long to keep the report's cache result around for.

$cache_instance : bool = true

Whether to cache the instance results.

$instance_cache_expiration : string = ''

How long to keep the instance's cache result around for.

Return values
object

Object of the requested Salesforce object.

api_http_request()

Private helper to issue an SF API request.

protected api_http_request(string $path, array<string|int, mixed> $params, string $method[, array<string|int, mixed> $options = array() ][, string $type = 'rest' ]) : array<string|int, mixed>

This method is the only place where we read to or write from the cache

Parameters
$path : string

Path to resource.

$params : array<string|int, mixed>

Parameters to provide.

$method : string

Method to initiate the call, such as GET or POST. Defaults to GET.

$options : array<string|int, mixed> = array()

This is the options array from the api_call method. This is where it gets merged with $this->options.

$type : string = 'rest'

Type of call. Defaults to 'rest' - currently we don't support other types. Other exammple in Drupal is 'apexrest'.

Return values
array<string|int, mixed>

The requested data.

http_request()

Make the HTTP request. Wrapper around curl().

protected http_request(string $url, array<string|int, mixed> $data[, array<string|int, mixed> $headers = array() ][, string $method = 'GET' ][, array<string|int, mixed> $options = array() ]) : array<string|int, mixed>
Parameters
$url : string

Path to make request from.

$data : array<string|int, mixed>

The request body.

$headers : array<string|int, mixed> = array()

Request headers to send as name => value.

$method : string = 'GET'

Method to initiate the call, such as GET or POST. Defaults to GET.

$options : array<string|int, mixed> = array()

This is the options array from the api_http_request method.

Return values
array<string|int, mixed>

Salesforce response object.

refresh_token()

Refresh access token based on the refresh token. Updates session variable.

protected refresh_token() : mixed

Todo: figure out how to do this as part of the schedule class This is a scheduleable class and so we could add a method from this class to run every 24 hours, but it's unclear to me that we need it. salesforce seems to refresh itself as it needs to. but it could be a performance boost to do it at scheduleable intervals instead.

Tags
throws
Object_Sync_Sf_Exception

The plugin's exception class.

Return values
mixed

set_access_token()

Set the access token.

protected set_access_token(string $token) : mixed

It is stored in session.

Parameters
$token : string

Access token from Salesforce.

Return values
mixed

set_instance_url()

Set the SF instance URL.

protected set_instance_url(string $url) : mixed
Parameters
$url : string

URL to set.

Return values
mixed

set_refresh_token()

Set refresh token.

protected set_refresh_token(string $token) : mixed
Parameters
$token : string

Refresh token from Salesforce.

Return values
mixed

cache_expiration()

If there is a WordPress setting for how long to keep the cache, return it and set the object property Otherwise, return seconds in 24 hours.

private cache_expiration() : mixed
Return values
mixed

Search results