function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bozotheclownbozotheclown 

Trying to Bring Heap Size Down

Hello.  I was wondering if anyone could give me some guidance.

 

I am having issues with the heap size of a certain VF page.  Specifically, this is being caused by an IF statement that pulls values from a large list.

 

Just as a side note...I initially was doing an aggregatedresult COUNT on the below, but due to other SOQL lists on the page, I was beginning to run into 50K limit issues.  Therefore, I thought I would just do an IF statement on whether a record met a few conditions.  If it did, I would just increase a "Count" variable by 1.

 

Well, this works...but I am getting dangerously close to the heap size limit. 

 

My page simply displays static data - so there is no need to keep any of the variables/lists in memory after the page renders.  Given that, I was thinking that I could bring the heap size down dramatically...but that is where I am having issues.

 

Thanks in advance.

 

 

// This is creating a list from a group of over 300,000 records // The "listA" that gets created below totals around 15,000 records listA = [SELECT id, Duration__c, Location__c, CustCondition__c, HappyCust__c, JoinedDate__c FROM myObject__c WHERE JoinedDate__c=TODAY OR HappyCust__c=false]; // Now I want to count the number of occurrences for records that meet a particular condition Count = 0; // resetting the counter value for (Integer a = 0; a < listA.size(); a++) {

// The below IF statement is what is causing the huge jump in heap size. I was wondering how to fix it

if(listA[a].JoinedDate__c==system.today() && listA[a].Location__c=='NE' && listA[a].Duration__c>=60) { Count = Count + 1; // increasing the counter by one } } listA = null; // I thought nulling out the big list would do the trick - but the heap is still huge

 

steve456steve456

Make sue you give most of the fiekds that will be there for a record

 

Try indexing by putting unique fiekds

 

 

Try to use LIMITs

cropzimcropzim
Date todayDt = Date.today();
for (MyObject__c mo : [SELECT id, Duration__c, Location__c, CustCondition__c, HappyCust__c, JoinedDate__c FROM myObject__c WHERE JoinedDate__c=TODAY OR HappyCust__c=false])
 if (mo.joinedDate__c == todayDt &&mo.location__c == 'NE' && mo.duration__c >= 60) 
   count++;

 Does this do the trick?