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
shra1_devshra1_dev 

custom action for standardcontroller

Hi,

i want to  create a custom action '{!toadd}' for customObject 'UserProfiles__c' in the vf page.

 

i hav written the following code:

 

/* visualforce page  */

<apex:page standardController="UserProfile__c" extensions="LeaveAppClass">
    <div align="center" style="font-family:forte;font-size:18pt;color:brown;background:wheat">
        <h1>Leave Application</h1>
    </div><hr/>
    <apex:form >
        fromadd :{!UserProfile__c.emailID__c}<br/>
        toadd :{!toadd}<br/>
        subject :<apex:inputtext id="subject" size="40"/><br/>
    </apex:form>
</apex:page>

 

/* Extension class LeaveAppClass */

public class LeaveAppClass
{   
    ApexPages.StandardController con;
    public LeaveAppclass(ApexPages.StandardController controller)
    { 
        con = controller;
    }
    public String toadd()
    { 
        String emailID;
        Userprofile__c ucon = [select emailID__c from Userprofile__c where Role__c =: 'HR'];
        hremailID = ucon.emailID__c;       
        return emailID;       
    }
}

 

I am getting an error as:

ErrorError: Unknown property 'UserProfile__cStandardController.toadd' 

 

what could be the problem. I am new Visualforce and apex....help me

Best Answer chosen by Admin (Salesforce Developers) 
SSRS2SSRS2

Hello shra1_dev

 Change 

 

public String toadd()
    { 
        String emailID;
        Userprofile__c ucon = [select emailID__c from Userprofile__c where Role__c =: 'HR'];
        hremailID = ucon.emailID__c;       
        return emailID;       
    }

 to 

 

   public String getToadd()
    { 
        String emailID;
        Userprofile__c ucon = [select emailID__c from Userprofile__c where Role__c =: 'HR'];
        hremailID = ucon.emailID__c;       
        return emailID;       
    }

 

-Suresh

 

All Answers

SSRS2SSRS2

Hello shra1_dev

 Change 

 

public String toadd()
    { 
        String emailID;
        Userprofile__c ucon = [select emailID__c from Userprofile__c where Role__c =: 'HR'];
        hremailID = ucon.emailID__c;       
        return emailID;       
    }

 to 

 

   public String getToadd()
    { 
        String emailID;
        Userprofile__c ucon = [select emailID__c from Userprofile__c where Role__c =: 'HR'];
        hremailID = ucon.emailID__c;       
        return emailID;       
    }

 

-Suresh

 

This was selected as the best answer
shra1_devshra1_dev

thanks ssrs2..... but why need to mention 'get'.

 

please post the links to refer on that

sfoxsfox

I also have the same question. Why do we use the prefix 'get'?

It means we can't use our own name for a method?

:(

SSRS2SSRS2

Hello shra1_dev;

  Visualforce markup can use the following types of controller extension and custom controller methods:

  • Action
  • Getter
  • Setter

for more info

    pages_controller_methods.htm

 

-Suresh

shra1_devshra1_dev

thank u suresh......I'll refer those

aballardaballard

You can also use Apex class properties (as described in the Apex Reference.   In this case there is no get/set prefix added.