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
Rahul Srivastava 44Rahul Srivastava 44 

User can't change prepopulate lookup field.

Onclick 'New opportunity' button under the account. We see 'Account Name' field prepopulate as in images below.
User-added image

My requirement is while clicking lookup button for account selection. It should show only the existing account or user cannot change the current populating account. If a user selects another account it should throw error. How can we achieve this?
Dhanya NDhanya N
Hi Rahul,

You can try something like this:

AND( NOT(ISBLANK(AccountId)), ISCHANGED(AccountId) )

Thanks,
Dhanya
Rahul Srivastava 44Rahul Srivastava 44
It will not work.
Khan AnasKhan Anas (Salesforce Developers) 
Hi Rahul,

Greetings to you!

Unfortunately, this is not possible to control in the standard UI. You can make a field read-only. You can write your own Visualforce page for the New Opportunity page. Something like this:
 
<apex:page standardController="Opportunity">
    <apex:sectionHeader title="Opportunity Edit" subtitle="New Opportunity" />
    <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="{!Opportunity.Name}"/>
            <apex:outputField value="{!Opportunity.AccountId}"/>
            <apex:inputField value="{!Opportunity.CloseDate}"/>
            <apex:inputField value="{!Opportunity.StageName}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>

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
Gaurav HandooGaurav Handoo

Hi Rahul

I agree with Khan Anas, this is not possible through standard. However, if you don't want to go to a VF Page based approach, your user will have search for the account (based on the accessibility rights) but you can still use the formula (modified version of the formula provided by Dhanya) as mentioned below:

AND(NOT(ISNEW()), NOT(ISBLANK(PRIORVALUE(AccountId))), ISCHANGED(AccountId) )

Hope this helps. Please mark as best answer if it does.

Cheers!!

Gaurav

Rahul Srivastava 44Rahul Srivastava 44
Hi Gaurav,

Thanks, but it will work only I update the records not while I create the records.