2

I am getting an odd bug where capitalizing the first letter of an Apex method that returns a map, causes an error within the javascript controller.

Javascript:

var action = component.get("c.OpAddOnCount");

Apex Controller:

public static Map<String,Integer> OpAddOnCount() {...}

When I capitalize the name in both JS and Apex, I get an error. However, if I make the first letter a lowercase 'o' (in both JS and Apex), everything works fine.

I am new to JS, is there an obvious syntax issue that I am unaware of? I want to make sure I don't get hung up on something like this again for so long!

  • Yep the case needs to match. Surprised about what you've seen through. Have you treble checked that you have changed both consistently i.e. both to upper case? – Keith C Jul 10 at 19:18
  • what is the name of the JS function that has the var action line? It must be named differently than the Apex Method. Quirky, but it is what it is. – Sebastian Kessel Jul 10 at 19:21
  • Yes, I even copied and pasted so I knew I had the cases matching exactly. For some reason is still only works when the "o" is lowercase. – John Jul 10 at 19:21
  • Name of the JS function is doInit. – John Jul 10 at 19:27
2

While Salesforce's naming conventions for Apex are optional in general, this isn't the case with Aura-linked server-side controller methods. I suspect this is due to JavaScript convention expectations (and that many IDEs will whinge if uppercase letters start function names that are not constructor functions [and vice versa]).

I can't say that I've seen any documentation on this one, but I certainly hit this same problem myself a year or two back.

Some useful reading here as well about parameter naming and the need to avoid name overloading on the client-side.

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.