I got 2 objects Service_Request__c(Parent) and Service_Line__c(Child). 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.
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;
}
}