+ Start a Discussion
Ankur SrivastavaAnkur Srivastava 

use value returned in server controller method to process further

I have the following method returning a changed owner id when a person selects a new value from lightning component. I want to use this ownerId in a method of some other class. The value of the ownerId is available in this method. I am unable to use this return ownerId in a different class. It looks trivial but I don't know how to do it.
    @AuraEnabled
    public static Id getNewRecordOwner(Id ownerId) 
    { 
        System.debug('The value of Owner ID'+ownerId);
        
        leadConvertController lctr = new leadConvertController(ownerId);
        lctr.ownerIdChanged=ownerId;

        return ownerId; 
    }
Best Answer chosen by Ankur Srivastava
Mohith Kumar ShrivastavaMohith Kumar Shrivastava
Make all your class property static .May be since one of your classes is instance its creating issues .

All Answers

Mohith Kumar ShrivastavaMohith Kumar Shrivastava
Store the returned value in the aura:attribute and you can retrieve the value from the attribute anytime and pass as a parmeter to the method needing this value 

Check the below code 
 
<aura:attribute name="ownerId" type="string" />
 
action.setParams({
				"ownerId": component.get("v.ownerId")
			});

 
Ankur SrivastavaAnkur Srivastava
I want to use the ownerId value in some other apex controller method. In my code I have leadConvertController class, in which there is class variable ownerIdChanged. I basically want to populate its value from the ownerId field which I have got from client-side controller.
Mohith Kumar ShrivastavaMohith Kumar Shrivastava
Make all your class property static .May be since one of your classes is instance its creating issues .
This was selected as the best answer
Ankur SrivastavaAnkur Srivastava
Static it is.. It worked for me. Thanks Mohith