2

I am currently working on a visualforce page that is supposed to display values in PDF upon saving. But unfortunately, I am unable to fetch what I've inputted in the form. Meanwhile, here's the controller:

public with sharing class EnrollmentCardCX2 {

    private ApexPages.StandardController parentRecord;
    public Parent__c pg1 {get;set;}
    public Parent__c pg2 {get;set;}
    public List<Parent__c> parentlist {get;set;}
    public Student__c st1 {get;set;}
    public Student__c st2 {get;set;}
    public Student__c st3 {get;set;}
    public Student__c st4 {get;set;}
    public List<Student__c> studentlist {get;set;} 
    public Other_Children__c oc1 {get;set;}
    public Other_Children__c oc2 {get;set;}
    public Other_Children__c oc3 {get;set;}
    public Other_Children__c oc4 {get;set;}
    public List<Other_Children__c> childlist {get;set;}
    public List<Enrollment_Form__c> enrollmentList {get;set;}
    public List<Enrollment_Form__c> enrollment {get;set;}
    public List<Enrollment_Form__c> enrollmentqry {get;set;}
    public String title {get;set;}
    public Boolean Page1 {get;set;}
    public Boolean Page2 {get;set;}



    public EnrollmentCardCX2(ApexPages.StandardController controller) {
        //title = 'STUDENT(S) ENROLLING' + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + 'OTHER CHILD(REN)';
        Page1 = true;
        Page2 = false;
        parentRecord = controller;
        pg1 = new Parent__c();
        pg2 = new Parent__c();
        parentlist = new List<Parent__c>();
        st1 = new Student__c();
        st2 = new Student__c();
        st3 = new Student__c();
        st4 = new Student__c();
        studentlist = new List<Student__c>();
        studentlist.add(st1);
        studentlist.add(st2);
        studentlist.add(st3);
        studentlist.add(st4);
        oc1 = new Other_Children__c();
        oc2 = new Other_Children__c();
        oc3 = new Other_Children__c();
        oc4 = new Other_Children__c();
        childlist = new List<Other_Children__c>();
        childlist.add(oc1);
        childlist.add(oc2);
        childlist.add(oc3);
        childlist.add(oc4);




        //parentmethod();
    }
    public class NewLine {
        public String NewLine {
            get { return '\r\n'; }
            set;
            }
    }
    public void proceed() {

        List<String> nameconcat = new List<String>();
        List<Student__c> newstudentlist = new List<Student__c>();
        List<Other_Children__c> newchildrenlist = new List<Other_Children__c>();
        enrollment = new List<Enrollment_Form__c>();
        enrollmentqry = new List<Enrollment_Form__c>();
        ApexPages.getMessages().clear();

        if(pg1.Relationship_1__c == null && pg2.Relationship_2__c == null){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, 'Please accomplish the form before proceeding'));
            return;
        }

        if(pg1.Relationship_1__c != null && pg1.Cell_Phone__c == null){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, 'Please key in required details'));
            return;
        }

        if(pg1.Relationship_1__c != null && pg1.Email__c == null){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, 'Please key in required details'));
            return;
        }

        if(pg2.Relationship_2__c != null && pg2.Cell_Phone__c == null){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, 'Please key in required details'));
            return;
        }

        if(pg2.Relationship_2__c != null && pg2.Email__c == null){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, 'Please key in required details'));
            return;
        }

        if(pg1 != null) {

            Parent__c father = new Parent__c();
            father.Relationship_1__c = pg1.Relationship_1__c != '' ? pg1.Relationship_1__c : '';
            father.Salutation__c = pg1.Salutation__c != '' ? pg1.Salutation__c : '';
            father.First_Name__c = pg1.First_Name__c != '' ? pg1.First_Name__c : '';
            father.Middle_Name__c = pg1.Middle_Name__c != '' ? pg1.Middle_Name__c : '';
            father.Last_Name__c = pg1.Last_Name__c != '' ? pg1.Last_Name__c : '';
            father.Address__c = pg1.Address__c != '' ? pg1.Address__c : '';
            father.Home_Phone__c = pg1.Home_Phone__c != '' ? pg1.Home_Phone__c : '';
            father.Cell_Phone__c = pg1.Cell_Phone__c != '' ? pg1.Cell_Phone__c : '';
            father.Email__c = pg1.Email__c != '' ? pg1.Email__c : '';
            father.Employer_Organization__c = pg1.Employer_Organization__c != '' ? pg1.Employer_Organization__c : '';
            father.Position__c = pg1.Position__c != '' ? pg1.Position__c : '';
            father.Work_Phone__c = pg1.Work_Phone__c != '' ? pg1.Work_Phone__c : '';

            if(father.Relationship_1__c != null) {
                upsert father Email__c;
                parentlist.add(father);
            }
        }

        if(pg2 != null) {

            Parent__c mother = new Parent__c();
            mother.Relationship_2__c = pg2.Relationship_2__c != '' ? pg2.Relationship_2__c : '';
            mother.Salutation__c = pg2.Salutation__c != '' ? pg2.Salutation__c : '';
            mother.First_Name__c = pg2.First_Name__c != '' ? pg2.First_Name__c : '';
            mother.Middle_Name__c = pg2.Middle_Name__c != '' ? pg2.Middle_Name__c : '';
            mother.Last_Name__c = pg2.Last_Name__c != '' ? pg2.Last_Name__c : '';
            mother.Address__c = pg2.Address__c != '' ? pg2.Address__c : '';
            mother.Home_Phone__c = pg2.Home_Phone__c != '' ? pg2.Home_Phone__c : '';
            mother.Cell_Phone__c = pg2.Cell_Phone__c != '' ? pg2.Cell_Phone__c : '';
            mother.Email__c = pg2.Email__c != '' ? pg2.Email__c : '';
            mother.Employer_Organization__c = pg2.Employer_Organization__c != '' ? pg2.Employer_Organization__c : '';
            mother.Position__c = pg2.Position__c != '' ? pg2.Position__c : '';
            mother.Work_Phone__c = pg2.Work_Phone__c != '' ? pg2.Work_Phone__c : '';

            if(mother.Relationship_2__c != null) {
                upsert mother Email__c;
                parentlist.add(mother);
            }
        }


        for(Student__c stloop : studentlist) {
            String concat = '';
            if(stloop.First_Name__c != '' && stloop.Middle_Name__c != '' && stloop.Last_Name__c != '') {
                concat = stloop.First_Name__c.deleteWhitespace() + stloop.Middle_Name__c.deleteWhitespace() + stloop.Last_Name__c.deleteWhitespace();
            }
            nameconcat.add(concat);
        }

        List<Student__c> checkStudents = [SELECT ID, Name, First_Name__c, Middle_Name__c, Last_Name__c, Student_Name__c, Grade_Level__c FROM Student__c WHERE Student_Name__c IN : nameconcat];
        Integer stnum = 0;

        /*


        //Set<Student__c> setst = new Set<Student__c>();

        //for(Student__c nameloop : studentlist) 
        for(stnum=0; stnum < studentlist.size(); stnum++) {
            for(Student__c studentloop : checkStudents) {
                if(studentlist[stnum].First_Name__c != '' && studentlist[stnum].Last_Name__c != '') {
                    system.debug('studentlist[stnum] first condition >> ' + studentlist[stnum]);
                    if(studentlist[stnum].First_Name__c != studentloop.First_Name__c && studentlist[stnum].Last_Name__c != studentloop.Last_Name__c) {
                        system.debug('studentlist[stnum] >> ' + studentlist[stnum]);
                        system.debug('studentloop >> ' + studentloop);
                        Student__c student = new Student__c();
                        student.First_Name__c = studentlist[stnum].First_Name__c != '' ? studentlist[stnum].First_Name__c : '';
                        student.Middle_Name__c = studentlist[stnum].Middle_Name__c != '' ? studentlist[stnum].Middle_Name__c : '';
                        student.Last_Name__c = studentlist[stnum].Last_Name__c != '' ? studentlist[stnum].Last_Name__c : '';
                        student.Grade_Level__c = studentlist[stnum].Grade_Level__c != null ? Integer.valueof(studentlist[stnum].Grade_Level__c) : null;
                        if(parentlist.size() > 0) {
                            for(Parent__c parentloop : parentlist) {
                                if(parentloop.Relationship_1__c != null && parentloop.Relationship_2__c == null) {
                                    student.Parent_Father__c = parentloop.id;
                                }
                                if(parentloop.Relationship_2__c != null && parentloop.Relationship_1__c == null) {
                                    student.Parent_Mother__c = parentloop.id;
                                }
                            }
                        }
                        newstudentlist.add(student);
                    } else {
                        system.debug('stnum : ' + stnum + ' ' + studentlist[stnum].First_Name__c + ' >> ' + studentloop.First_Name__c);
                        studentlist.remove(stnum);
                    }
                }        
            }
        }

        if(newstudentlist.size() > 0) {
            insert newstudentlist;
        }
        */
        for(Other_Children__c other : childlist) {
            if(other.Name != '') {
                Other_Children__c newchild = new Other_Children__c();
                newchild.Name = other.Name;
                newchild.Date_of_Birth__c = other.Date_of_Birth__c;
                if(parentlist.size() > 0) {
                    for(Parent__c parentloop : parentlist) {
                        if(parentloop.Relationship_1__c != null && parentloop.Relationship_2__c == null) {
                            newchild.Father__c = parentloop.id;
                        }
                        if(parentloop.Relationship_2__c != null && parentloop.Relationship_1__c == null) {
                            newchild.Mother__c = parentloop.id;
                        }
                    }
                }
                newchildrenlist.add(newchild);
            }
        }
        if(newchildrenlist.size() > 0) {
            insert newchildrenlist;
        }
        system.debug('newstudentlist1 >> ' + newstudentlist.size() + ' ' + newstudentlist);
        for(Student__c addstudents : checkStudents) {

            newstudentlist.add(addstudents);
        }
        system.debug('newstudentlist2 >> ' + newstudentlist.size() + ' ' + newstudentlist);

        enrollment = createEnrollmentForm(newstudentlist);

        Set<ID> eid = new Set<ID>();

        for(Enrollment_Form__c loopid : enrollment) {
            eid.add(loopid.id);
        }

        enrollmentqry = [SELECT ID, Name, Student_Name__c FROM Enrollment_Form__c WHERE ID IN : eid];

        Page1 = false;
        Page2 = true;
        sendPdf();
    }

    public PageReference queryStudent() {
        system.assertequals(studentlist + ' >> ' + st1,'test');

        return null;

    }

    public List<Enrollment_Form__c> createEnrollmentForm(List<Student__c> students) {
        system.debug('students >> ' + students.size() + ' >> ' + students);
        enrollmentList = new List<Enrollment_Form__c>();

        for(Student__c loopStudent : students) {
            Enrollment_Form__c newForm = new Enrollment_Form__c();
            newForm.Student__c = loopStudent.id;
            if(parentlist.size() > 0) {
                for(Parent__c parentloop : parentlist) {
                    if(parentloop.Relationship_1__c != null && parentloop.Relationship_2__c == null) {
                        newForm.Parent_Guardian1__c = parentloop.id;
                    }
                    if(parentloop.Relationship_2__c != null && parentloop.Relationship_1__c == null) {
                        newForm.Parent_Guardian2__c = parentloop.id;
                    }
                }
            }
            enrollmentList.add(newForm);
        }
        system.debug('enrollmentList >> ' + enrollmentList.size() + ' >> ' + enrollmentList);
        if(enrollmentList.size() > 0) {
            insert enrollmentList;


        }

        return enrollmentList;
    }


    public PageReference sendPdf(){
        //public Set<ID> eid{get;set;}

        PageReference pdf = Page.EnrollmentPDFPage;
        //pdf.getParameters().put('id', enrollmentList);

        Blob body;

        try {
            body = pdf.getContent();
        }catch (VisualforceException e) {
            body = Blob.valueOf('baklushiee');
        }

        Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
        attach.setContentType('application/pdf');
        attach.setFileName('baklushiee.pdf');
        attach.setInline(false);
        attach.Body = body;


        List<String> newEMail = new List<String>();
        newEmail.add('latosa.gizelle@gmail.com');
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setUseSignature(false);
        mail.setToAddresses(newEmail);
        mail.setSubject('Baklushie Sample');
        mail.setHtmlBody('Please check the attachment.');
        mail.setFileAttachments(new Messaging.EmailFileAttachment[]{ attach });


        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

        //ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Email with PDF sent to '+email));

        return null;
    }

    public class parentWrapper {

        public Parent__c parent {get;set;}

        public parentWrapper() {
            Parent__c parent = new Parent__c();
        }
    }
} 

