[SalesForce] Prevent User from changing related list lookup

I have a related list object through lookup relationship.

When i click on new button on child object in related list, the lookup is prepopulating with the parent Name.

how can i prevent the users from changing the value inside this lookup ?

Thank you!

Best Answer

Without creating a custom UI for this action, via Visualforce action overrides, this is not possible to control in the standard UI unfortunately. Even in the layout editor the option to make the field read-only is disabled. Though if you have a master detail relationship the platform will by default disable edit access to the parent field but only when editing the child record not creating it.

Visualforce Approach

Using the Visualforce action override approach linked above, i was able to build a page that resembled mostly the original native page. Of course in your case, it depends on the number of fields you have, though perhaps a minimum for creation is a good thing?

So this is what my mockup started like with the standard UI...

enter image description here

This is what I was able to achieve with the following VF page used as an action override...

enter image description here

This was my Visualforce page used above...

<apex:page standardController="Child__c">
    <apex:sectionHeader title="Child Edit" subtitle="New Child" />
    <apex:form>
    <apex:pageBlock>
        <apex:pageBlockButtons>
            <apex:commandButton value="Save" action="{!save}"/>
            <apex:commandButton value="Cancel" action="{!cancel}"/>            
        </apex:pageBlockButtons>
        <apex:pageBlockSection columns="1">
            <apex:inputField value="{!Child__c.Name}" required="true"/>
            <apex:outputField value="{!Child__c.Master__c}"/>
            <apex:inputField value="{!Child__c.Text_Something__c}"/>
            <apex:inputField value="{!Child__c.Checkbox_Something__c}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>
Related Topic