2

Right now if I call the action button without Queueable Apex, from all the parameters I get from the Visualforce page and then perform action on the backend, due to the Apex Triggers I always will get "Error: System.LimitException: Too many SOQL queries: 101".

So I'm trying to make my action call from a Queueable apex instead to avoid the SOQL queries limit exception.

So trying to perform this following code as below:

Visualforce page:

<apex:page controller="X_Controller" lightningStylesheets="true" extensions = "X_Queueable">
<td style="text-align:center;">
   <apex:commandButton value="Apply Adjustment" action="{!add_JobToQueue()}" reRender="showmsg" 
     onclick="this.disabled='true'; this.value='Generating...';return false;"/> 
</td>
</apex:page>

X_Controller:

public with sharing class X_Controller{

  public void ApplyChargeAdjustment(){
     //do something
  }
}

X_Queueable :

public with sharing class X_Queueable implements Queueable {
    
    public void execute(QueueableContext context) {
        //do something
    }

    public void add_JobToQueue(){
        ID jobID = System.enqueueJob(new X_Queueable());
    }
}

But when I save all the files I get this error :

Unknown constructor 'X_Queueable.X_Queueable(X_Controller controller)'

Even when I try to create a constructor on the Queueable apex, the error wouldn't go away.

Help?

3

You need to define 2 constructors in your X_Queueable.cls.

public X_Queueable() {  
}
    
public X_Queueable(X_Controller controller){  
}

Aside from this, your visualforce markup also needs to change to include <apex:form> & a minor change in the action attribute.

<apex:page controller="X_Controller" lightningStylesheets="true" extensions = "X_Queueable">
    <apex:form>
        <td style="text-align:center;">
           <apex:commandButton value="Apply Adjustment" action="{!add_JobToQueue}" reRender="showmsg" 
             onclick="this.disabled='true'; this.value='Generating...';return false;"/> 
        </td>
    </apex:form>
</apex:page>
2
  • Now there isn't any error when I save, but when I press the button on VF Page. I don't see any Apex jobs occuring. Any ideas? – compski Jun 17 '20 at 10:26
  • 1
    I would think it's more of an issue with the onClick than anything else. Remove the return false; and you should get a job entry. – TSmith Jun 17 '20 at 10:48

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.