And here's the visualforce page:

<apex:page standardController="Enrollment_Form__c" extensions="EnrollmentCardCX2" sidebar="false" showHeader="false" renderAs="pdf">
    <apex:form >
         <apex:pageBlock >

            <apex:pageBlockTable value="{!enrollmentList}" var="enroll" border="2">
                <apex:column value="{!enroll.Name}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form> 
</apex:page>

Thanks in advance.

Here's the other page calling the proceed method...

vf page: EnrollmentCardPage2

<apex:page standardController="Parent__c" extensions="EnrollmentCardCX2" sidebar="false" 

showHeader="false">
    <!--
    <script>
        function setRequired() {
            if(document.getElementById('{!$Component.theForm.block1.cp.cp1}').value == '' || 

document.getElementById('{!$Component.theForm.block1.email.email1}').value == '') {
                document.getElementById('{!$Component.theForm.block1.cp.cp1}').value = '0';
                document.getElementById('{!$Component.theForm.block1.email.email1}').value = '';
                reRenderBlock();
                }
        }
    </script>
    -->
    <style>
        #divblock {
            margin: auto;
            width: 57%;
        }
        #header {
            margin: auto;
            width: 50%;
        }
        #image {
            margin: auto;
            width: 50%;
        }
        #divresult {
            margin-top: 10%;
            margin-left: 20%;
            width: 57%;
        }
        p {
            font-size: large;
        }
        rescolumn {
            font-size: large;
        }
    </style>

    <apex:form id="theForm" rendered="{!Page1}">
        <!--INSERT BR HERE FOR LOGO-->
        <div id="header">
            <apex:sectionHeader title="    FAMILY INFORMATION SHEET AY 2015 — 2016"/>
        </div>
        <div id="image" align="center">
            <apex:image id="theImage" value="{!$Resource.logo}" width="100" height="100"/>
        </div>
        <div id="divblock">
        <apex:pageBlock id="block1">
            <apex:pageBlockSection id="showMsg">
                    <apex:Messages style="color: red;"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection >
                <apex:inputField label="Please select relationship: " value="{!

