Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
Hi All ,

Declared variable not working in @AuraEnabled controller 

below my sample code , how can we reuse declared variable "strusrfield "in mutiple methods 

getting  Variable does not exist: strusrfield   error 

Public class myusercls {

 @AuraEnabled public string strusrfield ; 

    

    @AuraEnabled

    public static list<String> getuserdetails(){ // this method calling from doinit 

          for( user objusr : [select id , Primary_Sales_Org__c from user where id=:UserInfo.getUserId() ]) {

              strusrfield = objusr.unicode__c;

           }

        list<customobj__c> objcus =[select id unicode__c from customobj__c where unicode__c =:strusrfield ];

        return objcus ;

    }

  public static list<String> getcustomretunx(){

         

        list<customobj__c> objcus =[select id unicode__c from customobj__c where unicode__c =:strusrfield ];

        return objcus ;

    }

}

Thanks
2 answers
Loading
0/9000