Skip to main content
New
Stack Overflow Jobs powered by Indeed: A job site that puts thousands of tech jobs at your fingertips (U.S. only). Search jobs

Questions tagged [controller]

A controller is one piece in the Model-View-Controller (MVC) architecture of Visualforce. A controller can be a standard or custom controller and extensions to controllers can written.

Filter by
Sorted by
Tagged with
109 votes
11 answers
42k views

How do I start to debug my own Apex code?

Sometimes questions are posted here that would best be answered by helping the questioner learn how to do their own debugging. (Remember that proverb?) I'd like to have something to link to on this ...
Keith C's user avatar
  • 136k
40 votes
4 answers
51k views

What is the Difference Between Controllers and Extensions?

Can any one explain the usage of controller and extensions in Visualforce? In which scenario we have to use controller and extensions?
Priyanka's user avatar
  • 1,909
33 votes
5 answers
78k views

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

I've built a few apex controllers, and like most people have copied some code from here and there. In the controllers, there's typically an expression that looks like the following: public *var type* ...
ZAR's user avatar
  • 2,043
30 votes
3 answers
64k views

How to access outer class instance variables from inner class in controller?

I have an outer class with an inner class as part of a controller. I have tried setting the instance variables in the outer class as static, which allows the code to compile, but after the controller ...
JimH's user avatar
  • 901
23 votes
2 answers
67k views

how to get a picklist all values in apex controller

I have a Student object and have a pick list field "Student Status" in this object. Status can be Full-Time OR Part Time. Now my requirement is i want this student status list, Part-Time or Full-Time ...
Pramod Kumar's user avatar
  • 5,300
21 votes
1 answer
4k views

Difference between returning null and ApexPages.currentPage()

How is returning null different from returning ApexPages.currentPage() as a result of a controller action?
ipavlic's user avatar
  • 3,736
18 votes
4 answers
6k views

Knowing if a future call is allowed

I'm having an issue where we have some code that can be called anywhere and then it makes an @future call to log a message to an external system. The problem is if this method is called (either ...
Patrick Connelly's user avatar
16 votes
2 answers
19k views

How to send Javascript map as a parameter from lightning component to Apex server controller?

I have a lightning component which enqueues server side action. To that action I need to pass a map as one of the parameters, but it looks like it takes memory address of the object instead. The ...
JaKu's user avatar
  • 357
14 votes
1 answer
6k views

setting default value for properties in controller

I was searching on how to set the default value to a select List input on Visualforce and found the below trick: public String selectedReminderTime {get; set;} {selectedReminderTime = '08:00 AM';} ...
javanoob's user avatar
  • 8,887
13 votes
1 answer
25k views

Reset an Aura attribute to a blank sObject type?

I have an Aura attribute as follows: <aura:attribute name="newItem" type="Camping_Item__c" default="{ 'sobjectType': 'Camping_Item__c', 'Name': '', '...
Shobhit Saxena's user avatar
12 votes
4 answers
28k views

How do I pass a parameter from component to a Visualforce page?

Can I pass a email value from a visualforce component to a Visualforce page? I have used components for reusing Company's logo and few images... <apex:component> <apex:image value="{!$...
MnZ's user avatar
  • 3,170
11 votes
3 answers
6k views

Order of Invocation - Controller Methods (Constructor, Getter, Action Method)

I was browsing through Visual Force Dev cookbook and was trying to understand the sequence of execution of the controller methods ( constructor, getter, action method) while invoking the action ...
KaLi's user avatar
  • 1,519
11 votes
2 answers
4k views

When to use Apex controller vs JS Remoting or REST

When developing a website or mobile hybrid application, what are the benefits of using the standard VisualForce page + Apex Controller design versus using a framework like AngularJS for controller ...
Valyrion's user avatar
  • 1,144
10 votes
3 answers
9k views

Pagination with Lightning Components

I am trying to implement a simple paginator that uses a wrapper object to move between pages, but I am not sure how to get the wrapper class to work in the component controller. Specifically my ...
Mossi2's user avatar
  • 469
10 votes
2 answers
4k views

Custom Controllers - effect of running in System mode

The VisualForce Developer's Guide says: Like other Apex classes, all custom controllers run in system mode. Consequently, the current user's credentials are not used to execute controller logic, ...
Joe's user avatar
  • 3,421
9 votes
2 answers
3k views

What is the $A object in lightning?

I'm starting to learn Lightning development. In the JS controller, out of curiosity, what exactly is the $A object? I see it is used in the context of $A.enqueueAction(...), $A.getCallback(), and $A....
moth's user avatar
  • 454
9 votes
2 answers
13k views

Display header and footer in all PDF pages using VF

