【发布时间】:2021-09-21 08:50:31
【问题描述】:
-
它在沙盒中运行良好,但在生产中导致过多的 soql 101。我尝试使用 2. 带有内容分发链接的批量化地图和 soql 查询,但它总是阻止 MAP 中的批量。有什么建议吗?
-
因为我用 list customObject__c=[select... contentdistribution := ..id] 尝试了所有事情,但它也提供了太多的 soql 101
@RestResource(urlMapping='/API/V1/notice/*') 全局共享类 API_Notice {
@HttpGet(UrlMapping='/API/V1/notice/all')
global static List<String> getNotice(){
List<Object> senderJson = new List<Object>();
for (Notice__c a: [SELECT Name, ClosingDate__c,Contents__c, NoticeTypes__c,createddate,OfficialSenders__c,id,(SELECT ContentDocumentId FROM ContentDocumentLinks) FROM Notice__c]) {
List<Object> multipleAcct = new List<Object>();
NoticeWrapper nw = new NoticeWrapper();
Set<Id> contentsId = new Set<Id>();
List<Object> urls = new List<Object>();
Set<Id> acctId = new Set<Id>();
for(ContentDocumentLink cdl: a.ContentDocumentLinks){
if(cdl.ContentDocumentId!=null){
contentsId.add(cdl.ContentDocumentId);
}
}
if(a.OfficialSenders__c != null){
acctId.add(a.OfficialSenders__c);
}
if(a.id!=null){
nw.noticeid = a.Id;
}
if(a.ClosingDate__c != null){
nw.ClosingDate = a.ClosingDate__c;
}
if(a.NoticeTypes__c != null) {
nw.NoticeTypes = a.NoticeTypes__c;
}
if(a.Contents__c !=null){
nw.Contents = a.Contents__c;
}
if(a.Name !=null) {
nw.Name = a.Name;
}
if(a.CreatedDate !=null){
nw.createddate = a.createddate;
}
if(!acctId.isEmpty()){
Map<Id,CampaignMember> camplinks = new Map<Id,CampaignMember>([
select accountid ,CampaignId from CampaignMember where CampaignId IN: acctId
]);
if(!camplinks.isEmpty()){
for(CampaignMember cm : camplinks.values()){
multipleAcct.add(cm.AccountId);
nw.accountId = multipleAcct;
}
}
}
if(!contentsId.isEmpty() && contentsid!=null){
Map<Id,ContentDistribution> links = new Map<Id,ContentDistribution>([
select id , distributionPublicURL,ContentDocumentId from contentDistribution where ContentDocumentId IN: contentsId
]);
if(!links.isEmpty()){
for(contentDistribution cdb : links.values()){
urls.add(cdb.DistributionPublicUrl);
nw.DistributionPublicUrl = urls;
}
}
}
senderJson.add(nw);
}
List<String> sends = new List<String>();
for(Object json : senderJson){
sends.add(String.valueof(json));
}
return sends;
}
@HttpPost
global static List<String> getOneNotice(String Id){
List<Object> urls = new List<Object>();
List<Object> senderJson = new List<Object>();
List<Object> multipleAcct = new List<Object>();
for (Notice__c a: [SELECT Name, ClosingDate__c,Contents__c,OfficialSenders__c, id,(SELECT ContentDocumentId FROM ContentDocumentLinks) FROM Notice__c where id=:id]) {
Set<Id> acctId = new Set<Id>();
Set<Id> contentsId = new Set<Id>();
NoticeWrapper nw = new NoticeWrapper();
nw.noticeid = a.Id;
nw.ClosingDate = a.ClosingDate__c;
nw.Contents = a.Contents__c;
nw.Name = a.Name;
for(ContentDocumentLink cdl: a.ContentDocumentLinks){
if(cdl.ContentDocumentId!=null){
contentsId.add(cdl.ContentDocumentId);
}
}
if(a.OfficialSenders__c != null){
acctId.add(a.OfficialSenders__c);
}
if(!acctId.isEmpty()){
Map<Id,CampaignMember> camplinks = new Map<Id,CampaignMember>([
select accountid ,CampaignId from CampaignMember where CampaignId IN: acctId
]);
if(!camplinks.isEmpty()){
for(CampaignMember cm : camplinks.values()){
multipleAcct.add(cm.AccountId);
nw.accountId = multipleAcct;
}
}
}
if(!contentsId.isEmpty()){
Map<Id,ContentDistribution> links = new Map<Id,ContentDistribution>([
select id , distributionPublicURL,ContentDocumentId from contentDistribution where ContentDocumentId IN: contentsId
]);
if(!links.isEmpty()){
for(contentDistribution cdb : links.values()){
urls.add(cdb.DistributionPublicUrl);
nw.DistributionPublicUrl = urls;
}
}
}
senderJson.add(nw);
}
List<String> sends = new List<String>();
for(Object json : senderJson){
sends.add(String.valueof(json));
}
return sends;
}
}
【问题讨论】:
标签: dictionary salesforce apex soql