pg1.Relationship_1__c}"/>
                <apex:inputField label="Please select relationship: " value="{!

pg2.Relationship_2__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection >
                <apex:inputField value="{!pg1.Salutation__c}"/>
                <apex:inputField value="{!pg2.Salutation__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection >
                <apex:inputField value="{!pg1.First_Name__c}"/>
                <apex:inputField value="{!pg2.First_Name__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection >
                <apex:inputField value="{!pg1.Middle_Name__c}"/>
                <apex:inputField value="{!pg2.Middle_Name__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection >
                <apex:inputField value="{!pg1.Last_Name__c}"/>
                <apex:inputField value="{!pg2.Last_Name__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection >
                <apex:inputField value="{!pg1.Address__c}"/>
                <apex:inputField value="{!pg2.Address__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection >
                <apex:inputField value="{!pg1.Home_Phone__c}"/>
                <apex:inputField value="{!pg2.Home_Phone__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection id="cp">
                <apex:inputField id="cp1" label="*Cellphone" value="{!pg1.Cell_Phone__c}"/>
                <apex:inputField label="*Cellphone" value="{!pg2.Cell_Phone__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection id="email">
                <apex:inputField id="email1" label="*Email" value="{!pg1.Email__c}"/>
                <apex:inputField label="*Email" value="{!pg2.Email__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection >
                <apex:inputField value="{!pg1.Employer_Organization__c}"/>
                <apex:inputField value="{!pg2.Employer_Organization__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection >
                <apex:inputField value="{!pg1.Position__c}"/>
                <apex:inputField value="{!pg2.Position__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection >
                <apex:inputField value="{!pg1.Work_Phone__c}"/>
                <apex:inputField value="{!pg2.Work_Phone__c}"/>
            </apex:pageBlockSection>
            <p>* School announcements and communication will be sent to this number and 

