Reputation: 1
I have 2 Objects based on Lookup relationship i.e 1) Assign 2) Inventory.
Relation is 1 inventory can be assigned to many (1 to many).
Inventory has picklist values called "status" contains 2 values i.e "Assigned" and "Backup". So when any inventory is assigned, value changes from "Backup" to "Assigned".
Whenever any record of assign object is deleted, automatically related object (Inventory) field "status" should get updated from "Assigned" to "Backup".
Or else I will need to manually change the status of inventory object from "assigned" to "backup" whenever any record is deleted from assign, which I don't want.
I tried the flow, but I am confused exactly which option I should select. For reference I had attached the snaps.enter image description here enter image description here enter image description here
Upvotes: 0
Views: 543
Reputation: 1
Upvotes: 0
Reputation: 1
You need to create a trigger with BEFORE DELETE context.
trigger Assign on Assign__c ( before delete ) {
if( Trigger.isBefore )
{
if( Trigger.isDelete )
{
List< Inventory__c > lstInventory = [Select Id, Status__c From Inventory__c Where Assign__c =: newMap.kseyset()];
for( Inventory__c i : lstInventory ){
i.Status__c = 'Backup';
}
update lstInventory;
}
}
}
You need to check if newMap is filled when delete records context is fired if not try to use oldMap.
Don't forget to use best pratices to develop your code.
I hope to help you.
Upvotes: 0