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?
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 ...
28
votes
5answers
49k 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* ...
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 ...
2
votes
2answers
10k views

System.QueryException: List has more than 1 row for assignment to SObject

I am trying to write a VF page to list all the id and name columns from a custom object but found an error "List has more than 1 row" in the VF page. Can anyone tell me what have I done wrong? VF ...
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 ...
1
vote
2answers
4k views

What is Interface method in salesforce

I have a very simple doubt regarding this Interfaces in sales force, Actually what it says is "This class will have a method but the body will be empty. And body for this method will be provided in ...
0
votes
2answers
2k views

show checkbox before every contact using wrapper class

I'm trying to fetch the contact record and showing on page using its showing error Unknown property EditContact_controller.wrapperClass.conList Which thing is unknown. here is my controller ...
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="{!$...
0
votes
2answers
31k views

How to get the text fields values in the controller class without using any scripts

Im having a VF page it has some text fields and one button . On clicking the button , the values in the text field should be passed to the controller class to save in the database . Can this be ...
0
votes
1answer
1k views

How do I enqueue an action after receiving value from first action lightning controller

I have an action from which I get an Id from the server. After I get an Id from the server I want to use this vale in a second action. But I cant seen to get this to work. From My research I ...
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?
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, ...
4
votes
3answers
3k views

Which of these error handling patterns is more efficient?

I'm working on a cleanup of some older apex code, and I've noticed two distinct patterns being used to handle errors when saving records. One uses a try-catch block to try to update the records, and ...
5
votes
1answer
1k views

Unit Test Big Objects

I have an APEX controller that writes to a Big Object. How do I unit this? During an insert operation insert I get an error: Unsupported External Object Operations.
5
votes
2answers
8k views

How do you check email format in Apex?

If I have a form for candidates to apply for certain jobs online, when a candidate enters his email and submits the form, I want my controller to validate the email format that was entered. Can ...
2
votes
0answers
1k views

How to use a javascript function from an external script in lightning controller?

I want to load a function from external script and then use it in the component controller: example of a function that i tried to call from the component controller (from the Init method specifically)...
0
votes
1answer
2k views

Test Class for a Custom Controller

How do you make a test class for custom controller? My search results involves this but trying to apply it in my test class only create too many error that I don't understand. public static ...
0
votes
1answer
136 views

Visualforce Controller Test Class - 0% Coverage

I have built a Visualforce page that allows the user to quickly choose a file and attach it to the record without having to go to an additional page. I have been attempting to build a test class for ...
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 ...
4
votes
1answer
3k views

Combine multiple PDF's together and attach them in a mail?

As of now , all i have is a VF page which renders as a PDF and it needs Account ID to be passed to generate a PDF . Is there a way wherein i can group all the PDF's into a single PDF ? Should i change ...
2
votes
1answer
2k views

Test class fails throws different types of error as :STANDARD_PRICE_NOT_DEFINED, No standard price defined for this product

Can any one help me out with test class code coverage .I have written a test class for a controller having wrapper class,but the code covearage is zero. Any help very much appreciated. Different ...
2
votes
2answers
3k views

Creating Salesforce Person Accounts via Visualforce

I have recently activated and configured Person Accounts in our salesforce org. We will be using these within the service console and also integrating Postcode Anywhere for address lookups. To ...
2
votes
1answer
5k views

How can I override clone correctly?

I have been trying to override the functionnality of the standard clone button. Writing in a custom controller, I tried: public PageReference clone() { new MyClass.MyException('HAAAAAA'); ...
1
vote
1answer
347 views

Visualforce Components: When your controller extends an abstract class, can you override the parent instance?

At the time I still have not received any feedback about my previous question so I went ahead with a different approach to my problem. Bare with me part of my problem might be because of how I changed ...
1
vote
1answer
697 views

Is apex getter method runs only once regardless of how many times it is called on VF page?

I have a basic question. I have a big VF page with many sections which render/hide based on some flags. The flags are set in constructor of controller extension and are mostly depend on the logged-in ...
1
vote
1answer
1k views

APEX Unit tests hello world

I am trying to learn how to do APEX testing but all the tests in the documentation are too complex and I can't find an example of a simple APEX Controller that is a Hello World Test. I have this APEX ...
1
vote
2answers
2k views

VF controller system context versus Sites Guest User object permissions

I'm trying to clarify VF controller context versus Sites Guest User permissions on Contact record. From everything I've read, a VF controller using "without sharing" operates in the system context. ...
0
votes
2answers
86 views

custom setting not displying correct picklist values based on the condtion

i have a custom setting called product and under that i created two fields called and other is string field BD__c. i want to display picklist value based on string matching record. my custom setting ...
0
votes
2answers
12k views

Redirect page to record

So this is my controller which create new event and save event. in this i have hardcoded page redirect link '/a3I/o'. i dnt want this to hardcoded. I want to do something like it will redirect to ...
0
votes
1answer
4k views

Error: Read only property 'StoreFrontController.productDisplay.quantity'

Error: Read only property 'StoreFrontController.productDisplay.quantity' Visualforce : <apex:page controller="StoreFrontController" tabStyle="Product__c" > <apex:form> <...
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 ...
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(); ...
4
votes
2answers
18k views

Multiple custom objects in a single VisualForce page

How would I go about using two custom objects (unrelated to each other) in a single VF page? Would I set the first object as a standard controller and use an extension controller for the second, or ...
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 ...
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 ...
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 ...
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 ...
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 ...
3
votes
2answers
12k views

Get text input value with the help of HTML and pass it to controller

I have designed my VF UI using HTML. I have a doubt, is it possible to get a Value in HTML (Input Type:Text) box and pass it to controller ? Please find the codes below My current VF page ...
2
votes
2answers
3k views

How do I persistent data between VF pages (that change the view state) that share one controller?

I have multiple VF pages that share one controller. My problem is that: 1.) If I set PageReference.setRedirect(false), it doesn't redirect the pages 2.) If I set PageReference.setRedirect(true), it ...
2
votes
0answers
492 views

How to dynamically query in Remote Object Model?

See my code comments in my controller for what I'm trying to do. This article might help as well: Overriding Default Remote Objects Operations Page <apex:page> <apex:remoteObjects &...
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 ...
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 ...
5
votes
1answer
553 views

Visualforce Component Getter/Setters from a Base Class

Originally I wanted to attempt using the interface notation as an added layer of abstraction for this project for the time being I'm going with what I believed to be a simpler solution, unfortunately ...
2
votes
1answer
724 views

Records truncated end of page in PDF

I have an apex PDF page. There are five different tabpanels to show records. Now when number of records increases the last record of last panel in a page gets segregated to the next page. In such ...
2
votes
1answer
809 views

Error Message in Visualforce page

I have a visualforce page which has a apex:pagemessage tag. A method on the controller is checking if a field in the visualforce page is valid. I want to display an error message but I do not want ...
2
votes
1answer
2k views

Custom New Button that creates record of specific type and parent record in Visualforce Controller (No URLFOR!)

Sorry for the lengthy title. But I want to make sure that I was not able to solve my problem with the standard answers to questions like this. I have a CustomObject_c that has many record types and a ...
1
vote
0answers
481 views

CurrentPage getParameters() is empty the first time I post to a page

I have a VisualForce/APEX page that I am posting to through a form. I send over a list of contacts as a single string. When I get to the other page I use the following code to retrieve the post ...