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
Harjeet Singh 28Harjeet Singh 28 

How I populate field values from a VF page to the site VF page

Hi All,

I have a VF page with standard controller and extension.This page basically used by salesforce user to enter the values.This form has an email field.Upon saving record an email should trigger to external user on the email id specified during record creation.The email whcih an external user receives will have link to the sites which we have created.Now when user copy paste the site link in browser tab then a new VF page will appear will some fields auto populate.
Basically my VF page is up and running.My site is up and running.For Salesforce users and external users I am displaying the same VF page with some sections (used renedring) but I am not able to auto populate the fieldson site VF.
Lets say in my vf page where salesforce users are entering values(name,email,mobile).When they save record the email will go to the email id specified during record creation. When external user receive email which will have link for the external site and go to that external site I want name and email field will be auto puplate this time and external user can only enter their mobile no 
Below is snippet from my VF page():
<apex:page standardController="Driver_Survey__c" extensions="SurveyForDriverController" sidebar="false" lightningStylesheets="true" showHeader="{! $Profile.Name == 'System Administrator' }" >
    
    
    <apex:form > 
       <!--Below section will be sued by the Salesforce user to enther details and save record-->
            <apex:pageBlockSection columns="1" collapsible="false" title="Driver Information"  rendered="{!IF($Profile.Name =='Profile1'|| $Profile.Name =='Profile2' , true, False)}"   >
                <apex:inputField label="Name" value="{!survey.Name__c}" required="true"/>
                <apex:inputField label="Mobile" value="{!survey.Mobile__c}" required="true" />
                <apex:inputField label="Email" value="{!survey.Email__c}" required="true" />
                
				
  
            </apex:pageBlockSection>
        <!--Below section will be visible on Sites for external user-->

             <apex:pageBlockSection columns="1" collapsible="false" title="Driver Information"  rendered="{!IF($Profile.Name=='Transport Questionnaire Profile',true,false)}"  >
                <apex:inputField label="Name1" value="{!survey.Name__c}"/>
                <apex:outputField label="Mobile1" value="{!survey.Mobile__c}"/>
                <apex:outputField label="Email1" value="{!survey.Email__c}"/>
                
					
  
            </apex:pageBlockSection>
         
            <apex:pageBlockButtons >
             
              
                <apex:commandButton value="Save" action="{!doFullSave}"  />
                    
                    <apex:commandButton value="Cancel" action="{!doCancel}" immediate="true"/>
       
            </apex:pageBlockButtons> 
        </apex:pageBlock>
      
    </apex:form>
</apex:page>
Below is my controller(pasting only required snippet):
public class SurveyForDriverController{
    
    //class variables
    public Driver_Survey__c survey{get;set;}
    Public String name{get;set;}
    Public String ordid;


    public GrabSurveyForDriverController(ApexPages.StandardController controller){
         survey=new Grab_Driver_Survey__c();
        survey=(Grab_Driver_Survey__c)controller.getRecord();
          system.debug('message3>>'+survey );
          Id profileId=userinfo.getProfileId();
            String profileName=[Select Id,Name from Profile where Id=:profileId].Name;
            system.debug('ProfileName'+profileName);
        if(profileName=='Grab Transport Questionnaire Profile'){
            survey.Name__c=ApexPages.currentPage().getParameters().get('ordid');
        }
       
    }
   
  
    
    
    public PageReference doFullSave(){
        system.debug('message1>>'+survey );
       	insert survey; 
   
        SendEmail();
        PageReference pageRef = new PageReference('/'+survey.Id);
        pageRef.setRedirect(true);
        return pageRef;  
        }
    
    public PageReference doCancel(){
        PageReference pageRef = new PageReference('/');
            pageRef.setRedirect(true);
            return pageRef;
    }
    public void SendEmail(){

      Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.toAddresses = new String[] { survey.Email__c };
        mail.subject = 'Subject Test Message';
        String body = 'Hi \n  ';
       
        body += + survey.Name__c+ '<br><br>' ;
        body+= +'Request you to kindly fill in the questionnaire'+ '<br><br>';
       body+= +'https://"My siteURL"/myVFpagename;
       
        mail.setHtmlBody(body);
        Messaging.SingleEmailMessage[] mailss =   new List<Messaging.SingleEmailMessage> {mail};
        Messaging.SendEmailResult[] results = Messaging.sendEmail(mailss);
         	if (results[0].success) 
                {
                    System.debug('The email was sent successfully.');
                } else 
                {
                    System.debug('The email failed to send: ' + results[0].errors[0].message);
                }
    }          
}

I am not able to auto populate the name and email on the page which external user will see 

Any help would be greatly appreciated

Kindly help

Mnay thanks in advance
Tad Aalgaard 3Tad Aalgaard 3
If I'm following this correctly I don't think that the link you are creating in the email contains the ordid parameter that your controller is looking for.
Harjeet Singh 28Harjeet Singh 28
Hi Tad,
Thanks you have responded my query.Yes I understand what you are trying to say and tried to implement that way also before I posted on community. 
Below was my approach: I append the URL something like:
1.body+= +'https://"My siteURL"/myVFpagename?ordid
2. Declare ordid as String which takes name,email 
3. Tried to get parameters in constructor

But not getting the results. I assume I am doing something wrong inside the constructor.If you can help me on same it would be great help for me

Many thanks in advance