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
Hariharan M 18Hariharan M 18 

display all oppurtunities

display all oppurtunities,

in the below code am getting error, can anyone tell me how to fix it?
User-added image
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Hariharan,

FIELDS(ALL) works in the Developer Console ("Query" tab) and other APIs (REST, SOAP, etc), just not Apex.  You can use FIELDS(STANDARD), but not either of the other two options while writing Apex. This is an Apex-only restriction to prevent blowing up heap limits.
 
public class OpportunityPracticeClass {

    public static void praticeFunction(){
        List<Opportunity> opplist=[SELECT FIELDS(STANDARD) FROM Opportunity LIMIT 200];
        for(opportunity opp:opplist){
            system.debug('opp'+opp);
        }
 
    }
}


Please find the same answer from stack exchange as well

https://salesforce.stackexchange.com/questions/340948/soql-fields-function-gives-error-even-with-limit

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
CharuDuttCharuDutt
Hii HariHaran
Try Below Code
Public class OppurtunityPracticeClass{
    public static void practiceFunction(){
        List<Opportunity> opportunityList = [SELECT Id,Name,Amount,StageName FROM Opportunity];
        for (Opportunity opp:opportunityList){
            system.debug(opp);
        }
    }
}
Please Mark It As Best Asnwer If It Helps
Thank You!