Salesforce 中SOQL语句查询字符串拼接

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);  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值