I have a lookup field declared as below:
<apex:inputfield value="{!Product2.Opportunity__c}" id="prodoppr"/>
wish to know how to add or handle event for this lookup field? When there is a change in the value I want to trigger method to perform certain validation and upate other fields….how can i achieve this? please any inputs?
Best Answer
You can use
apex:actionSupport
to listen for changes and respond accordingly. For example:If you want to do client-side validation, you can also use
apex:inputField
'sonchange
attribute to support listening for changes to the lookup field.Edit: The
action
attribute is used to determine the function to call. So, in this example, the function is namedvalidateAndUpdate
, which would look like this:Appropriate error handling should also be part of such a function to avoid partial transactions by way of Database.setSavePoint and Database.rollback.