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
Uttpal chandraUttpal chandra 

Prevent user to stop editing child record

Hi all,
I have one picklist value Status on master object if status value changes from New to Pending i want to prevent user from stop editing child record anyone know how to achieve that..??
Khan AnasKhan Anas (Salesforce Developers) 
Hi Uttpal,

Greetings to you!

You can use validation rule on the child object.

If you want the validation rule to fire when a status change to "Pending" from "New", then use below rule:
AND(
  ISPICKVAL(PRIORVALUE(Account.Status__c) ,"New"),
  ISPICKVAL(Account.Status__c,"Pending")
)

If you want the validation rule to fire when a status is "Pending", then use below rule:
ISPICKVAL(Account.Status__c, "Pending")

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Uttpal chandraUttpal chandra
Hi Khan Anas,
I have use custom vf page on edit button in child record and this validation rule it is not working
Sundar rajan ASundar rajan A
Hi Uttpal chandra,

You can use below code, It would pervent to Editing child record when the Master Status is Pending.

Visualforce page:

<apex:page standardController="Child__c" extensions="PreventEditchildRec">
<apex:form >
<apex:pageBlock rendered="{! issue}">
<apex:pagemessages />
</apex:pageBlock>

 <apex:pageBlock rendered="{! !issue}">

  your code here...
 <apex:inputField value="{! Child__c.Name}"/>

 </apex:pageBlock> 
 </apex:form>
</apex:page>



Controller:

public class PreventEditchildRec {
    
    public Boolean issue {get;set;}
    
    public PreventEditchildRec(ApexPages.StandardController controller) {
    
        ID childRecId = ApexPages.currentPage().getParameters().get('id');
        String Status = [select id,Master__c,Master__r.Status__c  from Child__c where id =: childRecId].Master__r.Status__c ;
    
    if(Status == 'Pending')
    {
    
        issue = True ;
        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'You Cannot Edit'));
    
    }

  }

}

I hope it will solve your requirement!!

Thanks.

Regards,
Sundar Rajan. A