You need to sign in to do that
Don't have an account?
Mike Rethage
Create Equipment (custom) Object Records based on Contract Field Values
Hello,
Our business process demands automatic equipment record creation when a contract is activated. When the contract is entered the user would enter numeric values for Product 1, Product 2 etc. I want the flow to look-up those numeric values and create the number of new equipment records specified. I.e Product1 =16 it would create 16 new equipment records under that account. Additionally I would want information such as the Install Contact from the contracts Contact Role to be populated in all the equipment records.
Is an Apex trigger the best way to accomplish this?
Thanks!
Our business process demands automatic equipment record creation when a contract is activated. When the contract is entered the user would enter numeric values for Product 1, Product 2 etc. I want the flow to look-up those numeric values and create the number of new equipment records specified. I.e Product1 =16 it would create 16 new equipment records under that account. Additionally I would want information such as the Install Contact from the contracts Contact Role to be populated in all the equipment records.
Is an Apex trigger the best way to accomplish this?
Thanks!
You can consider below 2 approaches based on the business requirement for equipment creation.
1. You can write a trigger on Contract object On Update event: 2. You can write batch and schedule on daily basis to find out the daily activated contracts and create equipments accordingly.
Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.
It sounds like a trigger to me, because you will want to instantiate a number of records based on the numeric values entered on the Contract. I'm not sure if a flow could accomplish the same task.
This would be an After Update trigger on Contract, as it would fire immediately upon contract update, meeting your automatic record creation on contract activation.
The trigger should first check whether the status of each contract has changed to 'Activated' by comparing against the status values for each record in the trigger.oldMap variable. The Ids of the contracts whose status has changed to 'Activated' would be collected into a set in order to query for ContractContactRoles where the ContractId is in this set and the Role = 'Install Contact' (I'm assuming this is identified on the ContractContactRole record). You will then have a list of ContractContactRoles for your Install Contacts where the Contract has just changed to 'Activated' The ContractId from each query result can be used to get the Contract from trigger.newMap, which will have with it the product counts and the AccountId. You may need to be careful that a product count field actually contains a value before you try to use it. I am making plenty of assumptions here about how the equipment record is set up, and I haven't tested any of this code. Even still it should give you an idea of how the information you are looking for is available using the trigger map variables and some SOQL. There is a number of equipment records being created, each populated with the contract's account id and the contact id of the Install Contact role.
As for getting the expected behavior from the trigger
- you'll want to make sure the trigger is active (sorry, I have seen it happen).
- Also, make sure your contract status value is spelled correctly.
- Check that the correct ContractContactRoles are in place, and that the role name is spelled correctly, as the ContractContactRole FOR loop will not even be entered if no ContractContactRole records are found, meaning there's no chance of creating the eqpt records.
- If DS_Systems__c is zero, then no eqpt records will be created either.
That's all I can think of that would prevent it from generating the expected records. Hope it helps!