public without sharing class LexSearchHospitalController { @AuraEnabled public static Results init(){ Results results = new Results(); try { User useracc = [SELECT accountid,UserPro_Type__c FROM user WHERE id = :UserInfo.getUserId() ]; String accountId = Useracc.accountid; // DB202309406949 gzw start String agencyProType = Useracc.UserPro_Type__c; String soql = 'SELECT id,Name,State_Master__c,State_Master__r.Name,Address__c FROM Account'; soql += ' where id in (SELECT Hospital__c FROM hospitalprice__c WHERE account__c = :accountId and Product_Type_F__c = :agencyProType) ' ; soql += ' order by Name desc limit 100'; System.debug('accountId111111111: ' + accountId); System.debug('agencyProType11111111111: ' + agencyProType); System.debug('soql11111111111: ' + soql); // DB202309406949 gzw end results.attList = Database.query(soql); results.result = 'Success'; } catch (Exception e) { results.result = 'Fail'; results.errorMsg = e.getLineNumber() + '---' + e.getMessage(); } return results; } @AuraEnabled public static Results searchHospital(String searchName, String accountId){ Results results = new Results(); try { // DB202309406949 gzw start User useracc = [SELECT accountid,UserPro_Type__c FROM user WHERE id = :UserInfo.getUserId() ]; String agencyProType = Useracc.UserPro_Type__c; results.attList = Database.query(makeSoql(searchName, accountId,agencyProType)); results.result = 'Success'; } catch (Exception e) { results.result = 'Fail'; results.errorMsg = e.getLineNumber() + '---' + e.getMessage(); } return results; } private static String makeSoql(String searchName,String accountId,String agencyProType){ // DB202309406949 gzw start String soql = 'SELECT id,Name,State_Master__c,State_Master__r.Name,Address__c FROM Account'; soql += ' where id in (SELECT Hospital__c FROM hospitalprice__c WHERE account__c = :accountId and Product_Type_F__c = :agencyProType) ' ; // DB202309406949 gzw end if(String.isNotBlank(searchName)){ soql += ' AND Name like \'%' + searchName+ '%\''; } soql += ' order by Name desc limit 100'; System.debug('accountId222222222222: ' + accountId); System.debug('agencyProType222222222222: ' + agencyProType); System.debug('soql222222222222: ' + soql); return soql; } public class Results { @AuraEnabled public String result; @AuraEnabled public String errorMsg; @AuraEnabled public List attList; } }