• Elise Smith
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
In Salesforce how do we assign large queries results to a collection and looping through the collection ( ie without SOQL for loops )? Please share code example 

Best Regards 
Debaranjan Ghosh
I'm using Salesforce Lightening Force and have an email template that I use for our monthly e-news.
 
Recently it's started telling me that I have too much content, just prior to sending, and will cut off elements unless I edit it.
 
I have discovered that there is a 32,000 character limit (which includes visible characters, other characters and markup) which doesn't seem like very much!  
 
The issue I have is that I think html code is being duplicated in the background somehow (I've deleted loads of "‌ " and also some table formatting which has just replicated and doesn't seem to have any purpose.  
 
Does anyone know if there is an easier way of removing code which isn't actually being used without trawling through?  Also how do I stop it from re-appearing??
 
The end of the template looks like the attached, but more (!) and every time I delete and save it magically reappears and it all counts toward the character limit!User-added image
why Am I facing this issue?
(AddOppInfoTrigger: execution of AfterInsert caused by: System.ListException: Duplicate id in list: a045h00000zJB2rAAG Trigger.AddOppInfoTrigger: line 80, column 1)

trigger AddOppInfoTrigger on Opportunity (After insert)
{
         
         List<Opportunity_Info__c> infoUpdate = new List<Opportunity_Info__c>();
         List<Opportunity_Info__c> infoInsert = new List<Opportunity_Info__c>();
    
         List<Account> addAccountRecods = new List<Account>();
         for(Opportunity getOpp: Trigger.new)
         {
             Account getRelatedRecords = [select id, name, (SELECT Id, Name, Stage_List__c, Amount FROM Opportunities) From Account Where id = :getOpp.AccountId];
             addAccountRecods.add(getRelatedRecords);
         }
         for(Account acc: addAccountRecods) 
         {
             List<opportunity> getOpp = acc.opportunities;
             for(opportunity checkOpp: getOpp)
             {
                 if(checkOpp.Stage_List__c == 'new' || (checkOpp.Stage_List__c == 'In Progress' || checkOpp.Stage_List__c == 'Negotiation'))
                 {
                     List<Opportunity_Info__c> getQuerry = [select id, Name,  Account__c, Amount__c, Counter__c from Opportunity_Info__c Where (Name = :checkOpp.Stage_List__c AND Account__c = :acc.Id) limit 1];
                     
                     for(Opportunity_Info__c oppInfo: getQuerry)
                          {
                              
                             if(getQuerry.size() <= 0)
                              {   
                                    Opportunity_Info__c newInfoInsert = new Opportunity_Info__c();
                                  newInfoInsert.Name = checkOpp.Stage_List__c;
                                  newInfoInsert.Counter__c =  newInfoInsert.Counter__c + 1;
                                  newInfoInsert.Amount__c =   newInfoInsert.Amount__c + checkOpp.Amount;
                                  newInfoInsert.Account__c = acc.Id;
                                  
                                  infoInsert.add(newInfoInsert);
                              }
                             else
                             {
                                 oppInfo.Name = checkOpp.Stage_List__c;
                                      oppInfo.Counter__c  = oppInfo.Counter__c + 1;
                                      oppInfo.Amount__c = oppInfo.Amount__c + checkOpp.Amount;
                                      
                                      infoUpdate.add(oppInfo);
                            }
                               
                          }                      
                 }
                 else
                 {
                     List<Opportunity_Info__c> getQuerry = [select id, Name,  Account__c, Amount__c, Counter__c from Opportunity_Info__c Where (Name = :checkOpp.Stage_List__c AND Account__c = :acc.Id) limit 1];
                     
                     for(Opportunity_Info__c oppInfo: getQuerry)
                          {
                              
                             if(getQuerry.size() <= 0)
                              {   
                                    Opportunity_Info__c newInfoInsert = new Opportunity_Info__c();
                                  newInfoInsert.Name = checkOpp.Stage_List__c;
                                  newInfoInsert.Counter__c =  newInfoInsert.Counter__c + 1;
                                  newInfoInsert.Amount__c =   newInfoInsert.Amount__c + checkOpp.Amount;
                                  newInfoInsert.Account__c = acc.Id;
                                  
                                  infoInsert.add(newInfoInsert);
                              }
                             else
                             {
                                 oppInfo.Name = checkOpp.Stage_List__c;
                                      oppInfo.Counter__c  = oppInfo.Counter__c + 1;
                                      oppInfo.Amount__c = oppInfo.Amount__c + checkOpp.Amount;
                                      
                                      infoUpdate.add(oppInfo);
                            }
                               
                          } 
                 }
                     
             }
             
         }
                    if(infoUpdate.size() > 0)
                    {
                        update infoUpdate;                       
                    }
                    
                    if(infoInsert.size() > 0)
                    {
                        insert infoInsert;                        
                    }
}