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
Prasun BanerjiPrasun Banerji 

How to call a managed Visual Force page from another custom Visual force page

I have a installed managed package. The package has a visual force page which is put as a button on the detailed page. The controller for the viusal force page is not defined global and hence I cannot see that code. 

I also have another custom button on the list view of the same object. I would like to call the visual force page of the installed package after my own logic in the custom button (visual force page with controller). 

Is there any way to do that?

Thanks,

Vj@88Vj@88
Make sure Apex action method has return type PageReference and you can call that manged visualforce page after your logic executes by using return statement like below 

return new PageReference('/apex/MangedVisualforcePageName');
Prasun BanerjiPrasun Banerji
Do you mean I need to do this in my custom controller to this page reference?
Prasun BanerjiPrasun Banerji
Here is the code of my custom Visual force page : 

<apex:page standardController="ECS__Product__c" extensions="SampleCheckedController" action="{!updateSampleChecked}">
  <apex:pageMessages id="pageMessages" />
</apex:page>

Here is the my controller : 

public class SampleCheckedController {
    public ECS__Product__c objEcsProduct{get;set;}                                 
    public List<ECS__Product__c> lstEcsProduct{get;set;}                           
    public List<ECS__Product__c> updatelstEcsProduct{get;set;}                    
    public String getrecordId{get;set;}                                           

    public SampleCheckedController(ApexPages.StandardController controller)       
    {                                                                             
    
        getrecordId = ApexPages.currentPage().getParameters().get('ids');        
        String[] splittedECSId= getrecordId.split(',');                            
        Set<Id> splitsids = new Set<Id>();                                         
        
        for(Integer i=0;i<splittedECSId.size();i++)                                 
        {                                                                          
          splitsids.add(splittedECSId[i]);                                         
        }                                                                         
    
        if(splitsids!=null)                                                       
        {                                                                          
          lstEcsProduct= [select id,name,CostPriceChecked__c,ECS__Unit_Weight__c,PeopleVox__PeopleVox_Last_Updated__c,Parcel_Type__c,ECS__Length__c,Sample_Checked__c,ECS__Width__c,ECS__Height__c,ECS__EAN__c from ECS__Product__c where id In: splitsids]; // Get all records based on Splitted ids and holding them all to List 
        }                                                                         
    
    }                                                                              
     
     
    public void updateSampleChecked()
    {                                                                             
       updatelstEcsProduct = new List<ECS__Product__c>();                          
     
       for(Integer i=0;i<lstEcsProduct.size();i++)                                 
       {                                                                          
          if(lstEcsProduct[i].CostPriceChecked__c==true && lstEcsProduct[i].ECS__Unit_Weight__c!=null && lstEcsProduct[i].Parcel_Type__c!=null && lstEcsProduct[i].ECS__Length__c!=null && lstEcsProduct[i].ECS__Width__c!=null && lstEcsProduct[i].ECS__Height__c!=null && lstEcsProduct[i].ECS__EAN__c!=null)    //checking the Fields Of ECS__Product__c Object cannot be null 
          {                                                                        
             lstEcsProduct[i].Sample_Checked__c='Yes';                            
             lstEcsProduct[i].PeopleVox__PeopleVox_Last_Updated__c=null;            
             updatelstEcsProduct.add(lstEcsProduct[i]);                            
             
              
             ApexPages.Message myMsg = new ApexPages.Message(ApexPages.severity.CONFIRM,'Sample Checked Successfully');                           
             ApexPages.addMessage(myMsg);
          }                                                                        
          else
          {                                                                       
              ApexPages.Message myMsg = new ApexPages.Message(ApexPages.severity.ERROR,'Product Can Not Be Marked As Sample Checked. Please Make Sure All Fields Are Populated'); //Adding Error Message to be displayed on VisualForce Page 
              ApexPages.addMessage(myMsg);
          }                                                                         
        
       }                                                                           
       
       if(updatelstEcsProduct.size()>0)
       {                                                                           
         update updatelstEcsProduct ;                                              
         
       }       
        
       for(Integer i=0;i<lstEcsProduct.size();i++)                              
       {
             // This is where I must call that managed visual force page to run through all the products passing the ID one by one. The code of the visual force page 
             //taking only one id as its on the detailed page, and this button is on list view.
       }
    }                                                                              

}                  


I am trying to call the managed VF page in the below section as commented. I hope that clarifies the issue.                                                                
Vj@88Vj@88
Change the method public void updateSampleChecked
to public PageReference updateSampleChecked

and at the end of the method add a return statement.


 
Prasun BanerjiPrasun Banerji
This is now working if I choose on record in the list view and click my button. The challenge now is to how to fire the same logic for all my selected records. 

So my button is on list view which runs on the selected record, the managed vf page is on the detailed page , so it takes only one ID. How, can I loop it through all my selected records using page reference.
Vj@88Vj@88
What kind is that managed Packed button? if its is detailed Page button. You cannot select multiple records as in list view.
Vj@88Vj@88
*Package
Prasun BanerjiPrasun Banerji
Yes the visual force page I am trying to call from my custom button is on the detailed page (using extension controller).

So you dont see any workaround to call that logic using some loop ?
Vj@88Vj@88
Now you are asking, I got a question? How do you manage to have a detail button on list view page?
Your code is using StandardController, not a StandardSetController. Can you confirm whether your code works for multiple records?
 
Prasun BanerjiPrasun Banerji
My custom button is on list view page using custom controller. Once I select multiple records , it updates few fields on those records. The managed package button is on the detail page on the same object using extension controller which when clicked send the data to an external system. 

So, once I click my custom button on list view page after selecting multiple records, it must call that package VF page logic to pass those records using API to the external system.
Vj@88Vj@88
Can you provide package VF page code?
Prasun BanerjiPrasun Banerji
This is the code for the packaged VF page code :


<apex:page standardController="ECS__Product__c" extensions="PeopleVox.UpdatePVXProductsController" action="{!updatePVX}"> <apex:pageMessages id="pageMessages" />
</apex:page>
 
Vj@88Vj@88
Instead of going to VF page Try calling the extended managed Apex class from your code by giving one ID at a time as input using a loop