Skip to main content
24 votes
Accepted

How to set record type of records while saving the records?

SUMMER '18 UPDATE You can now use the getRecordTypeInfosByDeveloperName() to get a Record Type Id by Developer Name without spending a SOQL query. This should be the preferred approach going forward ...
smukov's user avatar
  • 5,613
10 votes

Build a String for Database.query

The best way to avoid this problem is to use binding syntax if you need to use dynamic SOQL - it is easier to get right and cleaner to read. Importantly it also eliminates the risk of a SOQL Injection ...
Keith C's user avatar
  • 136k
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 ...
David Reed's user avatar
  • 93.2k
7 votes
Accepted

Redirect to another VF page while using a Same Controller?

The page's view state is preserved when the following conditions hold: The new page uses the same controller as the old page. The new page uses a subset of the extensions as the old page. The ...
sfdcfox's user avatar
  • 497k
7 votes
Accepted

Can you output map values in visualforce inline using a string key?

You have a local variable called map in your constructor that hides the map property. (See e.g. Variable shadowing for more about that.) Change: Map<String, Custom_Object__c> map = new Map<...
Keith C's user avatar
  • 136k
5 votes
Accepted

Visualforce Page Error

This one is easy to hit integer last = listTaskFollow.size(); // returns 1 if one member in list listTask.add(listTaskFollow[last]); // index[1] should be index[0] when list has 1 element You ...
cropredy's user avatar
  • 72.1k
5 votes

Formula fields not auto populating -- until after insert -- need a workaround

You can't evaluate cross-object formulas on a record that does not exist in the database. You'll have to insert it and then query the record back. One "trick" that I've used in the past is to insert a ...
sfdcfox's user avatar
  • 497k
5 votes
Accepted

get set from controller extension to visualforce page

