I have an apex method which receives a country name and returns a country code.

@AuraEnabled (cacheable = true)
public static String getCountryCode(String searchString) {
    //TODO add the code to lookup the country code
    String result = 'test';
    System.debug('ALH searchString='+searchString);
    System.debug('ALH result='+result);
    return result;

I will add the logic later to do the lookup, for now I am just trying to get the searchString into the apex method.

Here is part of my js code

import getCC from '@salesforce/apex/NewAccountController.getCountryCode';

@track searchCountry;
@track searchCountryCode;
@track foundCountryCode;

grabCC() {      
const searchccId=this.searchCountry;
                if (searchccId) {
                getCC ( {searchccId} ) 
                    .then(result => {
                        this.searchCountryCode = result;
                    .catch (error => {
                        console.log('catch error ' + error.message);

When I look at my debug log in for the APEX code it shows: ALH searchString=null ALH result=test

I understand that the input string is a "promise", but how can i force it to be passed in so that I can use the searchString in my APEX code?

  • This problem was similar but different cause. Thank you so much for the reply, this one had me stumpped. THANK YOU! – ahsfdc Oct 24 '19 at 15:30

You are declaring parameter of name searchString in apex method but you are passing searchccId. Below are the 3 options to fix:

Option 1:

const searchString =this.searchCountry;
     if (searchString) {
         getCC ( { searchString  } ) 
             .then(result => {

Option 2:

const searchccId =this.searchCountry;
     if (searchccId) {
         getCC ( { searchString: searchccId } ) 
             .then(result => {

Option 3:

 if (this.searchCountry) {
     getCC ( { searchString: this.searchCountry } ) 
         .then(result => {
  • 1
    Thank you so much! I can't believe I missed that. Works great now. THANK YOU! – ahsfdc Oct 24 '19 at 15:30

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