0

Hi I have a lookup field which returns an opportunity if available, currently once i select an opportunity an actionsupport is triggered onchange, I then want to put that value from the lookup field into the controller using an apex:param however when i debug it in the controller its coming through as blank

Visualforce

<apex:inputField value="{!pb.CXT_Opportunity_Name__c}"> 
      <apex:actionSupport event="onchange" action="{!checkIfSelectedContactHasPendingOpp}"  rerender="testing">
          <apex:param name="PendingOpportunityName" assignTo="{!PendingOpportunityName}" value="{!pb.CXT_Opportunity_Name__c}"/>
      </apex:actionSupport>
</apex:inputField>

controller

public string PendingOpportunityName {get;set;}

 public pagereference checkIfSelectedContactHasPendingOpp(){
    system.debug(PendingOpportunityName);

    return null;
}

enter image description here the debug just returns empty, any help would be awesome, Thanks

1
  • Is CXT_Opportunity_Name__c a Lookup?
    – Dan Jones
    Sep 28, 2016 at 16:54

2 Answers 2

1

If CXT_Opportunity_Name__c is a Lookup to another object, you're passing the object value to a String which wouldn't work.

What you'd need to do is assign the value to an instance of that object, then get the Name. For example:

Apex Class

public CXT_Pass_Registration__c PendingOpportunityName { // Change the variable to an instance of the object
    get;
    set;
}

public pagereference checkIfSelectedContactHasPendingOpp(){
    system.debug(PendingOpportunityName.Name); // Access the variable (object) and then, the Name
    return null;
}

public MyCustomController() {
    PendingOpportunityName = new CXT_Pass_Registration__c();
}

Visualforce Page

<apex:page controller="MyCustomController">
    <apex:inputField value="{!PendingOpportunityName.CXT_Opportunity_Name__c}" />
</apex:page>
2
  • Hi, its a Lookup(Opportunity) however when i tried this i got the error : Invalid conversion from runtime type String to CXT_Pass_Registration__c Sep 28, 2016 at 19:35
  • @ClevelandDan See my updates.
    – Dan Jones
    Sep 29, 2016 at 9:47
1

You are missing rerender here. Add rerender in your actionsupport and also add in value in param

<apex:actionSupport event="onchange" action="{!checkIfSelectedContactHasPendingOpp}" rerender="none"> 
       <apex:param name="PendingOpportunityName" assignTo="{!PendingOpportunityName}" value="{!pb.CXT_Opportunity_Name__c}"/>    
</apex:actionSupport>
5
  • I have added a rerender on the actionSupper which rerenders the outputpanel around the pageblock and added the value however its still null? Sep 28, 2016 at 16:05
  • <apex:actionSupport event="onchange" action="{!checkIfSelectedContactHasPendingOpp}" rerender="testing"> Sep 28, 2016 at 16:06
  • <apex:param name="PendingOpportunityName" assignTo="{!PendingOpportunityName}" value="{!pb.CXT_Opportunity_Name__c}"/> Sep 28, 2016 at 16:06
  • @ClevelandDan i is still not working for you?first check if there is required field and you didn't filled them then use immediate attribute. Sep 28, 2016 at 16:15
  • i added the immediate="true" still nothing, I have also tried adding a actionRegion to no avail Sep 28, 2016 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.