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
SFDummySFDummy 

error: expecting right curly bracket

Hello,

 

what am I doing wrong here on line 12  

     for(RecordType rt: AccrTypes(

I get the following error

 

    Error: Compile Error: expecting right curly bracket, found 'for' at line 12 column 3

public with sharing class CreateSampleData{

   //Query for the Account record types
     List<RecordType> AccrTypes = [Select Name, Id From RecordType
                  where sObjectType='Account' and isActive=true];

   //Query for the Contact record types
     List<RecordType> Cntrtypes = [Select Name, Id From RecordType
                  where sObjectType='Contact' and isActive=true];  
                  
   //Create recors
   for(RecordType rt: AccrTypes){}

}

 I have written code before this one I cannot tell what the problem is...

Naidu PothiniNaidu Pothini
public with sharing class CreateSampleData{

   //Query for the Account record types
     List<RecordType> AccrTypes = [Select Name, Id From RecordType
                  where sObjectType='Account' and isActive=true];

   //Query for the Contact record types
     List<RecordType> Cntrtypes = [Select Name, Id From RecordType
                  where sObjectType='Contact' and isActive=true];  
                  
   //Create recors

   public void MethodName()
   {
      for(RecordType rt: AccrTypes)
      {
          // do something.
      }
   }

}

 

Use the for loop inside a method.

James Gordon 10James Gordon 10
Sorry if this question is a bit basic, but why is that the case?  Could someone point me to a good source to learn the ins and outs of this type of thing?  I've been going through the Java OOP tutorials and Trailhead, but stuff like this is constantly tripping me up.  Thanks in advance.