+ Start a Discussion
Joe HayesJoe Hayes 

String is showing as blank. I don't know why?

Hi,

This should be pretty basic,
I have a vf page to display the value of the name field of a record in a custom object called 'Certification_Accredited_Centres__c'
I also have a controller that the vf page uses.

The URL passes a paramater 'centreId' which is the id of the record I am trying to get the name value of.

At the moment all I am getting on the vf page is "Assesments taken at      " <-- the string is blank

VF Page (not complete)
<apex:page controller="AddingAssessmentsController>
<h3>
<apex:outputText value="Assesments taken at {!asscen}"/>
</h3>
</apex:page>
Controller (not complete)
public class AddingAssessmentsController {

    public Id centreId;
    
    public String asscen{get;set;}
    
    public AddingAssessmentsController(){
        centreId = ApexPages.currentPage().getParameters().get('centreId');
        String asscen = [SELECT name from Certification_Accredited_Centres__c WHERE id =: centreId].name;
    }
}

Please can someone tell me why the {!asscen} is blank in the vf page?

Thanks
Joe 
 
Best Answer chosen by Joe Hayes
GulshanRajGulshanRaj
You have declared asscen variable inside too. Remove declaration part.
Here is correct code:
public class AddingAssessmentsController {

    public Id centreId;
    
    public String asscen{get;set;}
    
    public AddingAssessmentsController(){
        centreId = ApexPages.currentPage().getParameters().get('centreId');
        asscen = [SELECT name from Certification_Accredited_Centres__c WHERE id =: centreId].name;
    }
}

If this resolve your problem, please mark this as solved , so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks & Regards
Gulshan Raj
LinkedIn
(https://www.linkedin.com/in/gulshan-raj-a26b0640/)
Twitter (https://twitter.com/gulshan_bittoo)

All Answers

GulshanRajGulshanRaj
You have declared asscen variable inside too. Remove declaration part.
Here is correct code:
public class AddingAssessmentsController {

    public Id centreId;
    
    public String asscen{get;set;}
    
    public AddingAssessmentsController(){
        centreId = ApexPages.currentPage().getParameters().get('centreId');
        asscen = [SELECT name from Certification_Accredited_Centres__c WHERE id =: centreId].name;
    }
}

If this resolve your problem, please mark this as solved , so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks & Regards
Gulshan Raj
LinkedIn
(https://www.linkedin.com/in/gulshan-raj-a26b0640/)
Twitter (https://twitter.com/gulshan_bittoo)
This was selected as the best answer
Joe HayesJoe Hayes
Ahhhh! Of course I have. I knew it would be simple!

Thanks Gulshan.