PHP code example of comsave / safe-salesforce-saver-bundle
1. Go to this page and download the library: Download comsave/safe-salesforce-saver-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
comsave / safe-salesforce-saver-bundle example snippets
public function registerBundles()
{
$bundles = [
new Comsave\SafeSalesforceSaverBundle\ComsaveSafeSalesforceSaverBundle(),
];
return $bundles;
}
use Comsave\SafeSalesforceSaverBundle\Services\SafeSalesforceSaver;
class ObjectSaver
{
/** @var SafeSalesforceSaver */
private $safeSalesforceSaver;
/**
* @param SafeSalesforceSaver $safeSalesforceSaver
*/
public function __construct(SafeSalesforceSaver $safeSalesforceSaver)
{
$this->safeSalesforceSaver = $safeSalesforceSaver;
}
// This way of saving will wait for the save result from Salesforce. This means that you can immediately access the newly inserted ID after Salesforce saved the record.
public function saveSingle(Object $object): string
{
$this->safeSalesforceSaver->save($object);
return $object->getId();
}
// This function lets you save multiple objects at once. Simply put all the objects you want to save in an array and pass it to the SafeSalesforceSaver.
public function saveMultiple(Object $object, Object $object2, Object $object3): array
{
$this->safeSalesforceSaver->save([$object, $object2, $object3]);
return [$object->getId(), $object2->getId(), $object3->getId()];
}
// If you do not want to wait for the result you can simply put your object into the queue and continue with the rest of your code. This is recommended if you don't need the ID or if you don't need a confirmation that the save succeeded.
public function aSyncSaveSingle(Object $object): void
{
$this->safeSalesforceSaver->aSyncSave($object);
}
// As with the other save function, it is also possible to save multiple objects to Salesforce at once without waiting for the response.
public function aSyncSaveMultiple(Object $object, Object $object2, Object $object3): void
{
$this->safeSalesforceSaver->aSyncSave([$object, $object2, $object3]);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.