You need to sign in to do that
Don't have an account?
Abi V 4
How to pass the list from one method to another method in controller.
I have the different methods in controller and it is fetching the user.name based login details.
Controller is having the different methods and each method want to check the user.name details in where clause of soql.
Please let me know how to write a method and to hold the user.name details and use the same in all the methos where clause.
Controller is having the different methods and each method want to check the user.name details in where clause of soql.
Please let me know how to write a method and to hold the user.name details and use the same in all the methos where clause.
That way one variable can be accessed by any number of methods.
Sample:
Mark this as Best Answer, if this helps solve your problem.
All Answers
There are many ways to achive this. but i will sugeet you to add a Parameter in your controller method "String CurrentUserName".
When you call that method , pass Userinfo.getUserName() for paramter "CurrentUserName".
Example :
public with sharing class PassParameterClass {
Public void callMethod() {
String userName=userinfo.getUserName();
QueryMethod(userName);
QueryMethod2(userName);
}
public void QueryMethod(String CurrentUserName) {
List<COntact> conList= new List<COntact> ();
try {
conList=[select id ,firstname from Contact where owner.username=:CurrentUserName];
} catch (Exception e) {
ApexPages.addMessages(e);
message = 'Whoops! An error occurred -- ' + e.getMessage();
}
}
public void QueryMethod2(String CurrentUserName) {
List<Account> accList= new List<Account> ();
try {
accList=[select id ,name from Account where owner.username=:CurrentUserName];
} catch (Exception e) {
ApexPages.addMessages(e);
message = 'Whoops! An error occurred -- ' + e.getMessage();
}
}
}
But in my case QueryMethod and QueryMethod2 returing list values to vf page and diaplying in table .So is it the right way to do?
That way one variable can be accessed by any number of methods.
Sample:
Mark this as Best Answer, if this helps solve your problem.