21

You don't use the override keyword in this case, as you aren't extending another class and overriding its methods in a classical object oriented situation. Instead, the Visualforce platform adheres to a contract that it will look for a method in your extension named 'Save' first, and if it doesn't find that it will fallback to the method in the standard ...


18

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 instead of using the old getRecordTypeInfosByName() method as suggested in the original answer. Use this approach instead of the old suggestion below, unless ...


16

A standardcontroller's record will only contain the fields referenced in the visualforce page you're using it on. The standard controller addFields(List) method (docs) allows you to extend this to the fields you need in your apex code. cont.addFields(new List<String>{'Assigned_to_Partner__c'}); Set this as the 2nd line in your constructor.


15

You can't directly reference the other classes (extensions) in the same page, but you can make variables static, assuming they participate in the form; this requirement exists because static variables are transient (do not serialize into the view state). Simple example follows: Page: <apex:page standardController="Account" extensions="ext1,ext2"> <...


11

Answer and Why. After spending some further time on this, I believe the answer to your question in determining if the future feature is available programatically is unfortunately, no this is not possible. I've considered the following in arriving at this answer for you. Catching the LimitException. This is unfortunately not possible. I have had luck in ...


9

If you're trying to get the Id, you should just go back to stdController. Id issueId = stdController.getId(); I also very much doubt that this is getting the value from the query string, as the documentation suggests. I'm almost positive I've used this method in pages with no query params and it works. I'll try to test later and amend my answer based on ...


9

Salesforce DOESN'T handle this in custom save actions and doing an update instead of controller.save() makes no difference. One solution would be to re-read the record from the database in your controller extension save() method, before committing the record (save/update), and compare the re-read SystemModstamp with the SystemModstamp of the record in your ...


9

Inheritance denotes a commonality or relationship between objects. Extensions let you mix in completely unrelated functionality in a consistent manner. For example, an "address lookup" extension might be used to provide connectivity to a third-party service (most likely in conjunction with a component) to provide address auto-completion. You could use this ...


9

Things often get a bit hairy when you start to use maps of maps (or mapception :D). You can represent tables of data in this way if you change your variable model. Change the map of maps to be a list of a new inner class that contains simply the name of the inner property and a map of the outer properties to boolean values. Also add a method to retrieve a ...


9

To instantiate a subclass you would need to prefix the parent class name, not its variable reference. Try this. MyClass.MyType myTypeObj = new MyClass.MyType();


8

The only fields that are queried by default are the fields that are explicitly bound to the main standard controller during the page's construction (before the constructor of your extension is called). You have two choices here: 1) You can use StandardController.reset() and StandardController.addFields() to add Name as a field to query. 2) You can bind ...


8

When you use ApexPages.currentPage().getParameters().get('Id'); You need to set Test.setCurrentPage(pageRef); and pageRef.getParameters().put('Id', String.valueOf(obj.Id)); PageReference pageRef = Page.SendEmailReceipt1; Test.setCurrentPage(pageRef); pageRef.getParameters().put('Id', String.valueOf(obj.Id)); ApexPages.StandardController sc = new ApexPages....


7

yes it is possible since standard controller extensions require just a constructor with a standard controller as a param public class Ext_A_B { public Ext_A_B(ApexPages.StandardController controller){ sObjectType sot = controller.getRecord().getsObjectType(); if (sot == Lead.sObjectType){ // LEAD LOGIC } ...


7

The function getParameters() returns a Map<String, String> to which you can add items. In your test you can use something like this: PageReference pageRef = Page.Opportunities; pageRef.getParameters().put('display', 'INACTIVE');


7

From the Error Lines, the error is happening here: private List<Contact> performSearch(string searchString) { String soql = 'SELECT id, name FROM Contact'; if(searchString != '' && searchString != null) { soql = soql + ' WHERE name LIKE \'%' + searchString + '%\''; soql = soql + ' AND OwnerId =: currentUserId'; ...


7

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 attack. Note that the value bound has to be a simple variable reference (e.g. not a dotted expression) for the dynamic SOQL case. So: String companyLike = '%'...


7

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 Redirect flag is set to false on the PageReference. Both pages use an apex:form. Here's an incredibly basic proof of concept that shows this behavior in action: ...


7

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 read-only while caching its value (a lazy-loading pattern), you can synthesize a private setter: get { // ... } private set; That will allow your class ...


7

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<String, Custom_Object__c>(); to: map = new Map<String, Custom_Object__c>(); so you are assigning to the property in the constructor, not just the ...


6

You can go with the Upsert Option. Upsert can be used in places where you are not sure if you'll have the Id of the Object and you want to insert/update the record. If the object doesn't have an Id, it performs an insert and if it has, it does an update call. public pageReference SaveandClose() { try{ upsert this.Test; } ...


6

You haven't defined a getter for your Installation__c instance variable. Try replacing this line public final Installation__c installation ; with public final Installation__c installation {get; private set;} This will allow the VF page to be able to access the installation variable.


6

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 is called when this class is the controller for a page: public with sharing class MyExtension { ... public MyExtension(MyController ctrlParam) { } } You ...


6

I found an answer here that might work for you as well, where the solution would be to change your "Save" method to the following: public PageReference saveAndRedirect() { if(controller.save() != null) { PageReference redirectPage = Page.force_OrderDetail; redirectPage.setRedirect(true); redirectPage.getParameters().put('id',controller.getId())...


6

I would start off by putting the different locations in maps. So something like: List<Inventory_Lots__c> icList = [SELECT Id, Location__c, Closed__c, On_Hold__c from Inventory_Lots__c WHERE Location__c IN :recIds.Keyset() AND Closed__c != TRUE AND On_Hold__c != TRUE]; Map<Id, List<Inventory_Lots__c> lotByLocation = new Map<Id, List<...


6

When using a StandardController, there are a few different ways to manipulate the way it queries for the record. Note your line in the constructor: opp = (Opportunity)stdController.getRecord(); The above performs a query, pulling down all fields used on the page. In addition to what fields you use on the page, you can use the addFields method (though it ...


6

Please refer to this knowledge article. Basically you just need to add some checks like if (!Schema.sObjectType.Contact.fields.Name.isAccessible()){ return ''; } or if (!Schema.sObjectType.Contact.fields.Name.isUpdateable()){ return null; } For dynamic check you could use Describe functionality. Basically you need to use several methods ...


6

Congratulations. You found one of the ways that StandardController (and StandardSetController) is broken (at least, for now). I've been trying to get a straight answer about why it's as broken as it is, but that's been very vexing. Quite a few years ago, I stumbled across a particular oddity: StandardController and StandardSetController do not act like DML ...


5

When trying to understand some new programming concepts or the specifics of a new language or API, the documentation is invaluable. Here's a couple of resources for you. Force.com Apex Code Developer's Guide Visualforce Developer’s Guide Here are some details about the specific code snippets you had questions about. 1) Check out the Exception ...


5

This week I needed to reference once controller from another and ended up using this code: public with sharing class Ext1 { private Registry r; public Ext1(ApexPages.StandardController sc) { r = Registry.instance(); r.add(Ext1.class, this); ... } private Ext2 getExt2() { return (Ext2) r.get(Ext2.class); } }...


5

You can not really control which action you want to call. The first class in your extensions will have always the highest priority : doc here. //it will always call method from cntrlr1 first <apex:page standardController="Contact" extensions="cntrl1,cntrlr2"> //it will always call method from cntrlr2 first <apex:page standardController="Contact" ...


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