address.</p>
        </apex:pageBlock>
        </div>
        <div id="divblock" align="center">
        <apex:pageBlock >

            <apex:pageBlockSection collapsible="false" title="STUDENT(S) ENROLLING" >

                <apex:pageBlockTable value="{!studentlist}" var="sl" title="STUDENT(S) ENROLLING" 

width="10%">
                    <apex:column headerValue="First Name">
                        <apex:inputText value="{!sl.First_Name__c}"/>
                    </apex:column>
                    <apex:column headerValue="Middle Name">
                        <apex:inputText value="{!sl.Middle_Name__c}"/>
                    </apex:column>
                    <apex:column headerValue="Last Name">
                        <apex:inputText value="{!sl.Last_Name__c}"/>
                    </apex:column>
                    <apex:column headerValue="Grade Level">
                        <apex:inputText value="{!sl.Grade_Level__c}"/>
                        <!--
                            <apex:actionSupport action="{!queryStudent}" event="onchange" 

rerender="verified"/>
                        </apex:inputText>
                        -->
                    </apex:column>
                    <!--<apex:column id="verified" rendered="{}">Verified</apex:column> --> 
                </apex:pageBlockTable>

            </apex:pageBlockSection>
            <apex:pageBlockSection collapsible="false" title="OTHER CHILD(REN)" columns="4">
                <apex:pageBlockTable value="{!childlist}" var="cl" title="OTHER CHILD(REN)">

                    <apex:column headerValue="Name">
                        <apex:inputText value="{!cl.Name}"/>
                    </apex:column>
                    <apex:column headerValue="Date of Birth">
                        <apex:inputfield value="{!cl.Date_of_Birth__c}"/>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        <h5>To the best of my knowledge, the information submitted on this form is true and 

