Visualforce
Our organization uses a Visualforce page to override the New Opportunity action. Below is a functional sample of the Visualforce page that specifies the Account lookup field and demonstrates the issue:
<apex:page standardController="Opportunity">
<apex:form>
<apex:pageBlock mode="edit" title="New Opportunity">
<apex:pageBlockButtons>
<apex:commandButton action="{!save}" value="Save" />
</apex:pageBlockButtons>
<apex:pageBlockSection>
<apex:pageBlockSectionItem
HelpText="{!$ObjectType.Opportunity.fields.AccountId.inlineHelpText}">
{!$ObjectType.Opportunity.fields.AccountId.label}
<apex:inputField value="{!Opportunity.AccountId}" required="true"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
This is displayed as:
Compared to the standard lookup on the standard page layout:
Lookup Filter
This causes an issue with a lookup filter on the Account lookup. The lookup filter we are using has the following criteria:
Opportunity: Opportunity Record Type
equalsEquity
Account Name: Account Record Type
equalsInvestor
Opportunity: Opportunity Record Type
equalsDebt
Account Name: Account Record Type
equalsLender
With filter logic of (1 AND 2) OR (3 AND 4)
.
Note: It looks like only the Opportunity: Opportunity Record Type
filters are causing the issue. See the below update.
The Issue
When looking up an Account from the standard page layout, the filter works correctly:
But from the Visualforce page, no results are returned in either Recently Viewed Accounts:
Or in Search Results (regardless of what is searched):
Note: without the lookup filter, the issue does not occur. Additionally, if the Account ID field is filled by other means (i.e. if it's auto populated by the New Opportunity button on the Account), the filter logic is correctly applied. This issue also occurs regardless of the current user's permissions.
Question
How can I make the Account lookup on my Visualforce page behave the same as it does in the standard page layout?
Update
Simple filter criteria (i.e. Opportunity: Closed
equals False
or Account Name: Account Name
not equal to Fake
) do not cause any issues. Additionally, filtering by only Account Name: Account Record Type
works fine. Any filter on Opportunity: Opportunity Record Type
causes the issue.
We originally attributed the error to the lookup filter. Here's a link to the original question.