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
MktdevMktdev 

FOR loop not working

Hi,

 

Anyone can help , this for loop not working in class but working on System Log.

 

Error:

ErrorError: Compile Error: expecting right curly bracket, found 'for' at line 5 column 0 

 

 

List <optedOutList> = new List<contact>();

List <activeContactList> = new List<contact>();

List networkList = [SELECT id,name,Account_Name__r.Name, Title__c,Industry__c FROM Contact WHERE Industry__c like :IndustryName AND OptOut__c = false ORDER BY Name ASC LIMIT 100];

 

for(Contact contactObject: networkList)

{

 if(contactObject.OptOut__c==true)

{

 optedOutList.add(contactObject);

 }

 else if(contactObject.active==true)

{

 activeContactList.add(contactObject);

}

}

kbromerkbromer

 

List <optedOutList> = new List<contact>();
List <activeContactList> = new List<contact>();
List networkList = [SELECT id,name,Account_Name__r.Name, Title__c,Industry__c FROM Contact WHERE Industry__c like :IndustryName AND OptOut__c = false ORDER BY Name ASC LIMIT 100];

 

 

Should be:

 

 

List <contact> optedOutList = new List<contact>();
List <contact> activeContactList = new List<contact>();
List <contact> networkList = [SELECT id,name,Account_Name__r.Name, Title__c,Industry__c FROM Contact WHERE Industry__c like :IndustryName AND OptOut__c = false ORDER BY Name ASC LIMIT 100];

 

 

MktdevMktdev

Hi, Thanks!

 

But still same error.

 

Regards,

mktg

kbromerkbromer

You'd need to send the class declarations, that right-curly bracket error is usually caused by mismatching braces/brackets, so it could be happening anywhere in your class/trigger. 

 

 

MktdevMktdev

Hi,

 

Here is the complete class

 

 

public class PublicSearchController {

 

List <contact> optedOutList = new List<contact>();
List <contact> activeContactList = new List<contact>();
List <contact> networkList = [SELECT id,name,Account_Name__r.Name, Title__c,Industry__c FROM Contact WHERE Industry__c like :IndustryName AND OptOut__c = false ORDER BY Name ASC LIMIT 100]; 

 

for(Contact contactObject: networkList)

{

 if(contactObject.OptOut__c==true)

{

 optedOutList.add(contactObject);

 }

 else if(contactObject.active==true)

{

 activeContactList.add(contactObject);

}

}

}

kbromerkbromer

 

else if(contactObject.active==true)

 

 

'Active' is not a standard field on contacts. If it's a custom field, it may be called 'Active__c', so you'd instead say: 

 

contactObject.Active__c == true

 

You'll also need to select it in the SOQL statement where you get the contacts for networkList

MktdevMktdev

Still not working .For loop is not working in normal mode also.

elghoul_girlelghoul_girl

Hello,

 

   I am facing the same problem. Did you find the reason?

 

Thanks,

   Sally