0

I'm a newbie to salesforce. I have 2 Apex class as follows:

public class A {

B bb;

public PageReference save() {

bb = new B();
return bb.pay();
}

}

public class B {

public PageReference pay(){

}

}

I would like to return the PageReference method pay() at class B on class A. Is that possible? Or Are there any other way for me to call the pay() method from class A? Cuz right now, when I call the method from save() it won't redirect me to pay()

Thanks to the kind hearted soul!

5
  • This should have worked. I am assuming that you are calling the Save method from a visualforce page. Have you specified that on the action attribute?
    – Aayush K
    Commented Feb 4, 2015 at 18:51
  • @AAU Hi yes i called the !save from VF page. Yes I use <apex:commandButton action="{!save}" value="Save" rerender="all"> But it doesn't seems to go to the pay() method .. :(
    – newbieyoo
    Commented Feb 4, 2015 at 19:01
  • Actually, this shouldn't work. This code will not compile even. You have no return in your pay() method.
    – dphil
    Commented Feb 4, 2015 at 19:33
  • Like @dphil said, what are you returning from the pay() method?
    – Aayush K
    Commented Feb 4, 2015 at 19:45
  • @dhil, Hi is there any other way that I could call this pay() method?
    – newbieyoo
    Commented Feb 5, 2015 at 7:56

2 Answers 2

1

I'm not sure where you're going with this because the code you posted is pretty vague. Maybe you could make this a static method if you are only calling the PageReference exactly after you're instantiating the object. Here's a way to expedite the call of an instance method. This one goes to a new opportunity.

public class A
{
  public PageReference save()
  {
    return (new B()).pay();
  }
}

public class B
{
  public PageReference pay()
  {
    PageReference pageRef = new PageReference('/006/e');
    pageRef.setRedirect(true);
    return pageRef;
  }
}
0

Make sure you set the redirect to true and that you don't have a rerender on this ajax call.

1
  • No it doesn't work still..
    – newbieyoo
    Commented Feb 5, 2015 at 7:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .