how can i assign a string to the value of the output text from my controller? Thank you in advance.


public List<schedule__c> a = new List<schedule__c>();
public PageReference check() {


return null;      
public void checkSched(){
    for(teacher__c teacher: [select id,name, First_name__c, Subject__c, Room_assignment__c from teacher__c  ])
       if(teacher.Id == selectedtId)

          string a = ('this is not available for' + teacher.name);



  • gelay -- you're killing yourself with variable naming issues - a is declared as a List<Schedule__c> outside of your method and as an error value in the method. Although these are in different scopes, you only confuse yourself and the community. There are lots of resources on this, see for example - salesforce.stackexchange.com/questions/890/… as well as endless non Apex examples such as iwombat.com/standards/….
    – cropredy
    Feb 17, 2016 at 2:47

1 Answer 1


You need to take a getter setter variable

public string strName {get; private set;}

And in your constructor or method

strName  = 'Test string';

And VF page

<apex:outputText value="{!strName}" />

And you need to use rerender attribute to get updated value of strName

  • @Ratun Paul.But there is rerender tag in OutputText.. Aug 22, 2017 at 9:18
  • @DeepakAgarwal have you confused with rerender and rendered attribute ?
    – Ratan Paul
    Aug 22, 2017 at 9:23
  • no there is rendered att but not rerender in output text.I am using same syntax but unable to get output text on vf page.. Aug 22, 2017 at 13:39

You must log in to answer this question.

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