My vf page <apex:page renderAs="pdf" Controller="testpdf1"> <head> <style type="text/css" media="print"> @page { size: 8.5in ...
PavanFoxPro's user avatar
  • 1,181
9 votes
5 answers
8k views

Error: The method is referenced by Visualforce Page in salesforce.com. Remove the usage and try again

When a controller has a method or a variable that is referenced in the VF page, and you remove or rename that element in both - page and controller, then when you click save, you get an error saying ...
Kirill Yunussov's user avatar
9 votes
3 answers
8k views

What controls the 'severity' of ApexPages.addMessages(exception)?

I'm trying to crystallize out some 'best practises' for Visualforce Page exception handling. I think, at a minimum, a page should look something like this: <apex:page controller="PageController"&...
Matt and Neil's user avatar
9 votes
1 answer
9k views

Removing rows separately from the Visualforce pageBlockTable list

I created a visualforce page (with controller) that allows adding multiple records to a custom object (master object is account). I can add new rows and save the new records, I'm also pulling ...
Itay B's user avatar
  • 703
9 votes
4 answers
3k views

How do I unit test an Apex controller method for dynamic components?

I have an Apex controller method that returns a Component.Apex.OutputPanel for use in a <apex:dynamicComponent /> tag. How do I do a unit test that asserts that the controller is outputting the ...
user avatar
9 votes
4 answers
19k views

Uncaught TypeError: a.getAttribute is not a function

Scenario: I have a component that has an <aura:renderIf> within an <aura:iteration>. The <aura:iteration> references a component attribute called "selectedItems" to display ...
Bryan's user avatar
  • 427
8 votes
1 answer
3k views

Can't set lightning component controller

I am following the Trailhead "Create a Lightning Component" tutorial and I have reached the part where I have build the controller (Apex) and I am attempting to set the aura:component controller. My ...
David Dawson's user avatar
  • 1,204
8 votes
1 answer
4k views

Visualforce components within components

Fairly new to creating Visualforce components and I'm attempting to reuse some of my front-end mark up with multiple components that used in a parent component. At first I question if this was ...
Xtremefaith's user avatar
  • 4,560
8 votes
1 answer
2k views

How to redirect Visualforce page automatically

I have custom button which when clicked redirects to VF page, VF page calls some controller, But I want as soon as custom button is clicked it should process to VF page waits for 2 secs and then ...
Ashish's user avatar
  • 183
8 votes
1 answer
294 views

In Apex Controllers what is the correct short form way of overriding set; on a variable?

I know the long hand way of doing this is as follows: private String var1; public String getvar1() { return var1; } public void setvar1(String str) { var1 = 'Prefix '+str; } The shorthand way is ...
Venko's user avatar
  • 1,030
8 votes
1 answer
3k views

Assigning VF component attribute to a List controller class variable

I have a VF page using a standard controller, a component, and a custom controller for the component. I am trying to pass a list of sObjects from the standard controller to the component's custom ...
John L's user avatar
  • 81
7 votes
2 answers
36k views

redirect to a page from apex in the constructor

I have a method in the page constructor that checks if a user has access to the page. If not, I want to redirect the user to another "Access Denied" page. I know I can use Pagereferences as part of a ...
Jorjani's user avatar
  • 2,212
7 votes
2 answers
5k views

Test Class SeeAllData=true Annotation

I am creating a test class that will test my controller class which uses almost 5 to 8 objects that has many DML statements like insert and delete, however I am feeling a little bit worried about not ...
Oliver Wendell Carranza's user avatar
7 votes
4 answers
9k views

restful call to external analytics API via visualforce/apex

So I'm trying to access Woopra analytic's restful API via apex/visualforce. I am wondering a couple of things: 1) The API returns a JSON object via the usual POST/GET method... would it be best to ...
gfppaste's user avatar
  • 845
7 votes
2 answers
6k views

AssignTo variable in attribute

I have a visualforce component as below: <apex:component controller="RecordDisplayController"> <apex:attribute name="objectName" description="An Sobject" type="Sobject" required="false" ...
SfdcBat's user avatar
  • 4,811
7 votes
2 answers
3k views

Error Logging Utility and Controllers

I am trying to build a generic logging utility that will store exceptions in a custom object, this in itself is fine. What I am struggling with is using it in Controllers or Getters/Setters due to any ...
Girbot's user avatar
  • 5,465
7 votes
1 answer
4k views

Two constructor in apex controller

Just curious to know what will happen if I have an apex controller with two constructors. Something like this: public wrapperAccountOpportunity(){ fetchData(); } public wrapperAccountOpportunity(...
MIX DML's user avatar
  • 2,442
7 votes
1 answer
10k views

How do you access a wrapper class from a Test class?

I have a VisualForce page which uses a controller. Within the controller I have a couple of wrapper classes which hold various form elements on the page. Everything works great, but now it is time ...
VictorKilo's user avatar
  • 1,089
7 votes
1 answer
18k views

Writing test classes for a custom controller

I'm having trouble writing the tests for the following custom controller. I'm new to SF and I'm simply displaying a list of "future" events on a VF page. It does exactly what I need and I would like ...
penaservices's user avatar
7 votes
2 answers
1k views

JavaScript Remoting and optimal Angular.js architecture

Background I am starting to build more and more apps with angular, inside of a Visualforce container. Since many of the database services rely on some apex logic, the services layer uses JavaScript ...
greenstork's user avatar
  • 14.8k
7 votes
1 answer
1k views

How can I display 1 of 4 panels when a panel is clicked?

I'm trying to display 1 of 4 sections based on a clicks on navigation panels. I know that this could easily be done with a bit of JavaScript but I'd prefer to use the standard Visualforce mechanisms ...
Venko's user avatar
  • 1,030
6 votes
5 answers
7k views

Executing Apex code in controller only for specific profile

How to execute Apex code in controller only for specific profile, like System Administrator? So that when other users visit Visualforce page, the code block would not be skipped?
justasd's user avatar
  • 1,463
6 votes
4 answers
9k views

Error: Could not resolve the entity from <apex:inputField> value binding '{!variable}'

This seems like it should be very simple and I have no idea why it isn't working. I have a VF page with a controller. The controller has the following property (yes, I made sure to save): public ...
Ryan Elkins's user avatar
  • 7,687
6 votes
2 answers
13k views

How to assert a PageReference in Test Method for Visualforce Controller

Given the following test class, how do I assert that the PageReference is returning as intended? Test method: static testmethod testMyMethod(){ campaignmanageclass obj=new campaignmanageclass(); ...
bhagyashri chaudhari's user avatar
6 votes
1 answer
5k views

Controller Class Inheritance vs Multiple Controller Extensions

From reading the docs and dev forums, it seems that having multiple controller extensions can offer the ability to override methods, and keep class size/structure simple. Because these are things ...
Jan Julian's user avatar
  • 2,634
6 votes
2 answers
4k views

Debug ViewState Problems in Force.com Sites VF Pages

We're implementing a complex web application based on force.com Sites and ran into problems with the ViewState size of one of our pages. Now on the platform I would activate Development Mode and the ...
h9nry's user avatar
  • 1,091
6 votes
1 answer
8k views

How to get Record Owner ID from record ID?

I want to get the owner id/ user id of current record. for this what I know, we have to do 2 things. 1) First we have to fetch record ID from URL by using ApexPages.CurrentPage().getparameters()....
Noob_NoVoice's user avatar
  • 2,709
6 votes
2 answers
1k views

Lifecycle of Controllers

I am just wondering about the life cycle of page controllers? How often are than instantiated and is there any configurations which can change this? Is there a method guaranteed to be invoked every ...
More Than Five's user avatar
6 votes
1 answer
1k views

Order of execution of controller method calls during rerender

Let's say we have an apex:commandButton, with immediate="false", and no apex:actionSupport. It's just a standard apex:commandButton inside an apex:form. Additionally, suppose it has a reRender ...
Pittsburgh DBA's user avatar
6 votes
1 answer
3k views

How can I use the html (pass through) attributes in Salesforce

I have create a VF page which is accessible on mobile through which I can take pic and attach it to the selected record. For this I have created a input tag in html <input type="file" accept="...
Anu's user avatar
  • 3,857
6 votes
1 answer
1k views

Setting controller variables not reliable from apex:commandButton

I'm trying to set a variable inside my controller via an actionFunction, which is called by some Javascript, which is initially called by either by an actionPanel (with styleClass='btn') or a ...
Gary Chapman's user avatar
6 votes
3 answers
207 views

Controlling Access to Force.com Site

Is there a way to control who access the force.com site externally besides using IP addresses? I tried using a profile checker: public static String ProfileCheck(){ String ReturnVal; Profile Pro; ...
AlphaBravo's user avatar
6 votes
1 answer
1k views

How can I change the HTTP status code on a Visualforce Page?

I'm trying to develop a Page that given some GET parameters would return HTTP Status 200 or status 400 depending on some inner query. This would be really easy with a RESTful service, but we need ...
Juan Nunez's user avatar
6 votes
2 answers
2k views

How to pass session state between multiple custom controllers

I have a 65 multi step wizard form where i need to collect data on each step and have a previous and next button on each page. I have to store the data on each page and finally at the end store all ...
Buyan Thyagarajan's user avatar

1
2 3 4 5
28