function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
miku1051miku1051 

passing values from VF page template to component controller..?

VF Page component class Not getting value of soID.query works if i pass hard coded ID.Please someone tell me where i am wrong..**The constructor gets called first, before any variables are set. I dont know how to do this...

 

 

public with sharing class saleslinecntlr {
public string soID{get;set;}
List<Sales_Order_Line__c> saOrderLin;
public saleslinecntlr ()
{
System.debug('---------'+soID);
    saOrderLin=[Select id,name,Product__r.Name,Serial_Number__c,Quantity__c,Sale_Price__c,Total__c
                                             from Sales_Order_Line__c where salesorderid=:**soID** order by name];


}
    public List<Sales_Order_Line__c> getsaOrderLin() {
    return saOrderLin;
}

}

 

Best Answer chosen by Admin (Salesforce Developers) 
Prafull G.Prafull G.
Hi Miku,

As the constructor is first to be called during page load. And you are aware and mentioned we defines variables on top of the page and then rest of the components therefore You can write your logic in methods i.e. getter/setter to perform any logic based on the variables.

Instead of doing any logic in Constructor, you can go ahead and create getter method and write your query in it.

All Answers

ForcepowerForcepower
Try this as the first line in your constructor:
soId = System.currentPageReference().getParameters().get('id');

When going to the VF page, you'd do something like this:

/apex/SalesLineVF?id=a0000000001234
Prafull G.Prafull G.
Hi Miku,

As the constructor is first to be called during page load. And you are aware and mentioned we defines variables on top of the page and then rest of the components therefore You can write your logic in methods i.e. getter/setter to perform any logic based on the variables.

Instead of doing any logic in Constructor, you can go ahead and create getter method and write your query in it.
This was selected as the best answer