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
moni shamoni sha 

Expecting '}' but was: 'if' at line 13 column 6

hi team,

I have below line of code but receiving below error when saving

Expecting '}' but was: 'if' at line 13 column 6

Code

Set<String>CCset = new Set<String>();
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
 Enhancements__c AZMEE = Enhancements__c.getOrgDefaults();
    List<String> emailcc = new List <String>{AZMEE.Meeting_cc__c};
    
     if(emailcc.size() > 0)-----> error line 
     {
          CCset.add(emailcc);
               
               }
 
Could you please help on resolving the issue         
Suraj Tripathi 47Suraj Tripathi 47

Hi Moni,

You can never put a List inside a set directly, please check this Code:-

Set<String>CCset = new Set<String>();
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        Enhancements__c AZMEE = Enhancements__c.getOrgDefaults();
        List<String> emailcc = new List <String>{AZMEE.Meeting_cc__c};
            
        if(emailcc.size() > 0){
            for(string str:emailcc){
                CCset.add(str);
            }
        }
Please Mark it as Best Answer if it helps.
Thanks
moni shamoni sha
Hi Tripathi,

Thanks for your quick response, Tried but received the same error again.

Thanks
Suraj Tripathi 47Suraj Tripathi 47

I think you are not getting data in this Enhancements__c AZMEE = Enhancements__c.getOrgDefaults();

you can take reference from this link

https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_custom_settings.htm

https://thecodestuff.wordpress.com/2012/02/14/hierarchy-custom-settings-semantics-explained/

if you are getting data in AZMEE then copy my whole code and paste in your area.

global class DataTest{
    public static void data(){
       Set<String>CCset = new Set<String>();
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        Enhancements__c AZMEE = Enhancements__c.getOrgDefaults();
        List<String> emailcc = new List <String>{AZMEE.Meeting_cc__c};
            
        if(emailcc.size() > 0){
            for(string str:emailcc){
                CCset.add(str);
            }
    }   
    
}

I have tried the below code similar to above and I am not getting any error.

global class DataTest{
    public static void data(){
        Set<String>CCset = new Set<String>();
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        Account AZMEE =[select id,Name from Account limit 1];
        
        List<String> emailcc = new List <String>();
        emailcc.add(AZMEE.Name);
        
        if(emailcc.size() > 0){
            for(string str:emailcc){
                CCset.add(str);
            }
        }
    }   
    
}
Please let me know it is working or not.

 

 

Ratik SinghalRatik Singhal
HI Suraj, 

Fundamentally there is no issue while storing Set<Strig> into List<String> or vice versa. 
List<String> lst = new ArrayList<String>();
lst.add("1");
lst.add("2");

Set<String> setq = new HashSet<String>();
setq.add("3");
setq.add("4");

List<String> lstCombined = new ArrayList<String>();
Set<String> setCombined = new HashSet<String>();

lstCombined.addAll(lst);
lstCombined.addAll(setq);

setCombined.addAll(lst);
setCombined.addAll(setq);

System.out.println("lstCombined-> "+lstCombined);
System.out.println("setCombined-> "+setCombined);

===Answer===
lstCombined-> [1, 2, 3, 4]
setCombined-> [1, 2, 3, 4]

Here compile time error is coming due to some error before error line. I have similar issue and problem was in above for loop.