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
RJ12RJ12 

How to pass parameters to Visualforce page from Apex method?

I'm trying to pass parameters from the Apex method to the VF page where I have a VF component. So that I can get the VF component content into the 'pageAsString' variable in the apex method and display that value in an LWC component.

I'm getting the VF component content into the 'pageAsString' variable but the dynamic values are not getting populated.

I tried manually passing record Ids to the VF component inside the VF page and it is working.

I'm unable to pass record Ids dynamically from the Apex method to the VF page.

Below is the code I have tried so far. (There is a lot of code but I just cut down to what is required to understand the question)

If you are wondering why I'm using these many components: I'm trying to preview a visualforce email template body in an LWC component. The visualforce template has a VF component.

//Apex Class
public class SampleController {
 
    public String aId { get;set; }
    public String bId { get;set; }
    
    public static void getACDetails(Id accId, Id ConId) {
        PageReference pageReference = new PageReference('/apex/TestVFPage');
        pageReference.getParameters().put('aId', accId);
        pageReference.getParameters().put('bId', ConId);
        String pageAsString = pageReference.getContent().toString();
    }
}
//VF Page
<apex:page controller="SampleController" showHeader="false" sidebar="false" docType="html-5.0"> <!-- VF Component --> 
<c:ABCTemplateComponent accountId="{!aId}" contactId="{!bId}"/> 
</apex:page>

//VF Component
<apex:component controller="ComponentController" access="global"> 
<apex:attribute name="accountId" assignTo="{!aRecordId}" type="Id" description="some description" /> 
<apex:attribute name="contactId" assignTo="{!cRecordId}" type="Id" description="some description"/> 
</apex:component>

Could anyone help me understand how can I pass values from the Apex method to the VF page?
 
Suraj Tripathi 47Suraj Tripathi 47
Hi,
Please refer to this link -
http://bobbuzzard.blogspot.com/2011/07/passing-parameters-to-apex-method-from.html

I hope you find the above solution helpful. If it does, please mark it as the Best Answer to help others too.

Thanks and Regards,
Suraj Tripathi