List<id> rightEmpIds = new list<id>(); //id集合
String intentionStr='';
Integer noFollow_Day = 2 //
String activeStatusStr='';
String labelsStr='';
String customLabels = '';
String startDate='';//DateTime类型的字符串
String endDate='';//DateTime类型的字符串
String searchInfo = '';
//查询的字符串
String queryString = 'select id,Account__r.Name,Phone__c,Account__r.Address__c,Phase__c,CreatedDate,DecorationAddress__c,LastModifiedDate,HostEmployee__c'
+',Intention__c,Source__c,NoFollow_Day__c,ActiveStatus__c,Labels__c,Other_Labels__c,Renovation_District__c'
+',Employee__r.Wechat_User__r.vlink__User_ID__c,Lead__c,Area__c'
+' from Opportunity__c'
+' where Employee__c in :rightEmpIds'
+(Intention!='' ? (' And IntentionCode__c in '+('('+intentionStr+')')) : '')
+(NoFollow_Day!=0 ? (' And OppNoFollow_Day__c <= ' + Integer.valueOf(NoFollow_Day)) : '')
+(ActiveStatus!='' ? (' And ActiveStatus__c in '+('('+activeStatusStr+')')) : '')
+(Labels!='' ? (' And Labels__c includes '+('('+labelsStr+')') ): '')
+(customLabels!=null ? (' And Other_Labels__c like '+'\'%'+customLabels+'%\'') : '')
+(startDate!=NULL ? (' And CreatedDate__c>='+startDate) : '')
+(endDate!=NULL ? (' And CreatedDate__c<='+endDate) : '')
+(Utils.isNull(searchInfo) ? '' : ' And('
+' Account__r.Name like '+'\'%'+searchInfo+'%\''
+' OR Phone__c like '+'\'%'+searchInfo+'%\''
+')')
+' Order by TaskPhaseCode__c ASC,createdDate desc'
+' limit 50000'
;
//查询
List<Opportunity__c> list_opps = Database.query(queryString);
Salesforce 中SOQL语句查询字符串拼接
最新推荐文章于 2022-07-26 06:49:18 发布