Events

Next custom events are dispatched:

  1. tnw_salesforce_objects_save_before

  2. tnw_salesforce_objects_save_after

  3. tnw_salesforce_objects_delete_before

  4. tnw_salesforce_objects_delete_after

 

tnw_salesforce_objects_save_before

This event is dispatched in the process of any Magento-to-Salesforce or Salesforce-to-Magento entity synchronization before the entity’s data is saved to the tnw_salesforce_objects table. The payload carries data of the saved objects. The payload type is an array.

How to use this event:

app/code/Vendor/Module/etc/di.xml:

<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="tnw_salesforce_objects_save_before"> <observer name="tnw_salesforce_objects_save_before_test" instance="Vendor\Module\Observer\SaveBeforeObserver"/> </event> </config>

app/code/Vendor/Module/Observer/SaveBeforeObserver.php:

<?php declare(strict_types=1); namespace Vendor\Module\Observer; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; use TNW\Salesforce\Model\ResourceModel\Objects; class SaveBeforeObserver implements ObserverInterface { public function execute(Observer $observer) { $records = $observer->getEvent()->getData(Objects::RECORDS_KEY); // Any custom logic with $records array } }

 

tnw_salesforce_objects_save_after

This event is dispatched in the process of any Magento-to-Salesforce or Salesforce-to-Magento entity synchronization after the entity’s data is saved to the tnw_salesforce_objects table. The payload carries data of the saved objects. The payload type is an array.

How to use this event:

app/code/Vendor/Module/etc/di.xml:

<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="tnw_salesforce_objects_save_after"> <observer name="tnw_salesforce_objects_save_after_test" instance="Vendor\Module\Observer\SaveAfterObserver"/> </event> </config>

app/code/Vendor/Module/Observer/SaveAfterObserver.php:

 

tnw_salesforce_objects_delete_before

This event is dispatched before the entity’s data is deleted from the tnw_salesforce_objects table through mass delete on the “TNW Salesforce / Magento & Salesforce IDs” grid (SalesforceToolsSalesforce ID Mappings from admin menu). The payload contains the ids of deleted objects. The payload type is an array.

How to use this event:

app/code/Vendor/Module/etc/di.xml:

app/code/Vendor/Module/Observer/DeleteBeforeObserver.php:

tnw_salesforce_objects_delete_after

This event is dispatched after the entity’s data is deleted from the tnw_salesforce_objects table through mass delete on the “TNW Salesforce / Magento & Salesforce IDs” grid (SalesforceToolsSalesforce ID Mappings from admin menu). The payload contains the ids of deleted objects. The payload type is an array.

How to use this event:

app/code/Vendor/Module/etc/di.xml:

app/code/Vendor/Module/Observer/DeleteAfterObserver.php: