2

I'm trying to pass a parameter of an Object to a controller with this code block:

<apex:commandButton  value="Accept" action="{!Accept}" >                        
  <apex:param name="deal" value="{!deal.id}" assignTo="{!dealId}"/>
</apex:commandButton>

But Visualforce always gives following error:

List has no rows for assignment to SObject Error is in expression '{!Accept}' in component in page dealviewer: Class.DealViewerController.Accept: line 34, column 1

When I debug the controller in Developer Console it tells me I'm passing a null value:

// click action button Accept
    public void Accept() {
        String dealId = apexpages.currentpage().getparameters().get('dealId');
        System.debug(dealId);
        Deal_Action__c dealac = [SELECT Action__c, Contact__c FROM Deal_Action__c WHERE Deal_Action__c.Deal__c = :dealId];
        dealac.Action__c = 'Accepted';
        update dealac;
    }

Anyone knows the solution to this problem?

2 Answers 2

2

Thanks for your answer SF_User, but unfortunately this doesn't solved my problem.

Finally I found the problem. Apex is not supporting param and commandbutton so you have to work around with reRender attribute and reRender not the whole page.

<apex:column headerValue="Action" id="all">                 
 <apex:commandButton  value="Accept" action="{!Accept}" reRender="all" >                        
  <apex:param name="deal" value="{!deal.Id}" assignTo="{!dealId}" />
 </apex:commandButton>                      
 <button type="button">Reject</button>                                              
</apex:column>
0

If you want to use the apexpages.currentpage().getParameters().get('...') method, you can try this :

VF :

<apex:commandButton  value="Accept" action="{!Accept}" >                        
  <apex:param name="deal" value="{!deal.id}" />   // Remove the assignTo attribute
</apex:commandButton>

APEX :

// click action button Accept
    public void Accept() {
        String dealId = apexpages.currentpage().getParameters().get('deal'); // Change dealId to deal
        System.debug(dealId);
        Deal_Action__c dealac = [SELECT Action__c, Contact__c FROM Deal_Action__c WHERE Deal_Action__c.Deal__c = :dealId];
        dealac.Action__c = 'Accepted';
        update dealac;
    }

You must log in to answer this question.

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