You need to sign in to do that
Don't have an account?
Phuc Nguyen 18
Apex pass list results to another method
Hello All,
Having an issue passing a list to another method within a class.
So I have this code:
This code below is not working. The list is null
Any suggestions would be greatly appreciated.
Cheers,
P
Having an issue passing a list to another method within a class.
So I have this code:
public list<Cand__c> tc1; Cand__c tc1 = [my query]How fo I pass the results of tc1 to another method in the class?
This code below is not working. The list is null
public void summary ( list<Cand__c> new cand)
Any suggestions would be greatly appreciated.
Cheers,
P
As per my understanding you're trying to pass a list from 1 method to another of sObjecttype=Cand__c.
Declare a list at class level
Thanks,
Ashish Singh.
All Answers
If you are trying to pass the data from one method to another method then use the below syntax:
Public class className{
Public list<Cand__c> tc1(){
List<Cand__c> tc1list = [your query];
summary(tc1list);
return tc1list;
}
public void summary( list<Cand__c> cand)(){
system.debug( ' === ' + cand);
}
}
if you are not trying to pass the data from one method to another method but want the local property data inside method then you can access like below :
Public class className{
Public list<Cand__c> tc1 = [your query];
public void summary()(){
system.debug( ' === ' + tc1 );
}
}
Thanks,
Maharajan.C
Thnak you for the reply, I do not think I can use the voide since I have a void method.
And I have to keep it a void method so any ideas for a nother approach?
Thanks you for your time,
P
As per my understanding you're trying to pass a list from 1 method to another of sObjecttype=Cand__c.
Declare a list at class level
Thanks,
Ashish Singh.
it need to be like this I am iterating through an Id and geetting all of the records asociated
So wil lpassing to the other method look like
When I have it as It tells me that the variable does not exist.
for example: And note. My query is looking at parent and all of its related child records. When I run a query like below. tci is being put inside a list right?
Any guidance is appreciated. Seem to be going in a circle.
Thanks
P
Here is what I am seeing: When I run the debug log I can see there is a value in tc1 at this line: system.debug('debug tc1 ' + tc1)
But it appears to be only a single record since it is not a list.
But when I change tc1 to a list I cannot even deploy the code since it does not see the the fields in the list.
I am really stuck so if anyone has any suggesitons please advise.
Thank you,
P