What is Lookup dialog ?
All parent relationship field which is of type lookup can be changed using the standard inputField tag on them.How can we take action after the Lookup ?
When user selects some value for the parent relationship, we may need to take some action, perhaps a validation (or) confirmation action to the user.
Where it will be useful ?
We could use this for validation purposes or rendering different section of the page based on the value selected, etc.
Where is the Code ?
The code will illustrate how to take action after the lookup value changed & update different section of the page based on the new selected value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class testcls36_22122016 { | |
Opportunity opp; | |
public testcls36_22122016(ApexPages.StandardController sc) { | |
opp = (Opportunity) sc.getRecord(); | |
} | |
public void changeAccount() { | |
opp.Account.Name = [Select | |
Id, Name | |
From | |
Account | |
Where | |
Id =: opp.AccountId | |
][0].Name; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page standardController="Opportunity" extensions="testcls36_22122016"> | |
<apex:form> | |
<!-- Action for a change in lookup field --> | |
<apex:sectionHeader title="Change Account to reflect in Account Details"/> | |
<apex:outputLabel value="Opportunity Name"/> | |
<apex:inputField value="{!Opportunity.AccountId}"> | |
<apex:actionSupport event="onchange" action="{!changeAccount}" reRender="AccountName"/> | |
</apex:inputField> | |
</apex:form> | |
<!-- Account Details --> | |
<apex:sectionHeader title="Account Details"/> | |
<apex:outputText value="Account Name is {!Opportunity.Account.Name}" id="AccountName"/> | |
</apex:page> |
I am getting this issue
ReplyDeleteAttempt to de-reference a null object
Error is in expression '{!changeAccount}' in page rapidorderentry: Class.ProductController.changeAccount: line 11, column 1