低效代码
String profileid = COM_Util.getProfileIdToName(Label.LAB077);
List<user> userList = [SELECT contactId FROM user where profileid =:profileid and IsActive = true];
List<id> conIdList = new List<id>();
for(User u :userList){
conIdList.add(u.contactId);
}
List<contact> conList = [select AccountId from contact where id in:conIdList];
List<id> accIdList = new List<id>();
for(Contact con :conList){
accIdList.add(con.AccountId);
}
// 取引先のチェック
List<Account> userCheckList = [select id
,Name
From Account
where isdeleted = false
and Name in:accNameList
and id in:accIdList];
高效代码
List<Contact> conList = [select id
,Name
,AccountId
,Account.Name
,Account.ACC_E_MAIL__c
from contact
where contact.CON_TYPE__c = '种别名'
and id in (select contactId
from user
where profileid =:profileid
and isActive=true )];
低效
Map<id,Contact> conMap = new Map<id,Contact>([select id,Name from Contact where Account.Name LIKE :'%' + entryAccName + '%']);
List<plantApply__c> plaList = [select Id,PAP_ENTRY__r.Name from PlantApply__c where PAP_ENTRY__c in : conMap.keyset()]; //PAP_ENTRY__c is Contact
List<plantApply__C> plaList2 = [select Id,PAP_ENTRY__r.Name from PlantApply__c where PAP_ENTRY__r.Account.Name LIKE :'%' + entryAccName + '%' ];