Examples showing how to reference Apex variables and queries in visualforce. Also shows how to send variables from visualforce to an apex controller. Github Repo: https://github.com/Nicholashuber/Apex-Visualforce Simply create the visualforce page and controller and click preview after saving to see the results. Apex:
|
public class AccountVF_controller { public String var1 { get; set; } public String var2 { get; set; } public Account accountRecord{get; set;} public Contact contactRecord{get; set;} //Since this is the constructor (the same name as the controller) it is being called first. public AccountVF_controller() { accountRecord = [SELECT Id,name FROM Account limit 1]; contactRecord = [SELECT Id,name FROM Contact WHERE AccountID = :accountRecord.id limit 1]; //please be aware that in this example the first account selected should have atleast 1 contact related to it. var1 = accountRecord.id; var2 = contactRecord.id; } } |
Visualforce page:… Read More