You need to sign in to do that
Don't have an account?
Mayank07
unable to update parent field from child
I got 2 objects Service_Request__c(Parent) and Service_Line__c(Child). All I'm trying to do is update a field of parent object from child.based on the following condition.
In the following code, I'm not getting how to update the parent.
please suggest how to proceed.
In the following code, I'm not getting how to update the parent.
please suggest how to proceed.
public class StatusClosedHandler { public static void statuschange (String RecordId){ integer count = 0; List<Service_Line__c> sLine = new List<Service_Line__c>(); for(Service_Line__c sl : [Select id, Name, Status__c,Line_Type__c, Service_Request__r.Status__c,Service_Request__r.Name from Service_Line__c WHERE Service_Request__c = :RecordId ]){ if(sl.Status__c == 'Completed'){ count++; } if(count == 3){ sl.Service_Request__r.Status__c = 'Closed'; } sLine.add(sl); } update sLine; } }
Are you getting any errors as such??
Regards,
Anutej
I am getting no errors so far but my desirable output is also not coming, like i want to update my parent object field based on child's condition but no positive result is coming
https://developer.salesforce.com/forums/?id=906F0000000kIzEIAU
>> In case you want a scenario to update the parent record from child record using flow you, please have a look at the below example:
https://developer.salesforce.com/forums/?id=9060G000000UVjrQAG
Can you try looking at the above links once.
i am still stuck in updating the parent field.
Select id, Name, Status__c,Line_Type__c, Service_Request__r.Status__c,Service_Request__r.Name from Service_Line__c WHERE Service_Request__c = :RecordId
I think you need to compare Service_Request__c.id with recordid.
Can you try it.
Do let me know of the results.
Don't konw why are you trying to put the trigger on the parent object, such logics should alwawys be evaluated from the child. Ex. when a Service_Line__c status is updated to 'Completed', then 'Closed' the status to the parent Service_Request__c object.
Anyways, you can use below code which will work per your question (from the parent object trigger to upate parent). I've updated the code by using coding best practices too.
Make sure your Service_Request__c trigger is firing on "after update" and you are passing a new map to the handler method.
Ex.
Mark it the best answer if it solves your issue
It looks like our team of experts can help you resolve this ticket. We have Salesforce global help-desk support and you can log a case and our Customer Success Agents will help you solve this issue. You can also speak to them on live chat. Click on the below link to contact our help-desk. Trust me it is a support service that we are offering for free!
https://jbshelpdesk.secure.force.com
Thanks,
Jarvis SFDC team