1

I have two visualforce page, the first one will ask applicant to enter first, last name and SSN, and then the second page will ask applicant to enter information if the contact is not in our system. How can I make SSN, First and last name show up automatically in the second visualforce page since they have already entered once in the first visualforce page? A great guy has established following code for us and I am just trying to make some small modifications here and there. Any help will be really appreciated.

Here is the first visualforce page(partial):

<apex:page controller="landingPageController">
    <td>
        <apex:inputText value="{!searchSocialSecurityNumber}" />
    </td>
    <td>&nbsp;</td>
    <td>
        <apex:inputText value="{!searchFirstName}" />
    </td>
    <td>
        <apex:inputText value="{!searchLastName}" />
    </td>
    </tr>

    <tr>
        <td>&nbsp;</td>
    </tr>

    <tr>
        <td colspan="4" style="text-align:center; ">
            <apex:commandButton value="Submit" action="{!searchBySocialSecurityNumber}" reRender="contactsArea, theNewButton" />
        </td>
    </tr>
</apex:page>

Here is second visualforce page:

<apex:page controller="newDealCtrl">

       …     
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Contact Information" columns="1">
                <apex:inputField value="{!newContact.FirstName}" required="True"/>
                <apex:inputField value="{!newContact.LastName}" required="True"/>
                <apex:inputField value="{!newContact.SSN__c}" required="True"/>

            </apex:pageBlockSection>
       …
</apex:page>

Here is the apex for the firs page:

public class landingPageController {

    public String searchFirstName {get; set;}
    public String searchLastName {get; set;}
    public String searchSocialSecurityNumber {get; set;}
    public Boolean hasClickedSearch {get; set;}




    public void searchBySocialSecurityNumber() {

        String socialSecurityQueryString = searchSocialSecurityNumber.replaceAll('-', '');
        String firstNameQueryString = '';

        if(searchFirstName != null) {
            if(searchFirstName.length() > 0) {
                firstNameQueryString = '%' + searchFirstName.substring(0, 1) + '%';
            }
        }

        String lastNameQueryString = '';
        if(searchLastName != null) {
            if(searchLastName.length() > 0) {
                lastNameQuerySTring = '%' + searchLastName.substring(0, 1) + '%';
            }
        }
        public PageReference goToTheBlankCreationPage() {
            PageReference PR = Page.create_new_deal;
            PR.setRedirect(True);
            return PR;
        }
    }
}

Here is the apex for second page:

public class newDealCtrl{
    public Account newAcct {get;set;}
    public Contact newContact {get;set;}             

    public newDealCtrl(){
        newAcct= new Account();
        newContact = new Contact();
    }

    public PageReference save(){

        try{

            OpportunityContact__c opptyContact = new OpportunityContact__c();
            newAcct.Type = 'Applicant';
            newAcct.Industry = 'Transportation';

            newContact.AccountId = newAcct.Id;
            Upsert newContact;            
            PageReference PR = Page.landingPage;

                PR.setRedirect(True);
                PR.getParameters().put('reply','a');

                    Return PR;


        }

     }

 }
5
  • 3
    You can use one controller and two pages, that can help you to pass values. Check Chapter 5 in visualforce in practice Aug 19, 2016 at 18:15
  • 2
    An alternate approach - appropriate when separate controllers make sense - is described in this answer to "Connecting multiple VF pages".
    – Keith C
    Aug 19, 2016 at 18:51
  • @KeithC You probably don't want to be transmitting sensitive information like SSNs in the query string, though.
    – Derek F
    Aug 19, 2016 at 19:30
  • When transmitting sensitive information you can AES encrypt the data. This is also useful in shortening the data as well IIRC
    – Eric
    Aug 19, 2016 at 21:22
  • @DerekF Fair point that using URL parameters exposes the data more.
    – Keith C
    Aug 19, 2016 at 22:02

1 Answer 1

1

From what you've shown of the two different controllers, neither uses a standard controller or extends a standard controller for an object. That suggests to me that your simplest solution is to combine the methods from the two into a single controller for use by both pages. Doing that will allow you to store the values you need for the contact name and SSN in the controller view state when moving from the 1st page to the 2nd page. That technique is also much more secure than using a url query string parameter.

You must log in to answer this question.

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