You need to sign in to do that
Don't have an account?
gopi biswal
Single Apex Class for Multiple controller classes.
I have one Apex Class. I want to access that Apex Class variable from other controller classes. If I'll change the value from any controller, then that same value should be available to all controller.
You can use inheritance with Apex Classes. refer an example below
OR else
you can declare static variable on an object with public access specifier and access those on other classes, So same value will be reflected on refered classes.
All Answers
Class public virtual class GenericControllerClass1 {
public static integer A{get;set;}
public GenericControllerClass1(){
System.debug('$$$$$$$$$$$$$$ Main Class%%%%%%%%%%%%%'+ A);
}
}
My First Controller is.....
public class TestControllerClass1 extends GenericControllerClass1{
public TestControllerClass1(){
GenericControllerClass1.A = 998;
System.debug('###############'+ GenericControllerClass1.A);
}
public Pagereference CallMe(){
Return page.P2;
}
}
My Second Controller is .........
public class TestControllerClass2 extends
GenericControllerClass1{
public TestControllerClass1 TC{get;set;}
public TestControllerClass2(){
System.debug('================='+GenericControllerClass1.A);
}
}
My First Page P1......
<apex:page controller="TestControllerClass1" >
<Apex:form >
<apex:pageBlock title="Testing For Virtual Class">
<apex:pageBlockSection title="Input Value in Virtual Class">
<apex:commandButton value="Redirect" action="{!CallMe}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</Apex:form>
</apex:page>
My Second page P2......
<apex:page controller="TestControllerClass2">
<apex:pageBlock title="Testing For Virtual Class">
<apex:pageBlockSection title="Output Value in Virtual Class">
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
My both Vf pages refer to the different Controller ... both the controller also refer to one Main-Class. I'm using DebugLog
to check the value of second controller. But the value itself is showing 'null' there .I want to access the same value at Controller2 which I have inserted in my controller1... Where both the controller extends the Main controller variable.
You can use inheritance with Apex Classes. refer an example below
OR else
you can declare static variable on an object with public access specifier and access those on other classes, So same value will be reflected on refered classes.