Usage
Saves or updates an object in Salesforce. This method is available in API version 38.0 or later.
note: - To update using this method, include Id.
- To create using this method, include
entityApiName. - If an object uses
recordType, pass therecordTypeIdin thesaveLogcall. If you don't pass therecordType, the record is created using the defaultrecordTypefor the profile. To create a person account, you can pass the person accountrecordTypeif the profile's default is to a business account. - To refresh after you update or create using this method, call the
refreshViewmethod in thecallbackmethod.
Syntax
sforce.opencti.saveLog({
value:{
entityApiName:STRING, //Optional
Id:STRING, //Optional
param:VALUE //Optional
},
callback:FUNCTION //Optional
})
Arguments
| Name | Type | Description |
|---|---|---|
value |
object | Specifies the fields to save or update on the object. If the object's ID is specified, a record is updated. If the object's ID isn't specified, a new record is created. Ensure all required fields are specified when creating a record. |
callback |
function | JavaScript method executed when the API method call is completed. |
To update a record, include the object's ID in value:
{Id:"00QR0000000yN5iMAE", LastName:"New lastname" }
To create a record, include entityApiName instead:
{entityApiName:"Contact", LastName:"LastName" },callback:callback}
Sample Code–HTML and JavaScript
<!-- html set_clipboard --><html>
<head>
<script type="text/javascript" src="http://domain:port/support/api//lightning/opencti_min.js"></script>
<script type="text/javascript">
var callback = function (response) {
if (response.result) {
console.log('API method call executed successfully! returnValue:', response.returnValue);
} else {
console.error('Something went wrong! Errors:', response.errors);
}
}
function saveLog() {
//Update an existing object with the ID specified
sforce.opencti.saveLog({value:{Id:"00QR0000000yN5iMAE", LastName:"New lastname" }, callback:callback});
//Create a contact
sforce.opencti.saveLog({value:{entityApiName:"Contact", LastName:"LastName" },callback:callback});
//Update a lead
sforce.opencti.saveLog({value:{Id:"00QR0000000yN5iMAE", LastName:"New lastname" },callback:callback});
}
</script>
</head>
<body>
<button onclick="saveLog();">saveLog</button>
</body>
</html>
Response
This method is asynchronous. The response is returned in an object passed to a callback method. The response object contains the following fields.
| Name | Type | Description |
|---|---|---|
success |
boolean | Returns true if the API method call was invoked successfully, false otherwise. |
returnValue |
object | ID of object if creating or updating the object was successful; null if creating or updating the object wasn't successful. |
errors |
array | If the API call was successful, this variable is null. If the API call failed, this variable returns an array of error messages. |