Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to call my Apex class from a trigger:

trigger newCrossSellAccounts on Account (before insert) {

On the class I have:

public void insertAfterAccount2(list<account> accountList){

When I try to save trigger I get error:

Method does not exist or incorrect signature: crossSellModule.insertAfterAccount2(LIST<Account>) at line 2 column 4 

Now from documentation it says .new "Returns a list of the new versions of the sObject records." I tried to change the function on class to:

public void insertAfterAccount2(sObject<account> accountList){

But I get error:

Invalid type: sObject<account> 

Should I loop thru and create a list in trigger first? Or is there are workaround. Also, how one would test such trigger/class combination?

share|improve this question
I think you need to declare your function as static: public static void insertAfterAccount2(list<account> accountList){ – Lex Mar 10 '14 at 11:43
The reason you are getting the Invalid type: sObject<account> error is because you should be using List<sObject> rather than sObject<account> – BarCotter Mar 10 '14 at 11:46

As @Lex mentioned above the reason the code below is not working is because insertAfterAccount2 is not a static method and can not be called without first instantiating an instance of the CrossSellModule class.

trigger newCrossSellAccounts on Account (before insert) {

If you make the method static as shown below then it should fix the problem:

public static void insertAfterAccount2(List<Account> accountList) {

The reason you are getting the Invalid type: sObject<account> error is because you should be using List<SObject> rather than sObject<account>

FYI: The Trigger Context Variables are global and do not need to be passed directly. You could use in any class that is called from a trigger.

share|improve this answer
Could you please explain more about static methods? Is simply changing to a static method make the code work, as it saved successfully? Regarding the last point - should I then call the class as crossSellModule.insertAfterAccount2();? – dzh Mar 10 '14 at 12:14
More info on static methods can be found here. Its your decision on wether to pass in the list. It may make the class easier to understand, also if you plan on re-using that class somewhere else (e.g. in a Controller) then it makes more sense to pass in the List. – BarCotter Mar 10 '14 at 12:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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