You are setting a local variable rather than your controller property. Change: Set<String> myProperty { get; set; } public MyExtension(ApexPages.StandardController controller) { Set<...
Adrian Larson's user avatar
  • 151k
5 votes
Accepted

Unknown constructor

You need a recordSetVar="accounts" attribute on your <apex:page> tag. Otherwise, the Visualforce system believes you to be using an ApexPages.StandardController rather than an ApexPages....
David Reed's user avatar
  • 93.2k
5 votes
Accepted

Add Custom Error Message to VF Page

Your command button is calling the standard controller save. You need to use your custom action in the save button, shown below: <apex:commandButton value="Save" action="{!onSave}"/>
battery.cord's user avatar
  • 8,845
5 votes
Accepted

Variable does not exist in method

searchDir is an instance variable. It is bound to a specific instance of the class Direccion - here, the controller extension. static methods, such as @RemoteAction JavaScript remoting actions, aren'...
David Reed's user avatar
  • 93.2k
5 votes
Accepted

How to generate pptx files with the VisualForce page and Apex Controller

As well as labeling the content that your controller returns as of a specific content-type, you actually have to format the data to match. For PPTX that is a zipped set of XML files, which given that ...
Keith C's user avatar
  • 136k
5 votes
Accepted

How to fetch apex:input field value into extension class

The ApexPages.currentPage().getParameters() call allows you to access URL parameters supplied to your page. It has nothing to do with values bound to components on your page. Your input fields are ...
David Reed's user avatar
  • 93.2k
4 votes
Accepted

Pass value from the visualforce page to a global variable of a class

A good solution to this is to use a proxy object in the controller to capture the dateTime value public Event evt { // proxy object, fld StartDateTime is creatable get { if (this.evt == null) ...
cropredy's user avatar
  • 72.1k
4 votes

Use controller extension attribute in Javascript

You have some JavaScript issues. There's no size() function in JavaScript arrays and no types like int. Try below for loop in you javascript instead of yours. for(var i=0;i<theControllerValue....
highfive's user avatar
  • 6,241
4 votes
Accepted

Visualforce Delete Row: Missing id at index: 0

The problem is that no-database-saved items are being added to your 'delete' lists. You should validate that, before add an item to your 'delete' lists, the item is a valid record saved in database: ...
Joca's user avatar
  • 941
4 votes
Accepted

SObject row was retrieved via SOQL without querying- Using Dynamic References

Repro The MVR here is pretty simple: <apex:page standardController="Contact" recordSetVar="records"> <apex:pageBlock> <apex:pageBlockTable value="{!records}" var="record"&...
Adrian Larson's user avatar
  • 151k
4 votes
Accepted

How to call controller extesion action from VF component

I found 3 strange reasons why the addMethod wasn't being called. I'd love to hear from anyone that has any ideas on the why, or where I might be wrong. OnClick attribute For some reason the onClick ...
Nick C's user avatar
  • 6,790
4 votes
Accepted

How to get a Javascript variable to the apex controller class

You can't have submitted the value by the time your constructor is called; the page hasn't loaded yet. However, you should be able to check the referrer from Apex Code this way: public APage(...
sfdcfox's user avatar
  • 497k
4 votes
Accepted

Passing InputText to Controller Extension

The getter is returning the original value that was queried. Just use a normal getter, and assign the default value in your constructor. public i3_ProjectTimesheet_Controller_Edit(ApexPages....
sfdcfox's user avatar
  • 497k
3 votes

Value '[X]' cannot be converted from Text to core.apexpages.el.adapters.metadata.VFSObjectELAdapter

Looks to be same issue as posted here in the Developer Forums, you may want to check that the object is properly instantiated and that the mapping param name from VF page is correct. It should be &...
Gaurav Kheterpal's user avatar
3 votes
Accepted

Test class for a pagereference method

The testmethod looks like @isTest private static void testDisplayButton() { CreateNewCase ctlr = new CreateNewCase(new ApexPages.StandardController (new Contact()); ctlr.checkFirstName = ...
cropredy's user avatar
  • 72.1k
3 votes
Accepted

Set an inputfield inside a vf controller

To use you have to bind sObject fields with it. In your case you can declare an instance of type Prodotto_contratto__c and bind it's field with UI. Then you can access them in the controller. <...
highfive's user avatar
  • 6,241
3 votes
Accepted

Force.com Site - Direct User to Record Without Exposing Record Id in URL

Assuming you're not using a Standard Controller, you could always encrypt the URL (Crypto.encryptWithManagedIV), then decrypt the parameter within your controller. Otherwise, if you are using a ...
sfdcfox's user avatar
  • 497k
3 votes
Accepted

Replace custom object tab with a VF page/tab AND keep original SF classic looks

You don't even need any controller. The <apex:enhancedList> tag gives you a very similar view to the out of the box object tab. You can also set the tabStyle attribute. <apex:page tabStyle="...
Adrian Larson's user avatar
  • 151k
3 votes
Accepted

How to pass parameters from a VF page to a controller extension

Main Issue: No rerender on the action function. Removing that produces an attempt to dereference null object. SO I essentially added that to the actionFunction and it all started to work. Issue has ...
Eric's user avatar
  • 54.2k
3 votes
Accepted

Create a drop down list in VF Page

You need to set size="1". <apex:selectList size="1" ...>
Adrian Larson's user avatar
  • 151k
3 votes
Accepted

ReRender outputPanel via commandLink not reRendering anything when pressed

You issue is that: You are updating tempContact Your getIsVerified method is using the cont variable Last_Verification_Date__c field which is set on page load You are not updating the cont variable ...
Eric's user avatar
  • 54.2k
3 votes
Accepted

Decision to use Custom Controller rather than Controller Extension

According to me answer will be 1 and 3. Controller extension leverages the built-in-functionality of Standard Controller, but overrides one or more actions. Where as, Custom Controller replaces the ...
Santanu Boral's user avatar
3 votes

Can a single VF page override both a standard action and a list action?

It is not possible for a single VF page to do this, but you can create 2 VF pages and have them use the same controller extension, using the same notation you used above. Single Record Handler <...
abd3721's user avatar
  • 2,162

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