我有一个对象,我允许用户在文本字段中添加 Filter Clause,在我的代码中,我使用该子句来查询符合过滤条件的记录。现在我的问题是我的逻辑从一个父对象运行,它可以有多个相关记录意味着多个过滤子句。如果我在循环中添加查询,我将达到 soql 限制。所以我试图先查询所有没有过滤器的记录,并将它们存储在一个列表中,然后将过滤器应用于该列表。
循环中带有查询的代码,运行良好。
List<Document_Rule__c> documentRules = new DocumentRuleSelector().selectByEventIdAndStatus(new Set<Id>{recordId}, DocumentRuleDomain.STATUS_ACTIVE);
for (Document_Rule__c dr : documentRules) {
if (dr.Generate_Condition__c.Equals(DocumentRuleDomain.GENERATE_CONDITION_REGISTRATION_COMPLETED)) {
statusMap.put(DelegateDomain.REGISTRATION_STATUS_COMPLETED,DelegateDomain.REGISTRATION_STATUS_COMPLETED);
}
else if (dr.Generate_Condition__c.Equals(DocumentRuleDomain.GENERATE_CONDITION_ATTENDED)) {
statusMap.put(DelegateDomain.ATTENDANCE_STATUS_ATTENDED,DelegateDomain.ATTENDANCE_STATUS_ATTENDED);
statusMap.put(DelegateDomain.ATTENDANCE_STATUS_WALKIN,DelegateDomain.ATTENDANCE_STATUS_WALKIN);
}
List<Delegate__c> delegates = new DelegateSelector().selectDelegatesByStatusAndCritaria(statusMap, dr.Filter_Clause__c);
for (Delegate__c del : delegates) {
cvlist.add(generatePDF(del, dr.Document_Template__r));
}
}
if (cvlist.size() > 0) {
insert cvlist;
}
我试图在 APEX 中构建一个 SQOL 解析器,但看起来这是一项复杂的任务,需要处理所有运算符和条件,如 =、!=、喜欢、不喜欢…………