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
Pravi_1133Pravi_1133 

method return type for field type text.

Hi,

I have declared a field "Description__C" and itsdata type is "TEXT".

I am trying to return this field value using a <apex:outputText value={a.Description}/>. But I am getting error with resturn type.

VF page:

<apex:pageBlockTable value="{!lstDspMrch}" var="Prd">
                  <apex:column headerValue="Description">
                   <apex:outputText value="{!Prd.Desc}" /> </apex:column>
 </apex:pageBlockTable>

Controller:
Public String Desc{
            get
            {
                return Merchnd.Desc__c;
                
            }
     }

Error message:
Error Error: clsApexEx2 Compile Error: unexpected token: 'String' at line 36 column 15

Thanks in advance for your help.
Best Answer chosen by Pravi_1133
Sonam_SFDCSonam_SFDC
Hi,

In the controller - you need to define the get method as a method get() - please check the following doc for code snippet:
http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_methods.htm


All Answers

Sonam_SFDCSonam_SFDC
Hi,

In the controller - you need to define the get method as a method get() - please check the following doc for code snippet:
http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_methods.htm


This was selected as the best answer
Pravi_1133Pravi_1133
Thank you So much Sonam!
After changing it as a getter method my code is working. 

Below code works perfectly fine.

Public String getDesc()
        {
           return Merchnd.Desc__c;
        }

If I had declared my Desc__C as textarea data type, then my code would have worked (return type string works).
My question is if I want to code like I mentioned in my question, then what is the return type for data type TEXT.

Thanks once again.

---Praveen.



Sonam_SFDCSonam_SFDC
Hi Praveen,

Even when you have the data type as text for the field - you can choose the return type for the method as String.