function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
swain 10swain 10 

passing paramter / value from one apex controller to another apex controller

  Set<id> resultId = new Set<id>();

I need to send the resultId to another apex controller , so that i can use that in where ID IN condition
originalangoriginalang
You can access this list by calling the class from your other class:
 
// the first class

public class classOne {

    public static Set<id> getSet() {
        Set<id> resultId = new Set<id>();
        // add values to set
        return resultId;
    }

}
 
// the second class

public class classTwo {
    Set<id> setFromClassOne = classOne.getSet();
}
Prashant Pandey07Prashant Pandey07
Hi Swain,


You can use two approaches:
 
1.Use Static methods

You cannot use controller2 instance methods here

public class controller2 
{
    public static string method2(string parameter1, string parameter2) {
        // put your static code in here            
        return parameter1+parameter2;
    }
    ...
}
In a separate class file call method2()

// this is your page controller
public class controller1
{
    ...
    public void method1() {
        string returnValue = controller2.method2('Hi ','there');
    }
}
2.Create an instance of the other class

public class controller2 
{
    private int count;
    public controller2(integer c) 
    {
        count = c;
    }

    public string method2(string parameter1, string parameter2) {
        // put your static code in here            
        return parameter1+parameter2+count;
    }
    ...
}

public class controller1
{
    ...
    public void method1() 
    {
        controller2 con2 = new controller2(0);
        string returnValue = con2.method2('Hi ','there');
    }
}
If your methods are in a package with a namespace

string returnValue = mynamespace.controller2.method2();

--
Thanks,
Prashant