You need to sign in to do that
Don't have an account?
Manish Anand 10
Calling a method from controller extension to a custom controller.
How do I call a method from the controller extension to a custom controller?
Below is the controller extension class:-
public with sharing class ControllerEx1
{
public final Account acct;
public ControllerEx1(Apexpages.StandardController stdcon) {
this.acct=(Account)stdcon.getRecord();
}
public Account returnAccount()
{
return acct;
}
public PageReference Add_Con_Or_Opp()
{
PageReference pr = new PageReference ('/apex/ContactsOrOpportunity');
pr.setRedirect(true);
return pr;
}
}
I want to call returnAccount() from above CE to below controller method.
global without sharing class MyController2
{
public Account acnt{get;set;}
ControllerEx1 c=new ControllerEx1();
acnt=c.returnAccount();
}
It throws an Compile Error: unexpected token: '=' at the last line
Below is the controller extension class:-
public with sharing class ControllerEx1
{
public final Account acct;
public ControllerEx1(Apexpages.StandardController stdcon) {
this.acct=(Account)stdcon.getRecord();
}
public Account returnAccount()
{
return acct;
}
public PageReference Add_Con_Or_Opp()
{
PageReference pr = new PageReference ('/apex/ContactsOrOpportunity');
pr.setRedirect(true);
return pr;
}
}
I want to call returnAccount() from above CE to below controller method.
global without sharing class MyController2
{
public Account acnt{get;set;}
ControllerEx1 c=new ControllerEx1();
acnt=c.returnAccount();
}
It throws an Compile Error: unexpected token: '=' at the last line
Please find the modified code:
But you may need to change according to your requirement.
Please do let me know if it helps you.
Regards,
Mahesh
All Answers
NOTE: This code has not been tested and may contain typographical or logical errors
Please find the modified code:
But you may need to change according to your requirement.
Please do let me know if it helps you.
Regards,
Mahesh