title: Salesforce Too many soql 101
body: <ol>
  <li><p>It works fine in sandBox but it causes too many soql 101 in Production. I tried to use 2. bulkified map with content distribution link with soql query but it always blocked bulk in MAP. any advise ?</p>
  </li>
  <li><p>Since I tried every thing with list customObject__c=[select... contentdistribution := ..id] but it gives also too many soql 101</p>
  </li>
  </ol>
  <p>@RestResource(urlMapping='/API/V1/notice/*')
  global with sharing class API_Notice {</p>
  <pre><code>@HttpGet(UrlMapping='/API/V1/notice/all')
  global static List&lt;String&gt; getNotice(){          
      
      List&lt;Object&gt; senderJson = new List&lt;Object&gt;();  
      
      for (Notice__c a: [SELECT Name, ClosingDate__c,Contents__c, NoticeTypes__c,createddate,OfficialSenders__c,id,(SELECT ContentDocumentId  FROM ContentDocumentLinks) FROM Notice__c]) {               
              List&lt;Object&gt; multipleAcct = new List&lt;Object&gt;();                                       
              NoticeWrapper nw = new NoticeWrapper();
              Set&lt;Id&gt; contentsId = new Set&lt;Id&gt;();             
              List&lt;Object&gt; urls = new List&lt;Object&gt;();
              Set&lt;Id&gt; acctId = new Set&lt;Id&gt;();
          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&lt;Id,CampaignMember&gt; camplinks = new Map&lt;Id,CampaignMember&gt;([
                 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() &amp;&amp; contentsid!=null){
              Map&lt;Id,ContentDistribution&gt; links = new Map&lt;Id,ContentDistribution&gt;([
                  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&lt;String&gt; sends = new List&lt;String&gt;();
  
          for(Object json : senderJson){
              sends.add(String.valueof(json));
          }
  
          return sends;    
          
      }
  
  @HttpPost
  global static List&lt;String&gt; getOneNotice(String Id){
             
      List&lt;Object&gt; urls = new List&lt;Object&gt;();
      List&lt;Object&gt; senderJson = new List&lt;Object&gt;();
      List&lt;Object&gt; multipleAcct = new List&lt;Object&gt;();
      for (Notice__c a: [SELECT Name, ClosingDate__c,Contents__c,OfficialSenders__c, id,(SELECT ContentDocumentId FROM ContentDocumentLinks) FROM Notice__c where id=:id]) {
              Set&lt;Id&gt; acctId = new Set&lt;Id&gt;();
              Set&lt;Id&gt; contentsId = new Set&lt;Id&gt;();            
              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&lt;Id,CampaignMember&gt; camplinks = new Map&lt;Id,CampaignMember&gt;([
                 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&lt;Id,ContentDistribution&gt; links = new Map&lt;Id,ContentDistribution&gt;([
                  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&lt;String&gt; sends = new List&lt;String&gt;();
        
          for(Object json : senderJson){
              sends.add(String.valueof(json));
      } 
      return sends;    
  }
  </code></pre>
  <p>}</p>