• Ivan Wang 5
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Hi,

I am attaching a csv file and following is the code

   

List<Opportunity> listCurrentShowOpportunities = [select Name,OwnerId,AccountId,StageName,Probability,TotalOpportunityQuantity,Amount,Description,CloseDate from opportunity] ;

String csvContent = 'Name,Owner Name,Owner Id,Account Name,Account Id,Stage Name,Probability,Total Opportunity Quantity,Amount,Description,Close Date'+'\n';
      
 for (Opportunity opp : listCurrentShowOpportunities){
        csvContent = csvContent + opp.Name + ',' + opp.Owner.FirstName + opp.Owner.LastName + ',' + opp.OwnerId + ',' + opp.Account.Name + ',' + opp.AccountId + ',' + opp.Show__r.Name + ',' + opp.Show__c + ',' + opp.StageName + ',' + opp.Probability + ',' + opp.Item__c + ',' + opp.Item_Type__c + ',' + opp.Product_Family__c + ',' + opp.TotalOpportunityQuantity + ',' + opp.Sales_Price__c + ',' + opp.Amount + ',' + opp.Description + ',' + opp.CloseDate + '\n';
       }

      Attachment attachment = new Attachment();
      attachment.Body = Blob.valueOf(csvContent);
      attachment.Name = 'csvFile.csv';
      attachment.ParentId = parentid; 
      insert attachment;
Where listCurrentShowOpportunities does not have any limit. I asume it to be size limit of list.
If we consider that I we get about 7000 oppty string csvContent size gets exceeded and I get Apex heap size too large error.
How should I handle this?