i import the method that i have to use in JavaScript file like this

import getRoles from '@salesforce/apex/LeaveSettingsController.getRoles';

@wire(getRoles) rolesList;

when i'm trying to push the code to my scratch org i got an error like this Unable to find Apex action class referenced as 'LeaveSettingsController'

I create an apex class in my DevHub org

public with sharing class LeaveSettingsController {

    public LeaveSettingsController(){


    public static List<UserRole> getRoles(){
        return [SELECT Id, Name FROM UserRole];

I have a DevHub org and only one scratch org and i use this command to push the code to the scratch org using the VS Code:

sfdx force:source:push
  • Do you have apex class named LeaveSettingsController? Which command are you trying to deploy your code? – sanket kumar Apr 10 '19 at 9:13
  • Have you opened the developer console on the scratch org and hit Ctrl+shift+O and searched for your class? Although the output in the terminal when you hit sfdx force:source:push should have listed the class as deployed – akarnid Apr 10 '19 at 9:36
  • @akarnid i searched for my class and it not exist in my scratch org can you tell me why this it happened? – sally yamak Apr 10 '19 at 9:47

First, you need to create an apex class using below command from command palette,

sfdx: create apex class

You need to enter your class name, then just press enter to select default directory for apex classes.

A class will be created in your project in a folder like ...\default\classes.

Just paste all your code over there.

Then you can push to scratch org, which will create an apex class in your scratch org, and you won't get any error.

Update - An alternate way: If scratch org is open in the browser, you can also create apex class from there by going to setup -> Apex Classes.

  • Thank you very much i did exactly what you say before and now it works! – sally yamak Apr 10 '19 at 11:20
  • 1
    @sallyyamak if this answers your question mark the answer as correct and it will help future people trying to find answers to similar questions – RedDevil Apr 10 '19 at 11:31

In my case, the problem appeared because during on deploy I forgot to include Apex Classes

I used a command

sfdx force:source:deploy -m LightningComponentBundle 

while I should have used a command

sfdx force:source:deploy -m ApexClass,LightningComponentBundle

This helps in the case when the source code is deployed from Version Control System into Developer Edition organization or to the scratch org as well.

However, in case of scratch org, instead of command

sfdx force:source:push -m LightningComponentBundle 

another command should be used

sfdx force:source:push -m ApexClass,LightningComponentBundle

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.