45 votes
Accepted

Apex Controllers: What do the get; set; do?

Visualforce requires a "getter" and "setter" to reference a variable in the controller or extension. Without a getter or setter, even public or global variables cannot be referenced in Visualforce ...
  • 444k
17 votes

Apex Controllers: What do the get; set; do?

What you are seeing with {get;set;} is an example of automatic properties. From the Apex Documentation on Automatic Properties. Properties do not require additional code in their get or set ...
11 votes

VF controller redirect to another page

I figured out that I can use apex:page action="". VF: <apex:page controller="demoController" action="{!redirect}"/> Controller: public PageReference redirect(){ if(p == null){ ...
  • 415
11 votes

Passing URL parameters from VF page to custom controller

When passing parameters in a URL, you can grab the parameter values in your Visualforce Controller by using: String thecaseID = System.currentPageReference().getParameters().get('caseID');
10 votes
Accepted

Best practices for custom controller actions

Salesforce's MVC is much different than ASP.NET in that with Salesforce, controllers are used with VisualForce pages which relies on a View State which is limited to 135 kb. So, what to do in a ...
  • 40.5k
10 votes
Accepted

Visualforce components within components

Can use the controller? Perhaps set a controller and pass the parent controller to the construct or somehow? Yes, you may use the controller using apex:attribute. The data type of the attribute ...
  • 444k
9 votes
Accepted

Variable is not visible

You cannot assign to a property AccLinks = (kvl != null && kvl.Value__c != null ? kvl.Value__c : 'some_url'); if that property does not have a setter method declared. To make the property ...
  • 88.1k
7 votes

Apex Controllers: What do the get; set; do?

This was answered on SF dev forums: Reg: Get and set Methods That post linked to a great aticle on the behavior of the default get/set methods: Getter and setter methods - What are they??
6 votes

custom controller with extension

It is possible to have an extension for a custom controller. Let's say my custom controller is this: public with sharing class MyController { ... } My extension could then have a contructor that ...
  • 19.2k
6 votes

Unknown constructor for visualforce controller

The zero-argument constructor is the "default constructor", but you only get it "for free" if you don't include any other constructors. Once you do, the zero-argument constructor has to be explicitly ...
  • 444k
6 votes
Accepted

Why do I get a String to System.SelectOption conversion error?

You should change public SelectOption RemoveReason {get;set;} to public String RemoveReason {get;set;} since the value of <apex:selectList>resolves to a String (it is independent of the <...
  • 2,700
6 votes

Why are you forced to have an empty method to use a method with input parameters?

I find it far simpler to use the assignTo attribute to set my parameters: public class MyController { public transient String src { get; set; } public PageReference MyControllerFunction() { ...
  • 444k
6 votes
Accepted

Displaying an error message on a visualforce page

You need to rerender pageMessages section by commandButton's attribute <apex:pageBlock> <apex:pageMessages id="msgId"/> <apex:commandButton name="Submit" action="{!exchangeInv}...
6 votes
Accepted

Difficulty creating test class on custom controller for table VF page that lists records from custom object

That's a good start. You're inserting one record in your test class. The problem is, you don't even call your controller in your test, so it can't be test. Your code is never executed. So after ...
  • 7,218
5 votes

System.QueryException: List has no rows for assignment to SObject

This basically means your query doesn't return any results. It may be because there are not records for that ID or that ID is not passed in the URL. Initialize the account before you hit the query.
  • 937
5 votes
Accepted

Test Class for Chart Controller

Your test would just instantiate the class and request the list: @isTest static void test() { PieChartController ctrl = new PieChartController(); PieChartController.PieWedgeData[] data = ctrl....
  • 444k
5 votes

Complete list of Standard Field Validation Error Messages

The strings are version and language dependent. However, there is a way to find which codes are valid for a particular release: go into Setup > Develop > API, generate the Enterprise WSDL, and find ...
  • 444k
4 votes
Accepted

Test Class for a VF Page Controller w/ Void Method

Testing void methods on controllers is not that different from none-void methods, first take a look at the Salesforce topic, Testing Custom Controllers and Controller Extensions. In the case of a ...
4 votes
Accepted

Constructor not invoked for Custom Controller. Any suggestions of what is wrong?

Constructors do not have a return value. Remove void and it'll work, i.e. public MasterDataSyncController() { System.debug('Inside Constructor...'); }
4 votes

VF controller redirect to another page

You can use cookies Set cookie Cookie elementMsg = new Cookie('msg','true','/apex/pageYouAreGoingToUse',10,false); Add to the current page ApexPages.currentPage().setCookies(new Cookie[]{...
  • 241
4 votes

Apex Controllers: What do the get; set; do?

public *var type* someName { get { // this block equals to: // public *var type* getSomeName() // work with someName return someName; } set { ...
  • 687
4 votes

Passing URL parameters from VF page to custom controller

Simply use this inside your method: String caseID = Apexpages.currentPage().getParameters().get('caseID'); And then use caseID for anything you want.
  • 1,977
4 votes
Accepted

Reference a child field in grid or create grid from standard controller

You can indeed reference a child in pure Visualforce. Note that if you want just one record, you don't get to choose which one will be displayed (it will probably be the oldest record, but no ...
  • 444k
4 votes
Accepted

Implementing CompareTo In An Inner Class That Needs Outer Class Data

You can pass in a reference to the controller class in e.g. the constructor: public class WEvent implements Comparable { private ActivityListAttemptController controller; public Event e {get; ...
  • 131k
4 votes
Accepted

How to solve the apex:attribute and assignTo naming conflict?

Using generic terms on one side or the other can help. So instead of rentalContract, use record (single instance of an SObject) or, instead of rentalContractId, use recordId. Even these two alone give ...
  • 144k
4 votes
Accepted

Is it possible to use a field set with a custom controller?

It is completely possible: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_dynamic_vf_field_sets.htm <apex:page standardController="Account"> <apex:repeat value=...
  • 53.3k
4 votes
Accepted

finishLocation seems to work, retUrl does not

Looking at how that parameter is cased in other parts of the system, I see retURL. These url parameters are case-sensitive, and code looking for retURL will not find a retUrl parameter.
  • 144k
4 votes
Accepted

Where can I find a documentation of Lightning server-side controller's response?

My understanding is the response object param coming back into the callback function is nothing but a representation of the Aura Action object. So you will have all of the properties and methods of ...
4 votes

How to repeatedly poll a server-side controller for an action in a Lightning Component?

Since the actions are asynchronous, they will not execute in the order you expect. Your code works, you just need to you leave your console open long enough and you will see batches of server side ...
  • 19.5k
4 votes
Accepted

How to repeatedly poll a server-side controller for an action in a Lightning Component?

So I've finally figured it out. It looks like it's possible to repeatedly poll the server-side controller. For the first, I put setTimeout inside of the action's callback, at the bottom of function's ...

Only top scored, non community-wiki answers of a minimum length are eligible