# Create, Read and Update data on SalesForce
Before starting with this guide, make sure you check how the custom interactive works in creating a custom interactive section to understand the application workflow. To create, update, or read SalesForce data, we use Ti.App
to execute various actions.
# Creating new values
To create a new value on SFDC, you will need to use sendStatsFromHTML
event with fireEvent
function with an event called event_redirect_createSFDC
. Check here to see all the params this event supports.
Example:
const fieldsCustomObject = {
objectType: 'customObject__c',
CustomObject_Name__c: 'Sample Value',
CustomObject_Use__c: 'Sample Value',
}
Ti.App.fireEvent('sendStatsFromHTML', {
event_name: 'event_redirect_createSFDC',
event_params: fieldsCustomObject,
})
NOTE
When this event is fired, if the device is online, create/update calls are fired as soon as possible. If the device is not online, these calls are saved and gets synced on the first online presence.
# Updating values
To update an existing value on SFDC, you will need to use sendStatsFromHTML
event with fireEvent
function with an event called event_redirect_updateSFDC
. Check here to see all the params this event supports.
event_redirect_updateSFDC
requires an id parameter value of an existing customobject entry to update.
Example:
const fieldsCustomObject = {
Id: SFDC_ID_HERE,
objectType: 'customObject__c',
CustomObject_Name__c: 'Sample Value',
CustomObject_Use__c: 'Sample Value',
}
Ti.App.fireEvent('sendStatsFromHTML', {
event_name: 'event_redirect_updateSFDC',
event_params: fieldsCustomObject,
})
NOTE
When this event is fired, if the device is online, create/update calls are fired as soon as possible. If the device is not online, these calls are saved and gets synced on the first online presence.
# Reading values
Pitcher Impact downloads the data from SalesForce and saves it locally in to a database. In this way, the data is accesible even if the user has not internet connection. To read the SalesForce data from an interactive, searchDB
event needs to be used.
Example:
function getCustomObjectRelatedToAccount(currentAccountID, source) {
Ti.App.fireEvent('searchDB', {
objectType: 'customObject__c',
keyword: currentAccountID,
callBack: 'gotCustomObject', // function name to be called as a callback function
source: source, // required for only iOS
})
}
// this function needs to be in the global context
// called as a callback function after Ti.App.fireEvent('searchDB')
function gotCustomObject(params) {
const parsedParams = JSON.parse(params)
console.log(parsedParams)
}
- In the example above,
currentAccountID
can be accesses fromwindow.params
, depending on the interactive content type you are developing. source
can be eithermodal
for zip interactive orpresentation
for presentation interactive content types. This is needed for the callback function to be fired up in the correct content view.
Example with @pitcher/core and ES6:
import { fireEvent } from '@pitcher/core'
async function getCustomObjectRelatedToAccount(currentAccountID, source) {
const result = await fireEvent('searchDB', {
objectType: 'customObject__c',
keyword: currentAccountID,
source: source, // required for only iOS
})
console.log(result)
return result
}
- If used with
fireEvent
function in@pitcher/core
package,callback
param is not needed asfireEvent
function already assigns a param and returns the data asynchronously. - NOTE that
@pitcher/core
package has Vue.js dependency and cannot be used without it.