I have two object , abc__c
and xyz__c
. xyz__c
has a field named key__c
which should store the id of abc__c
object.
abc__c has a picklist field status__c which can have different value "In-progress" , "Approved", "Sent","Error","complete"
. xyz__c has a status field as a text field. xyz__c record is created when status of abc__c is changed from "Approved" to "Sent". The key__c
field of xyz__c
will store id value of abc__C. I am
using this to eastablish a connection between xyz__c and abc__c.
What I want to do:
I want to create a trigger on abc__C object and have a logic when the abc__c record is updated(afterUpdate). I want to do the following when the record is updated:
when abc__c status is changed from "Approved" to "Sent" - I have to create a new record for xyz__c object if it is not exsisting yet. The key__c value should be sfdc id of abc__c. I find whether xyz__c record for an abc__c record is available or not based on the value of key__c field which holds abc__c's id.
I am storing the id of abc__c in the field - key__c of xyz__c object so that I can query the xyz__c record which was related to abc__c object.
How can I query inside the trigger to find the exsisting abc__c record which has the id of abc__c record. I see a challenge that I might hit the governs limit for this.
List<abc__c> a; for(abc__c s: trigger.new){ a=[select id from xyz__c where key__c = s]; }
Once I find the xyz__c record which stores the id of abc__c record:
I want to make the status__c field on xyz__C record as "sent" if the status of abc__c record is changed from "approved" to "sent" only