1

I am new to Salesforce development and I am trying to practice by creating a list of strings deriving from another list of object records created from a query. My code is the following....

public class ProjectStatus{
    public static void Test(List<String> myArray) {
        for (List<pse__Proj__c> projects : [SELECT Id FROM pse__Proj__c WHERE Project_Status_Requirement__c = True LIMIT 1000]) {    
            myArray.add(String.valueOf(projects)); 
        }
    System.debug(myArray);
    }
}

After attempting to run in the Anon window, I receive the following error...

Method does not exist or incorrect signature: void Test() from the type ProjectStatus

I ran the following code in the Anon Exec window...

ProjectStatus.Test();

Could anyone help me identify why this error is being thrown? This is probably a simple beginner's mistake but after spending a lot of time researching and editing my code I am still unsuccessful so I am hoping someone here may be able to add some input, thanks in advance!

2
  • 2
    What was your exec anon code? Could you edit the code in to your question?
    – sfdcfox
    Jan 2, 2019 at 20:15
  • @sfdcfox updated the post, but here is the code I ran... ProjectStatus.Test(); Jan 2, 2019 at 20:18

2 Answers 2

3

You're missing the parameter. Try :

public class ProjectStatus{
    public static void Test() { // Notice I took out the bit between the ()
        List<String> myArray = new List<String>(); // and added the variable as a local variable

        // Removed the "list<>" from below code
        for (pse__Proj__c p : [SELECT Id FROM pse__Proj__c WHERE Project_Status_Requirement__c = True LIMIT 1000]) {    
            myArray.add(String.valueOf(p)); 
        }

        System.debug(myArray);
    }
}

If you wanted to try to use your method as is you would need to call it like so:

 List<String> results = new List<String>();
 ProjectStatus.Test(results);

Here's some documentation about method prototypes that might help you understand. Note, this is not a Salesforce specific issue, it can happen in all programming languages.

This article goes over scope to help understand what I mean by a local variable.

Copy-Pasta

public class ProjectStatus{
    public static void Test() { // Notice I took out the bit between the ()
        List<String> myArray = new List<String>(); // and added the variable as a local variable

        for (Account a : [
            SELECT Id 
            FROM Account
            LIMIT 1000
        ]) {    
            myArray.add(String.valueOf(a)); 
        }

        System.debug(myArray);
    }
}

Anon:

ProjectStatus.Test();
7
  • Your modification wouldn't work as is, missing variable definition.
    – sfdcfox
    Jan 2, 2019 at 20:22
  • @gNerb Sorry to bother you, I plan on thoroughly reading through the documentation you have sent, but I also tried changing my code as well as running it as it was with a parameter like you had commented but I am still receiving the following error... "Method does not exist or incorrect signature" Jan 2, 2019 at 20:30
  • I updated my code with copy pasta, please give that a try.
    – gNerb
    Jan 2, 2019 at 20:45
  • Hmmm seeing this error now, "duplicate value found: <unknown> duplicates value on record with id: <unknown>" I wonder if this underlying issue is also preventing me from running successfully? Also wondering if this is related to the metadata I am trying to pull because I am not really doing any data manipulation with this code. Jan 2, 2019 at 20:48
  • 1
    @gNerb sounds good, i will keep digging into this issue and try to identify the root cause. I greatly appreciate the help and hope one day I am able to repay the favor! Glad I was able to resolve the original question and your insight added a ton of clarification into that issue, I should really spend more time reading documentation before jumping right into programming with a new language Jan 2, 2019 at 20:57
1

This error is telling you that you forgot some parameters (in this case, a string list object). You'd call your code like this:

String[] values = new String[0];
ProjectStatus.Test(values);

Note that your code is directly modifying the values in the parameter, which you can see by using debug:

String[] values = new String[0];
ProjectStatus.Test(values);
System.debug(values);
2
  • Sorry to bother you, I tried running with the parameter like you had commented but I am still receiving the following error... "Method does not exist or incorrect signature: void Test() from the type ProjectStatus" Jan 2, 2019 at 20:32
  • @MaxGoldfarb You still apparently missed the parameter; if you had provided a parameter, the error would have looked different.
    – sfdcfox
    Jan 2, 2019 at 20:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .