( https://dev.osf-global.com/jira/browse/COBRA-134 )
- Clone the project.
- Push the project to the scratch org.
sfdx force:source:push -u <scratch org username/alias>
- Import sample data provided at ./data.
sfdx force:data:tree:import -p data/sample-data-plan.json -u <scratch org username/alias>
- Open the scratch org.
sfdx force:org:open -u <scratch org username/alias>
- A first query is performed to find the Metadata record that is activated. Metadata is used for integration settings purposes.
- The last value found on this metadata is used to filter another query for the next objects to be processed.
- Objects are processed (translated).
- Last value for the used metadata is updated. The process is pointed in three basic steps on comments at osf_AccountSourceBatch class.
Testing:
- Clone this repository.
- Create a scratch org and push this project.
- Import records provided on /data/sample-data-plan.json file.
- Make changes on osf_Account_Source__c
- Open developer console.
- Choose a future time (CRON time-based) to run the test job.
- Open execute anonymous window, and create an Apex scheduler by running the code bellow.
- After the batch is completed, verify changes reflected on osf_Account_Target__c.
osf_AccountSourceSchedule schedule = new osf_AccountSourceSchedule();
String cron = '0 59 10 * * ?';
String jobID = system.schedule('New import job', cron, schedule);
System.debug('Schedule job ID: ' + jobID);
- A first query is performed to find the Metadata record that is activated. Metadata is used for integration settings purposes.
- The triggered object (Trigger.new) is processed (translated).
Testing:
- Clone this repository.
- Create a scratch org and push this project.
- Import records provided on /data/sample-data-plan.json file.
- Make sure trigger is activated.
- Make changes on osf_Account_Source__c (any field described on Metadata fields map).
- Verify changes reflected on osf_Account_Target__c.
- Defined both source and target (custom) objects: for this sample code, osf_Account_Source__c and osf_Account_Target__c respectively.
- Created a custom metadata type (osf_Account_Mapping__mdt) with the following custom fields, for each source-target pair of objects. Each record of this may represent general instructions about how to proceed with the translation:
- Active: given it is possible to create many records for a metadata, it is easier to check or uncheck this field to inform which metadata must be considered for the next translations. A priori, only one of them must be checked.
- Email: provide an email address to be warned with general informations when the batch process of translations is finished.
- Fields Map: provide a JSON-like with the fields named after source object fields, and values named after the correspondent target object fields. This JSON can be improved with instrucitons to make the whole process easier.
- Last Value: This field is auto populated after each translation process, with the last LastModifiedDate value among all source objects translated in the last time.
- Unique Field: this field must be populated with the field name that uniquely correlates source and target objects. It is used for further updates purposes.
- Created at least one custom metadata type record and activate it.