Create List of Strings from Another List of Object Records












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!










share|improve this question




















  • 2




    What was your exec anon code? Could you edit the code in to your question?
    – sfdcfox
    Jan 2 at 20:15










  • @sfdcfox updated the post, but here is the code I ran... ProjectStatus.Test();
    – Max Goldfarb
    Jan 2 at 20:18


















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!










share|improve this question




















  • 2




    What was your exec anon code? Could you edit the code in to your question?
    – sfdcfox
    Jan 2 at 20:15










  • @sfdcfox updated the post, but here is the code I ran... ProjectStatus.Test();
    – Max Goldfarb
    Jan 2 at 20:18
















1












1








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!










share|improve this question















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!







apex list developer-console developer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 20:17







Max Goldfarb

















asked Jan 2 at 20:13









Max GoldfarbMax Goldfarb

83




83








  • 2




    What was your exec anon code? Could you edit the code in to your question?
    – sfdcfox
    Jan 2 at 20:15










  • @sfdcfox updated the post, but here is the code I ran... ProjectStatus.Test();
    – Max Goldfarb
    Jan 2 at 20:18
















  • 2




    What was your exec anon code? Could you edit the code in to your question?
    – sfdcfox
    Jan 2 at 20:15










  • @sfdcfox updated the post, but here is the code I ran... ProjectStatus.Test();
    – Max Goldfarb
    Jan 2 at 20:18










2




2




What was your exec anon code? Could you edit the code in to your question?
– sfdcfox
Jan 2 at 20:15




What was your exec anon code? Could you edit the code in to your question?
– sfdcfox
Jan 2 at 20:15












@sfdcfox updated the post, but here is the code I ran... ProjectStatus.Test();
– Max Goldfarb
Jan 2 at 20:18






@sfdcfox updated the post, but here is the code I ran... ProjectStatus.Test();
– Max Goldfarb
Jan 2 at 20:18












2 Answers
2






active

oldest

votes


















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();





share|improve this answer























  • Your modification wouldn't work as is, missing variable definition.
    – sfdcfox
    Jan 2 at 20:22










  • Fixed, thanks @sfdcfox
    – gNerb
    Jan 2 at 20:23










  • @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"
    – Max Goldfarb
    Jan 2 at 20:30












  • I updated my code with copy pasta, please give that a try.
    – gNerb
    Jan 2 at 20:45






  • 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
    – Max Goldfarb
    Jan 2 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);





share|improve this answer





















  • 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"
    – Max Goldfarb
    Jan 2 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 at 20:54











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "459"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f245240%2fcreate-list-of-strings-from-another-list-of-object-records%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









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();





share|improve this answer























  • Your modification wouldn't work as is, missing variable definition.
    – sfdcfox
    Jan 2 at 20:22










  • Fixed, thanks @sfdcfox
    – gNerb
    Jan 2 at 20:23










  • @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"
    – Max Goldfarb
    Jan 2 at 20:30












  • I updated my code with copy pasta, please give that a try.
    – gNerb
    Jan 2 at 20:45






  • 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
    – Max Goldfarb
    Jan 2 at 20:57


















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();





share|improve this answer























  • Your modification wouldn't work as is, missing variable definition.
    – sfdcfox
    Jan 2 at 20:22










  • Fixed, thanks @sfdcfox
    – gNerb
    Jan 2 at 20:23










  • @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"
    – Max Goldfarb
    Jan 2 at 20:30












  • I updated my code with copy pasta, please give that a try.
    – gNerb
    Jan 2 at 20:45






  • 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
    – Max Goldfarb
    Jan 2 at 20:57
















3












3








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();





share|improve this answer














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();






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 2 at 20:42

























answered Jan 2 at 20:18









gNerbgNerb

5,835734




5,835734












  • Your modification wouldn't work as is, missing variable definition.
    – sfdcfox
    Jan 2 at 20:22










  • Fixed, thanks @sfdcfox
    – gNerb
    Jan 2 at 20:23










  • @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"
    – Max Goldfarb
    Jan 2 at 20:30












  • I updated my code with copy pasta, please give that a try.
    – gNerb
    Jan 2 at 20:45






  • 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
    – Max Goldfarb
    Jan 2 at 20:57




















  • Your modification wouldn't work as is, missing variable definition.
    – sfdcfox
    Jan 2 at 20:22










  • Fixed, thanks @sfdcfox
    – gNerb
    Jan 2 at 20:23










  • @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"
    – Max Goldfarb
    Jan 2 at 20:30












  • I updated my code with copy pasta, please give that a try.
    – gNerb
    Jan 2 at 20:45






  • 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
    – Max Goldfarb
    Jan 2 at 20:57


















Your modification wouldn't work as is, missing variable definition.
– sfdcfox
Jan 2 at 20:22




Your modification wouldn't work as is, missing variable definition.
– sfdcfox
Jan 2 at 20:22












Fixed, thanks @sfdcfox
– gNerb
Jan 2 at 20:23




Fixed, thanks @sfdcfox
– gNerb
Jan 2 at 20:23












@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"
– Max Goldfarb
Jan 2 at 20:30






@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"
– Max Goldfarb
Jan 2 at 20:30














I updated my code with copy pasta, please give that a try.
– gNerb
Jan 2 at 20:45




I updated my code with copy pasta, please give that a try.
– gNerb
Jan 2 at 20:45




1




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
– Max Goldfarb
Jan 2 at 20:57






@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
– Max Goldfarb
Jan 2 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);





share|improve this answer





















  • 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"
    – Max Goldfarb
    Jan 2 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 at 20:54
















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);





share|improve this answer





















  • 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"
    – Max Goldfarb
    Jan 2 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 at 20:54














1












1








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);





share|improve this answer












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);






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 2 at 20:18









sfdcfoxsfdcfox

249k11191426




249k11191426












  • 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"
    – Max Goldfarb
    Jan 2 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 at 20:54


















  • 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"
    – Max Goldfarb
    Jan 2 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 at 20:54
















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"
– Max Goldfarb
Jan 2 at 20:32




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"
– Max Goldfarb
Jan 2 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 at 20:54




@MaxGoldfarb You still apparently missed the parameter; if you had provided a parameter, the error would have looked different.
– sfdcfox
Jan 2 at 20:54


















draft saved

draft discarded




















































Thanks for contributing an answer to Salesforce Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f245240%2fcreate-list-of-strings-from-another-list-of-object-records%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents