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
104
votes
11answers
35k 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 ...
38
votes
4answers
50k 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?
28
votes
5answers
50k 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* ...
28
votes
4answers
54k 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 ...
22
votes
2answers
56k 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 ...
21
votes
1answer
3k views

Difference between returning null and ApexPages.currentPage()

How is returning null different from returning ApexPages.currentPage() as a result of a controller action?
18
votes
3answers
5k 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 ...
15
votes
2answers
15k 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 ...
13
votes
1answer
23k 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': '', '...
12
votes
4answers
24k 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="{!$...
11
votes
3answers
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 ...
11
votes
2answers
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 ...
10
votes
3answers
8k 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 ...
10
votes
2answers
3k 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, ...
9
votes
2answers
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....
9
votes
1answer
4k 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';} ...
9
votes
5answers
6k 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 ...
9
votes
1answer
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 ...
9
votes
3answers
7k 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"&...
9
votes
4answers
2k 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 ...
9
votes
4answers
11k 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 ...
8
votes
1answer
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 ...
8
votes
1answer
3k 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 ...
8
votes
1answer
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 ...
8
votes
1answer
222 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 ...
8
votes
1answer
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 ...
7
votes
4answers
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 ...
7
votes
2answers
2k 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 ...
7
votes
1answer
8k 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 ...
7
votes
1answer
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 ...
7
votes
2answers
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 ...
7
votes
1answer
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 ...
6
votes
2answers
30k 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 ...
6
votes
5answers
6k 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?
6
votes
2answers
4k 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 ...
6
votes
4answers
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 ...
6
votes
2answers
5k 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" ...
6
votes
2answers
10k 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 ...
6
votes
2answers
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(); ...
6
votes
1answer
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 ...
6
votes
2answers
3k 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 ...
6
votes
1answer
7k 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()....
6
votes
2answers
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 ...
6
votes
1answer
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 ...
6
votes
1answer
2k 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="...
6
votes
1answer
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 ...
6
votes
3answers
177 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; ...
6
votes
1answer
910 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 ...
6
votes
2answers
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 ...
6
votes
0answers
632 views

“Variable not visible” error in production, but fine in development

My managed package works fine in development. When it runs from client orgs, as an installed managed package, this error occurs: "VisualForce Error Variable is not visible: [PackagePrefix....

1
2 3 4 5
27