function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sainath VenkatSainath Venkat 

VF page and Apex class to update child and parent record

Hello Everyone, I have two objects
  1. Time__c
  2. Resource__c
I have Stage__c field on two objects, time is parent and resource is child, now I wanto create a button on Resource__c object, on clicking the button, I want to update Stage__c on both objects to 'Recalled'.
Can anyone help me out to achieve this, I want to achieve with VF page and apex class here. I also want to show success message to user on updation of records.
Suraj Tripathi 47Suraj Tripathi 47
Hi,
You can try the below code if it helps you:-
<apex:page Controller="changeStatus" >
 
    <apex:form >
            <apex:pageBlock title="Save Contact">

            <apex:pageBlockButtons >
                 <apex:commandButton action="{!changeRecords}" value="changeStage" />
            </apex:pageBlockButtons>
        
</apex:pageBlock>
    </apex:form>
</apex:page>
////////////////
Public class changeStatus{
    public changeRecords(ApexPages.StandardController controller) {
        strign currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
           system.debug('currentRecordId-- '+currentRecordId);

      Resoure__c R=  [select id,TimeId__c,stageName from Resoure__c where id=:currentRecordId];
       Time__c T = [select id,name,stageName  from Time__c where id=:R.TimeId__c];
        R.stageName ='Recalled';
        update r;
         
        T.stageName  = 'Recalled';
        update T;
 }
    }

Please mark it as Best Answer if it helps you.

Thanks & Regards
Suraj Tripathi
Sainath VenkatSainath Venkat
hi @Suraj Tripathi, thanks for helping me out on this, I am getting error stating unknown constructor on VF Page