When you are creating a new record, the LookUp filters work well in the standard SalesForce page but the same does not happen when creating a record in the VisualForce page. Let us look at this issue using an example –
- Create a new custom object say Equipment which has a lookup relation with Account.
- Create a new lookup custom field in Case which relates with Equipment.
- Case has already related with standard object account.
- Create lookup filter for Equipment filed in case such that: Case.AccountId equals Case. Equipment. AccountId.
- Go to any account record and create a new case for that Account.
- When user will select Equipment for that case only those Equipment records will be available for user to select which are related to the same Account for which Case is being created.
- Now create a VF page for create Case.
- As user will always be creating Case from an Account and user is not allowed to update the Account while on the case page thus, account field is incorporated with <apex:outField> Tag.
- Run this VF page where it can be seen that lookup filter for Equipment it not showing any result which was working in standard case create page.
- Replace <apex:outputField> tag with <apex:inputField> for the standard Account field on case.
- Disable Account field using JS/ CSS instead of rendering using <apex:outputField>.