You need to sign in to do that
Don't have an account?
umair.ilyas1.397096182101089E12
Need Apex Trigger for picklist from one object to checkbox on another object
Hi,
I just have a brief overview of Apex, but I'm wondering if someone can help me here.
I have two custom objects:
Parent Object: Requests
Related Child Object: Requestor
On the parent object, I have a picklist field: Request Status (None, In Progress, Complete)
On the child object, I have a checkbox: Request Complete
I need a workflow to trigger when Request Complete = True. However, I don't want to manually edit the checkbox. I need an Apex trigger that will edit the child object when the parent object is edited, and I need that to trigger my workflow on the child object. I need an Apex Trigger that will do the following:
When Request Status = Complete
Then Resource Complete = True
Is this possible? If so, could someone help show what such a code would look like?
I just have a brief overview of Apex, but I'm wondering if someone can help me here.
I have two custom objects:
Parent Object: Requests
Related Child Object: Requestor
On the parent object, I have a picklist field: Request Status (None, In Progress, Complete)
On the child object, I have a checkbox: Request Complete
I need a workflow to trigger when Request Complete = True. However, I don't want to manually edit the checkbox. I need an Apex trigger that will edit the child object when the parent object is edited, and I need that to trigger my workflow on the child object. I need an Apex Trigger that will do the following:
When Request Status = Complete
Then Resource Complete = True
Is this possible? If so, could someone help show what such a code would look like?
the formula field would be something like:
if(ISPICKVAL(request status, complete),true,false)
when doing the formula field, you will see an advanced tab, use that and the insert field to get the correct related field.
than, you could do the workflow based on that value
If I understood your question correctly.
You should write the trigger on parent object that should have query to select all the child records. Select query should execute only when Request Status = 'Complete'.
If your query is not null you can update like this Resource Complete = True.
Eg.
trigger test on object__c (before update) {
set<id> idval = new set<id>();
for(object__c ben : Trigger.New){
if(ben.Request Status = 'Complete'){
idval.add(ben.id); //adding id value to query child records
}
}
if(!idval.isEmpty())
{
list<childobj> tet = [select id,Resource Complete from childobj where parentobj IN:idval and Resource Complete!=:true ];
}
for(childobj t : tet)
{
t.Resource Complete =true;
}
update tet; //updating child values.
}
I hope this will helpful.
Thanks.
Praveen Murugesan
Thank you for your reply. Is your example what the final code would look like? I'm VERY new to learning code, so what would a final code look like for the following:
parent object is REQUEST__C
child object is REQUESTOR__C
If Request_Status__c = Resource Complete on RRT_Request__c,
Then Update
Add_Requestor_to_Evaluation__c To TRUE on RRT_Requestor__c
Thanks.
Praveen Murugesan