Not able to call a variable from constructor
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty{ margin-bottom:0;
}
up vote
3
down vote
favorite
I am using a visualforce email template which calls a visualforce component and that component calls the controller class.
I am sending an Id from the Email Template to the component and trying to set it to another variable in the controller. It does not print the id from the component when i try to set it in the constructor and print it in the component. It would be great if someone could tell me where am I wrong. I researched on this issue and most likely it looks like There is an execution order that is not met. please help me fix this poblem and print the Id.
Visualforce Template:
<messaging:emailTemplate subject="Account overview Document" recipientType="User" relatedToType="pse__Proj__c">
<messaging:plainTextEmailBody >
<c:Information_Document_component Project_Id="{!relatedTo.Id}"/>
</messaging:plainTextEmailBody>
</messaging:emailTemplate>
Visualforce Component:
<apex:component controller="Information_Document_Controller" access="global" >
<apex:attribute: required="required" name="Project_Id" type="String" description="Test" AssignTo="{!projectId}"/>
{!projectId} <!-- This prints the correct Id -->
{!test} <!-- This prints as "test result: null where as I want this to print the Id too-->
</apex:component>
Controller:
public class Information_Document_Controller {
public String test {get; set;}
public String projectId{get; set;}
public Information_Document_Controller(){
test = 'test result: '+projectId;
}
}
Please note that i have simplified the class just for this issue. Once i am able to get the Id in the constructor i will be using it in queries to return some fields from few of the related objects. Thank You in advance.
apex visualforce visualforce-component email-template
add a comment |
up vote
3
down vote
favorite
I am using a visualforce email template which calls a visualforce component and that component calls the controller class.
I am sending an Id from the Email Template to the component and trying to set it to another variable in the controller. It does not print the id from the component when i try to set it in the constructor and print it in the component. It would be great if someone could tell me where am I wrong. I researched on this issue and most likely it looks like There is an execution order that is not met. please help me fix this poblem and print the Id.
Visualforce Template:
<messaging:emailTemplate subject="Account overview Document" recipientType="User" relatedToType="pse__Proj__c">
<messaging:plainTextEmailBody >
<c:Information_Document_component Project_Id="{!relatedTo.Id}"/>
</messaging:plainTextEmailBody>
</messaging:emailTemplate>
Visualforce Component:
<apex:component controller="Information_Document_Controller" access="global" >
<apex:attribute: required="required" name="Project_Id" type="String" description="Test" AssignTo="{!projectId}"/>
{!projectId} <!-- This prints the correct Id -->
{!test} <!-- This prints as "test result: null where as I want this to print the Id too-->
</apex:component>
Controller:
public class Information_Document_Controller {
public String test {get; set;}
public String projectId{get; set;}
public Information_Document_Controller(){
test = 'test result: '+projectId;
}
}
Please note that i have simplified the class just for this issue. Once i am able to get the Id in the constructor i will be using it in queries to return some fields from few of the related objects. Thank You in advance.
apex visualforce visualforce-component email-template
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I am using a visualforce email template which calls a visualforce component and that component calls the controller class.
I am sending an Id from the Email Template to the component and trying to set it to another variable in the controller. It does not print the id from the component when i try to set it in the constructor and print it in the component. It would be great if someone could tell me where am I wrong. I researched on this issue and most likely it looks like There is an execution order that is not met. please help me fix this poblem and print the Id.
Visualforce Template:
<messaging:emailTemplate subject="Account overview Document" recipientType="User" relatedToType="pse__Proj__c">
<messaging:plainTextEmailBody >
<c:Information_Document_component Project_Id="{!relatedTo.Id}"/>
</messaging:plainTextEmailBody>
</messaging:emailTemplate>
Visualforce Component:
<apex:component controller="Information_Document_Controller" access="global" >
<apex:attribute: required="required" name="Project_Id" type="String" description="Test" AssignTo="{!projectId}"/>
{!projectId} <!-- This prints the correct Id -->
{!test} <!-- This prints as "test result: null where as I want this to print the Id too-->
</apex:component>
Controller:
public class Information_Document_Controller {
public String test {get; set;}
public String projectId{get; set;}
public Information_Document_Controller(){
test = 'test result: '+projectId;
}
}
Please note that i have simplified the class just for this issue. Once i am able to get the Id in the constructor i will be using it in queries to return some fields from few of the related objects. Thank You in advance.
apex visualforce visualforce-component email-template
I am using a visualforce email template which calls a visualforce component and that component calls the controller class.
I am sending an Id from the Email Template to the component and trying to set it to another variable in the controller. It does not print the id from the component when i try to set it in the constructor and print it in the component. It would be great if someone could tell me where am I wrong. I researched on this issue and most likely it looks like There is an execution order that is not met. please help me fix this poblem and print the Id.
Visualforce Template:
<messaging:emailTemplate subject="Account overview Document" recipientType="User" relatedToType="pse__Proj__c">
<messaging:plainTextEmailBody >
<c:Information_Document_component Project_Id="{!relatedTo.Id}"/>
</messaging:plainTextEmailBody>
</messaging:emailTemplate>
Visualforce Component:
<apex:component controller="Information_Document_Controller" access="global" >
<apex:attribute: required="required" name="Project_Id" type="String" description="Test" AssignTo="{!projectId}"/>
{!projectId} <!-- This prints the correct Id -->
{!test} <!-- This prints as "test result: null where as I want this to print the Id too-->
</apex:component>
Controller:
public class Information_Document_Controller {
public String test {get; set;}
public String projectId{get; set;}
public Information_Document_Controller(){
test = 'test result: '+projectId;
}
}
Please note that i have simplified the class just for this issue. Once i am able to get the Id in the constructor i will be using it in queries to return some fields from few of the related objects. Thank You in advance.
apex visualforce visualforce-component email-template
apex visualforce visualforce-component email-template
asked Nov 29 at 7:36
Umair Ayaz
161
161
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
3
down vote
Sadly, that's just how VisualForce components work. They are constructed first, then the parameters are set.
So, typically, you have to implement custom setter methods. Each one calls an initialisation method which you write to check when all of the parameters have been initialised, then so its actual work e.g.
public String test {get; set;}
public String projectId{get; set {
projectId = value;
initialise();
}}
private void initialise() {
if(projectId != null) {
test = 'test result: '+projectId;
}
}
Thanks Aiden. It worked!
– Umair Ayaz
Nov 29 at 10:41
Great! Could you accept the answer so that anyone else with the same problem can see that there is a working answer here?
– Aidan
Nov 29 at 10:45
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
Sadly, that's just how VisualForce components work. They are constructed first, then the parameters are set.
So, typically, you have to implement custom setter methods. Each one calls an initialisation method which you write to check when all of the parameters have been initialised, then so its actual work e.g.
public String test {get; set;}
public String projectId{get; set {
projectId = value;
initialise();
}}
private void initialise() {
if(projectId != null) {
test = 'test result: '+projectId;
}
}
Thanks Aiden. It worked!
– Umair Ayaz
Nov 29 at 10:41
Great! Could you accept the answer so that anyone else with the same problem can see that there is a working answer here?
– Aidan
Nov 29 at 10:45
add a comment |
up vote
3
down vote
Sadly, that's just how VisualForce components work. They are constructed first, then the parameters are set.
So, typically, you have to implement custom setter methods. Each one calls an initialisation method which you write to check when all of the parameters have been initialised, then so its actual work e.g.
public String test {get; set;}
public String projectId{get; set {
projectId = value;
initialise();
}}
private void initialise() {
if(projectId != null) {
test = 'test result: '+projectId;
}
}
Thanks Aiden. It worked!
– Umair Ayaz
Nov 29 at 10:41
Great! Could you accept the answer so that anyone else with the same problem can see that there is a working answer here?
– Aidan
Nov 29 at 10:45
add a comment |
up vote
3
down vote
up vote
3
down vote
Sadly, that's just how VisualForce components work. They are constructed first, then the parameters are set.
So, typically, you have to implement custom setter methods. Each one calls an initialisation method which you write to check when all of the parameters have been initialised, then so its actual work e.g.
public String test {get; set;}
public String projectId{get; set {
projectId = value;
initialise();
}}
private void initialise() {
if(projectId != null) {
test = 'test result: '+projectId;
}
}
Sadly, that's just how VisualForce components work. They are constructed first, then the parameters are set.
So, typically, you have to implement custom setter methods. Each one calls an initialisation method which you write to check when all of the parameters have been initialised, then so its actual work e.g.
public String test {get; set;}
public String projectId{get; set {
projectId = value;
initialise();
}}
private void initialise() {
if(projectId != null) {
test = 'test result: '+projectId;
}
}
answered Nov 29 at 9:20
Aidan
6,700941
6,700941
Thanks Aiden. It worked!
– Umair Ayaz
Nov 29 at 10:41
Great! Could you accept the answer so that anyone else with the same problem can see that there is a working answer here?
– Aidan
Nov 29 at 10:45
add a comment |
Thanks Aiden. It worked!
– Umair Ayaz
Nov 29 at 10:41
Great! Could you accept the answer so that anyone else with the same problem can see that there is a working answer here?
– Aidan
Nov 29 at 10:45
Thanks Aiden. It worked!
– Umair Ayaz
Nov 29 at 10:41
Thanks Aiden. It worked!
– Umair Ayaz
Nov 29 at 10:41
Great! Could you accept the answer so that anyone else with the same problem can see that there is a working answer here?
– Aidan
Nov 29 at 10:45
Great! Could you accept the answer so that anyone else with the same problem can see that there is a working answer here?
– Aidan
Nov 29 at 10:45
add a comment |
Thanks for contributing an answer to Salesforce Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f240916%2fnot-able-to-call-a-variable-from-constructor%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown