function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
thekid12345thekid12345 

how to call an APEX class method from a Trigger

In my Class I have this method 
global class Queue{

public static void send(List<ListRequests> requests){...}

}
In my Trigger, I initialize the class and want to call the Apex class method
Queue sendToQueue = new Queue();

List<String> lead = new List<String>();

sendToQueue.send(leads);
It is throwing an error saying 

Method does not exist or incorrect signature
Malni Chandrasekaran 2Malni Chandrasekaran 2
thekid12345,
I am not sure what you are trying to do, here r few errors noted below.

global class Queue{
public static void send(List<ListRequests> requests){...} // Method signature looking for a list of type 'ListRequests'
}

Queue sendToQueue = new Queue();
List<String> lead = new List<String>();  // Here you have defined list of type 'String' which is supposed to be 'ListRequests' as per your method signature
sendToQueue.send(leads);    //you have mispelled the parameter name as 'leads' but you have defined it as 'lead' -  's' at the end.

Please fix all the issues.

Please mark it as solved if it helps you to fix the issues.
Thanks.
Shruti SShruti S

I would also like to add one more point.
You have declared your send method as a static method, hence you need not instatiate the class and then call the send method. Instead you can direclty call it as - 

Queue.send( leads );
Pavit SiddhuPavit Siddhu
hello, 
Queue sendToQueue = new Queue();

List<String> lead = new List<String>();

sendToQueue.send(leads);


change to
List<ListRequests> lead = new List<ListRequests>();

sendToQueue.send(leads);