correct. &nbsp;</h5>
        <apex:commandButton action="{!proceed}" title="Proceed" value="Proceed"/>
        </apex:pageBlock>
        </div>


    </apex:form>
    <apex:form id="resultForm" rendered="{!Page2}">
        <div id="divresult">
            <apex:pageBlock >
                <p>You have now successfully accomplished the pre-enrollment form</p>
                <p>This is your reference number for each student being enrolled: </p>

                <apex:pageBlockTable value="{!enrollmentqry}" var="e">
                    <apex:column styleClass="rescolumn" headerValue="Name" value="{!

e.Student_Name__c}"/>
                    <apex:column styleClass="rescolumn" headerValue="Reference Number" 

value="{!e.Name}"/>
                </apex:pageBlockTable>

                <p>Please keep a copy of the reference number and present it to the Registrar</p>
                <p><b>Thank you!</b></p>
                <p>Click here to go back to the Everest Website</p>
            </apex:pageBlock>
        </div>

    </apex:form>
</apex:page>
  • 1
    From where you are calling your proceed method? – Santanu Halder Feb 24 '16 at 6:55
1

Your two vf pages are having different StandardController due to which the Extension class is being re-initiated after redirection to the 2nd page. So your list variable enrollmentList is having no values in the 2nd page.

You should be using same standardController in both the pages. If thats not possible let me know I will try to find other ways to pass the values to the 2nd page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.