39

Visualforce requires a "getter" and "setter" to reference a variable in the controller or extension. Without a getter or setter, even public or global variables cannot be referenced in Visualforce expressions. "get;" is basically: public *datatype* getVarName() { return varName; } "set;" is basically: public void setVarName(*datatype* value) { varName = ...


16

What you are seeing with {get;set;} is an example of automatic properties. From the Apex Documentation on Automatic Properties. Properties do not require additional code in their get or set accessor code blocks. Instead, you can leave get and set accessor code blocks empty to define an automatic property. Automatic properties allow you to write ...


11

I figured out that I can use apex:page action="". VF: <apex:page controller="demoController" action="{!redirect}"/> Controller: public PageReference redirect(){ if(p == null){ PageReference pageRef = new PageReference('/apex/demo2'); return pageRef; } else{ return null; } }


10

When passing parameters in a URL, you can grab the parameter values in your Visualforce Controller by using: String thecaseID = System.currentPageReference().getParameters().get('caseID');


10

Can use the controller? Perhaps set a controller and pass the parent controller to the construct or somehow? Yes, you may use the controller using apex:attribute. The data type of the attribute will be the name of the class you're passing in. You can use both the standard controller and any other controllers you'd like. As a trivial example: Page <...


9

siteName = con[0].Site__r.Name; con[] has no elements so trying to access the 0 index element will cause the list index out of bounds excpetion. To protect against this you could change your code to first check to see if the returned List is not empty: if (!con.isEmpty()) { siteName = con[0].Site__r.Name; } You may want to add in an else condition to ...


9

Salesforce's MVC is much different than ASP.NET in that with Salesforce, controllers are used with VisualForce pages which relies on a View State which is limited to 135 kb. So, what to do in a particular situation greatly depends on the View State of your VisualForce page; something which can definitely be affected by your controller. A large or poorly ...


8

When we need to send parameter with action function then we have to use rerender attribute in otherwise we always get null value in controller. <apex:actionFunction name="setAttachment" action="{!setAttachment}" rerender="none" > <apex:param name="attachmentBody" value=""/> </apex:actionFunction>


8

This was answered on SF dev forums: Reg: Get and set Methods That post linked to a great aticle on the behavior of the default get/set methods: Getter and setter methods - What are they??


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

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 ...


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

<apex:outputPanel id="feed-display-panel" rendered="{!filtRecs != null}" > is not rendered when the page loads, because filtRecs is null You cannot reRender something that didn't render at page load. Here's that blog post I mentioned in my previous reply, which explains this quite well. So on button click reRender a parent container, so move the ...


6

The zero-argument constructor is the "default constructor", but you only get it "for free" if you don't include any other constructors. Once you do, the zero-argument constructor has to be explicitly defined in order to work. Extensions use the one-argument Apexpages.StandardController controller constructor, or the Apexpages.StandardSetController controller ...


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

You should change public SelectOption RemoveReason {get;set;} to public String RemoveReason {get;set;} since the value of <apex:selectList>resolves to a String (it is independent of the <apex:selectOptions>)


6

I find it far simpler to use the assignTo attribute to set my parameters: public class MyController { public transient String src { get; set; } public PageReference MyControllerFunction() { // src will be set here return pr; } } Then, you can change your action function to: <apex:form > <apex:actionFunction name="...


6

You need to rerender pageMessages section by commandButton's attribute <apex:pageBlock> <apex:pageMessages id="msgId"/> <apex:commandButton name="Submit" action="{!exchangeInv}" rerender ="msgId"/> </apex:pageBlock> Take this approach: Since you are throwing applicationException, so better to use throw new ...


6

That's a good start. You're inserting one record in your test class. The problem is, you don't even call your controller in your test, so it can't be test. Your code is never executed. So after having inserted record, you just have to call your controller. Finally, you have to make some assertions to verify that your controller query returns your inserted ...


5

Your code isn't working because you can only rerender Visualforce components -- the Visualforce framework can't tell that you have a plain HTML <div>. This should work: <apex:outputPanel id="activationForm"> <apex:form rendered="{!activationFormIsVisible}"> <p>Show some more fields here...</p> <apex:...


5

The query limit applies to the sum of all queries in one transaction, so the 'limit 50000' doesn't help here. Alternatively you can check the limits before doing the query: Integer rowsLeft = Limits.getLimitQueryRows() - Limits.getQueryRows(); francePinCodeList = [SELECT name from Quote_line_item__c limit :rowsLeft]; And maybe check if rowsLeft == 0 to ...


5

The problem is that you try to create an instance of AddBasketGasQuoteFromMonitor with the line AddBasketGasQuoteFromMonitor controller = new AddBasketGasQuoteFromMonitor(); However, your class AddBasketGasQuoteFromMonitor only has a constructor that takes a ApexPages.StandardController as a parameter. So in your test, when you want to create an instance, ...


5

This basically means your query doesn't return any results. It may be because there are not records for that ID or that ID is not passed in the URL. Initialize the account before you hit the query.


5

Your test would just instantiate the class and request the list: @isTest static void test() { PieChartController ctrl = new PieChartController(); PieChartController.PieWedgeData[] data = ctrl.getPieData(); // Verify data contains correct values, via System.assert } This example uses hard-coded data, so there's nothing to add. In the "real world"...


5

The strings are version and language dependent. However, there is a way to find which codes are valid for a particular release: go into Setup > Develop > API, generate the Enterprise WSDL, and find the StatusCode simpleType. In version 39.0, in my org, it looks like the following values apply. The actual value that will be output depends on the user's ...


4

In this scenario, rather than creating some custom code to do that, have you considered just setting a Sort Order on the Status field to group all of your Active Contacts at the top of your related list and push your Terminated Contacts to the bottom of the list. On your page layout, there is a way to set your Sort By field for your related list. This ...


4

Testing void methods on controllers is not that different from none-void methods, first take a look at the Salesforce topic, Testing Custom Controllers and Controller Extensions. In the case of a void method you are asserting the state or member variables of your controller class instread of the return value of the method. In your case the awards member ...


4

You can use cookies Set cookie Cookie elementMsg = new Cookie('msg','true','/apex/pageYouAreGoingToUse',10,false); Add to the current page ApexPages.currentPage().setCookies(new Cookie[]{elementMsg}); Redirect to the page you want return new PageReference('/apex/CompetencyAssessmentOne?id=' + Assessment.id ); Take the cookie from the page you ...


4

Simply use this inside your method: String caseID = Apexpages.currentPage().getParameters().get('caseID'); And then use caseID for anything you want.


4

You can indeed reference a child in pure Visualforce. Note that if you want just one record, you don't get to choose which one will be displayed (it will probably be the oldest record, but no guarantees are given). Here's how you could remove the extra variable by way of using the query: <apex:page Controller="DecomController"> <apex:form > ...


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