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
Daniel BleasdaleDaniel Bleasdale 

My Visual Force Page that uses a custom Apex controller wont show fields

Finally got all the testing done for my Apex controller and got the print layout functioning as I wanted but a huge problem I have encounterd now is that my Visual Force Page isnt showing any data. What must I add to my Visualforce/Apex to show the values that I have in the fields.
User-added image
Ive had this problem before but couldnt figure it out. Here is some information It should be displaying.
User-added image

Here is my apex Class:-
public class PrintableView{   
public Apprentice__c ApprenticeObj{get;set;}
public Programme_Area__c ProgramArea {get;set;}
public Boolean bolPrintableView {get;set;}
       
    public void init() {
   String strPrintableView = ApexPages.currentPage().getParameters().get('print');
   bolPrintableView = (strPrintableView == '1');
  }
  
public PageReference save(){
if(ApprenticeObj != null){
} 
return null;
}
}
Visual Force componet used to make the print function:-
<apex:component controller="PrintableView" allowDML="true">
    public PrintableView(){ 
    ApprenticeObj = new Apprentice__c();
    ProgramArea = new Programme_Area__c ();
    ProgramArea.PA_Code__c = 'P12';
    insert ProgramArea;
    }
</apex:component>
And a small Snippet of the Visualforce Page
<apex:page lightningStyleSheets="True" Controller="PrintableView" title="Learning Agreement" showHeader="{!bolPrintableView}" sidebar="{!bolPrintableView}" action="{!init}">
    <apex:form >
    <apex:outputPanel rendered="{!NOT(bolPrintableView)}">
    <a href="/apex/Apprentice?print=1" target="_blank">Printable View</a>
</apex:outputPanel>

<apex:outputPanel rendered="{!bolPrintableView}">
    <script>
        window.print()
    </script>
</apex:outputPanel>

<apex:pageBlock >
         Learner ID :- <apex:inputField value="{! ApprenticeObj.Learner_Reference_Number__c }"/>
            <apex:pageBlockSection columns="3">
                <apex:inputField value="{! ApprenticeObj.Date_of_Birth__c}"/>
                <apex:inputField value="{! ApprenticeObj.Surname__c}"/>
                <apex:inputField value="{! ApprenticeObj.First_Name__c}"/>
                <apex:inputField value="{! ApprenticeObj.Middle_Other_Names__c}"/>
                <apex:inputField value="{! ApprenticeObj.Previous_Surname__c}"/>
                <apex:inputField value="{! ApprenticeObj.Preferred__c}"/>
                <apex:inputField value="{! ApprenticeObj.Gender__c}"/>
                <apex:inputField value="{! ApprenticeObj.ULN__c}"/>
                <apex:inputField value="{! ApprenticeObj.NI_Number__c}"/>
            </apex:pageBlockSection>
         </apex:pageBlock>

Thankyou for all and any help!

 
Best Answer chosen by Daniel Bleasdale
Raj VakatiRaj Vakati
Update your controller to get the data .. you create a ApprenticeObj  without any values from the DB .. 

Refer this sample code
 
public class PrintableView{   
public Apprentice__c ApprenticeObj{get;set;}
public Programme_Area__c ProgramArea {get;set;}
public Boolean bolPrintableView {get;set;}
       
    public void init() {
   String strPrintableView = ApexPages.currentPage().getParameters().get('print');
   bolPrintableView = (strPrintableView == '1');
   
   ApprenticeObj =[Select Id , Date_of_Birth__c , Surname__c,First_Name__c,Middle_Other_Names__c, Previous_Surname__c ,Preferred__c ,NI_Number__c ,ULN__c from Apprentice__c where Id=:strPrintableView]
  }
  
public PageReference save(){
if(ApprenticeObj != null){
} 
return null;
}
}

 

All Answers

Raj VakatiRaj Vakati
Update your controller to get the data .. you create a ApprenticeObj  without any values from the DB .. 

Refer this sample code
 
public class PrintableView{   
public Apprentice__c ApprenticeObj{get;set;}
public Programme_Area__c ProgramArea {get;set;}
public Boolean bolPrintableView {get;set;}
       
    public void init() {
   String strPrintableView = ApexPages.currentPage().getParameters().get('print');
   bolPrintableView = (strPrintableView == '1');
   
   ApprenticeObj =[Select Id , Date_of_Birth__c , Surname__c,First_Name__c,Middle_Other_Names__c, Previous_Surname__c ,Preferred__c ,NI_Number__c ,ULN__c from Apprentice__c where Id=:strPrintableView]
  }
  
public PageReference save(){
if(ApprenticeObj != null){
} 
return null;
}
}

 
This was selected as the best answer
Shruti SShruti S
Please let me know from where you are invoking the Visualforce page.
Daniel BleasdaleDaniel Bleasdale
The page is being invoked from a button on the Apprentice__c page.

RajV seems to have the fix. I was just wondering would it make more sense for me to put the print function  I created into an Extention and just use the Apprentice__c Standard Controller?
Raj VakatiRaj Vakati
I think you can do URL hacking also for print function if you are on classic but lightning it will not work