Apex heap size too large

Prashant, Salesforce standard SOQL queries typically hit the limit around 6000 records, give or take. Does the user need to see 50,000 rows? You may want to try an aggregate model - aggregate SOQL queries are able to process across many more rows. But even then, a lot depends on the data you’re aggregating (whether fields are indexed, how many fields you’re returning, etc.).