You need to sign in to do that
Don't have an account?
lakshmi salesforce
how to write a code in trigger to change the master field through detail field
hi everyone
Actually i have an issue like i have two objects 1)position(master),and 2)job applications(detail).I have fileds in both the objects as
position-------------status(pick list data type(open,new,closed))
job applications-----------------status(picklist(open,new,closed))
------------------ position(master detail relationship field)
now i have need to write a trigger on job apllication object such that whenever the job applications status has been changed to closed,the trigger should chage the status of position to closed automatically.i have written the code as following ,but it is showing the following error
code
trigger jobApplicationAssociatePositionClose on Job_Application__c (after insert,after update) {
for(Job_Application__c jobApp:trigger.new){
if(jobApp.Status__c=='closed')
jobApp.position__c.Status__c='closed';
}
}
error:invalid foreign key relationship :job_application__c.position__c
anybody please help me on this issue
Actually i have an issue like i have two objects 1)position(master),and 2)job applications(detail).I have fileds in both the objects as
position-------------status(pick list data type(open,new,closed))
job applications-----------------status(picklist(open,new,closed))
------------------ position(master detail relationship field)
now i have need to write a trigger on job apllication object such that whenever the job applications status has been changed to closed,the trigger should chage the status of position to closed automatically.i have written the code as following ,but it is showing the following error
code
trigger jobApplicationAssociatePositionClose on Job_Application__c (after insert,after update) {
for(Job_Application__c jobApp:trigger.new){
if(jobApp.Status__c=='closed')
jobApp.position__c.Status__c='closed';
}
}
error:invalid foreign key relationship :job_application__c.position__c
anybody please help me on this issue
You can fetch the record, before updating the field of master object and then do the changes to required fields.
I have just revised your code, pleaselet me know if it works for you.
Best Regards,
BALAJI
All Answers
You can fetch the record, before updating the field of master object and then do the changes to required fields.
I have just revised your code, pleaselet me know if it works for you.
Best Regards,
BALAJI
1) In your code are try to update position__c object from Job_Application__c object trigger in that case you need to query Position object.
TRy below code. Let us know if this will help you
You need to revise your trigger code a bit to make it work.