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
QuickDEVQuickDEV 

Passing values from one apex class to other

Hi,

 

I have a tricky situation.

 

I have a page VF1 with SelectRadio (there are other things, for simplicity consider only this) and corresponding Apex class, class1.  when the form on the page is submitted the variables are set in class1.  

 

Now, I need to pass some of the values captured in class1 variables to class2.

For that, I declared a  callingMethod in Class1 and calledMethod in class2 passing the variables List<string>.

To invoke the CallingMethod, declared a static{ callingMethod();} block in class1. The problem is I am getting the values as 'null' in class2, may be because of the fact that static block is executed before the varaibles are set on submit button.Please suggest me any workarounds or Am I going in wrong direction.

 

Appreciate your time.

 

This is what I am trying to explain:

 

 

class1{

static{

 

callingMethod(List<String> abc);

 }

 

//populate List<String> static callingMethod(List<String> lst) { class2.calledMethod(lst); } } ============== Class2 { static calledMethod(List<String> lst) { // read values from list. I am getting 'null' values } }

 

 

 

sfdcfoxsfdcfox
Each page runs in its' own context, far as I can discern. Instead, add some URL parameters to the link (i.e. /apex/VF2?param1=value1&param2=value2...). From this method, you could use the getParameters() function to retrieve this data. Note that composite objects (i.e. sobjects and other non-primitive types) would not be directly passable (but you could pass a list of ID values, or serialize an object). Also note that URL limits would prevent any significant amount of data from being passed (roughly 2000 URL-encoded characters). Finally, as an extreme method, you could create a custom object with data fields, populate the object, commit it to the database, then pass its' ID to the new page, and that page could retrieve the values and delete the object. Other than that, I'm pretty much out of ideas. I hope something in this response points you in the right direction.
QuickDEVQuickDEV

Thank you for your reply.

 

Yes, I think I can get one of these good ideas work.  Meanwhile I have been trying other ways. 

 

Let you know once I get something working.

 

Thanks