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
civiccivic 

Function call

i have the following in the class

 

String getsubscriptionGroupId(string conId)

          String subGrpId = "hello";

          return subGrpId;

 

how do i call the same function in my VF Page.

i need the code.

Shashikant SharmaShashikant Sharma

You can not call this directly like you call in apex class, this looks to me a get method

 

so if you will have a control like

 

<apex:outputLabel value="{!subscriptionGroupId}" />

 

this will show the value

just make sure your getsubscriptionGroupId method is public. And also remove that parameter from it. parameter is passed in set method not in get method.

 

Ankit AroraAnkit Arora

I can derive many issues in it.

 

As you have written a get method

 

String getsubscriptionGroupId(string conId)
          String subGrpId = "hello";
          return subGrpId;

 and want to use it on visualforce page then you need to make it look like this :

 

public String getsubscriptionGroupId()
{
          return 'hello';
}

 You need to make it public and you can not pass the parameter in it.

 

But if you want to use it in apex code itself then this will work for you like this :

 

public class t
{ 
    String getsubscriptionGroupId(string conId)
    {
          String subGrpId = 'hello';
          return subGrpId;
    }
    public t()
    {
        String str = getsubscriptionGroupId('test') ;
    }
}

When you write a getter method using on visualforce page then it will act as a property of class but you pass a parameter in it and use it in apex code it will act as a method.

 

Also if you are just getting the value from this property you don't need the set method. Best practice says you should not set the value in get method but there are many instance where you need to fetch the value from database and send it to visuaforce page using get and not set.

 

So when you use this code :

 

public String getsubscriptionGroupId()
{
          return 'hello';
}

 You can get the value on visualforce page like this :

 

<apex:page controller="T">
    {!subscriptionGroupId}
</apex:page>

 Let me know if there is any other use case you want to understand.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page