You need to sign in to do that
Don't have an account?
Kevin Jackson 11
Why are my variables not being called from Apex
Why are my variables not being called
I cannot figure out what I am doing wrong here. This was working before.
MY VF Page
My Controller
The VF page does not show any of the variables.
Any help is appreciated. Where is the bug?
I cannot figure out what I am doing wrong here. This was working before.
MY VF Page
<apex:page Controller="TestP" showHeader="false"> <apex:pageBlock><apex:pageBlockSection> <apex:form> Email given: {!cemail} Email Returned: {!IdentifyUser.email} Name: {!IdentifyUser.name} </apex:form> </apex:pageBlockSection> </apex:pageBlock> </apex:page>
My Controller
public class TestP { Public string cemail {get;set;} Public Contact IdentifyUser {get;set;} Public Contact x {get;set;} // IDENTIFY USER BASED ON EMAIL ADDRESS Public Contact getIdentifyUser(){ cemail='kevin@caberu.be'; Contact x = [SELECT Id, firstname, email, name FROM Contact WHERE email = :cemail LIMIT 1]; Return x; } }
The VF page does not show any of the variables.
Any help is appreciated. Where is the bug?
If you want an input, you can use inputText and a command button "Search".
return null; means "return to the same page". This code is basic and should be improved for the errors ('not found') and so on but it works for a test.
Regards
Alain
All Answers
It just lacks the constructor in you controller if you want some data just calling your VFP without passing parameters.
1. The constructor methods on the associated custom controller or controller extension classes are called, instantiating the controller objects.
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_get_request.htm The constructor is public MyController() in the sample of Salesforce (no return type):
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_custom.htm
The syntax for a constructor is similar to a method, but it differs from a method definition in that it never has an explicit return type and it is not inherited by the object created from it.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_constructors.htm (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_custom.htm)
Regards
Alain
Great! This works, but how do I do the same thing with passing parameters? I want to have cemail as an input and use that to determine the Contact.
cemail=IdentifyUser.email ??
Kind Regads,
If you want an input, you can use inputText and a command button "Search".
return null; means "return to the same page". This code is basic and should be improved for the errors ('not found') and so on but it works for a test.
Regards
Alain