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
Ravi kumar 292Ravi kumar 292 

How to call the Pagereference method from Apex Class

Hi all,

I have two classes say A and B. Pagereference method is in class B. Now i want to call the method in the class A.

exp:

Public class A{
    //i want to call the method here
}

Public class B{
  Public Pagereference C(){
    //some data

}


Please help me on this
Thanks in advance..
Amit Chaudhary 8Amit Chaudhary 8
please check below post
1) http://amitsalesforce.blogspot.in/2015/07/custom-popup-in-salesforce-visualforce.html

One Small example for you :-
Apex class.
public with sharing class CustomPopupController {

    public boolean showPopup {get;set;}
    
    public CustomPopupController ()
    {
        showPopup = false;
    }
    
    public PageReference openPopup()
    {
        showPopup = true;
        return null;
    }
    
    public PageReference Cancel()
    {
        showPopup = false;
        return null;
    }
    

}
Page
<apex:page controller="CustomPopupController">
<style type="text/css">
    .popupBackground{
        background-color:black;
        opacity: 0.20;
        filter: alpha(opacity = 20);
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        z-index: 9998;
    }
    .custPopup{
        background-color: white;
        border-width: 2px;
        border-style: solid;
        z-index: 9999;
        left: 50%;
        padding:10px;
        position: absolute;
        width: 500px;
        margin-left: -250px;
        top:100px;
    }

</style>
<apex:form >
 <apex:pageBlock > 

 <apex:commandButton action="{!openPopup}" value="Open Popup" />
 
 <apex:outputPanel id="tstpopup" rendered="{!showPopup}">
                <apex:outputPanel styleClass="popupBackground" layout="block" />
                    <apex:outputPanel styleClass="custPopup" layout="block" >
                        <center>
                              Hello this is Custom pop-Up<BR></BR>
                             <apex:commandButton value="Save"  action="{!Cancel}" />
                             <apex:commandButton value="Cancel" action="{!Cancel}" />
                        </center>
                 </apex:outputPanel>
 </apex:outputPanel>

</apex:pageBlock>
</apex:form>
</apex:page>


Let us know if this will help you
 
ShivaKrishna(Freelancer)ShivaKrishna(Freelancer)
Hi Ravi,

you can do some thing like this

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

hope it works

make sure these points
1) you should call that from pagereference method only 
2) make the called method as static 
3) setRedirect as true

let me know, if it helps you or need help :)
shiva.sfdc.backup@gmail.com
DeepthiDeepthi (Salesforce Developers) 
Hello Ravi,

You can call a method from one class(say class A) into another(say class B) by creating an instance for class A  in class B. Please check the below sample code.
global with sharing class A{
    public List<Account> method1(){
        for(Account a : [select Name from Account limit 10]){
        System.debug(a);
        }
        return null;
    }
}
 
global with sharing class B{
    public List<Account> method2(){
        System.debug('Hello World');
        A instance = new A();    // creating instance for class A 
        return instance.method1();  // calling the method of class A
    }
}

Hope this helps you! 
Best Regards,
Deepthi