7

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:

Visualforce lookup

Compared to the standard lookup on the standard page layout:

Standard lookup

Lookup Filter

This causes an issue with a lookup filter on the Account lookup. The lookup filter we are using has the following criteria:

  1. Opportunity: Opportunity Record Type equals Equity
  2. Account Name: Account Record Type equals Investor
  3. Opportunity: Opportunity Record Type equals Debt
  4. Account Name: Account Record Type equals Lender

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:

Standard dialogue

But from the Visualforce page, no results are returned in either Recently Viewed Accounts:

Visualforce dialogue

Or in Search Results (regardless of what is searched):

Visualforce dialogue with search

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.

7
  • 2
    Can you post your VF page? May 27, 2015 at 18:55
  • @RuslanVekua Sure. Let me carve it down to a minimal example that demonstrates the issue. May 27, 2015 at 18:57
  • @RuslanVekua Updated to include trimmed down Visualforce page. May 27, 2015 at 19:11
  • 1
    @LukeWillis are you looking at the standard and VF lookup as the same user and what do you see any result when you explicitly search for Test?
    – Rao
    May 27, 2015 at 19:12
  • 1
    @LukeWillis just a silly suggestion if you are testing this in a sandbox, can you clear the recordtype from the lookup criteria and check if the test accounts are pulling up fine?
    – Rao
    May 27, 2015 at 19:26

1 Answer 1

2

The issue had to do with the Opportunity Record Type somehow not being properly set for the record.

By adding

<apex:outputField value="{!Opportunity.RecordTypeId}" />

to the Visualforce page, I could see that the Record Type was what I expected; however, the lookup filter thought the Record Type was not set at this point.

I was able to get around the issue by making the New Opportunity action skip the record type selection page and setting the Record Type in an inputField on the visualforce page:

<apex:inputField value="{!Opportunity.RecordTypeId}" required="true" />

Thanks to rao for helping figure out that the Opportunity Record Type was causing the issue.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .