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
VancouverDevVancouverDev 

Unexpected Token Account

Hi everyone,

I'm trying to build a test class for a trigger, and I'm running into an issue I don't fully understand. Here's the code:
 
@isTest class TestValidateCorrectSIC{
    public static void CreateTestData{
    Account acct = new Account(Name='Test Account');
    acct.Sic='1111';
    acct.NumberOfEmployees=101;
    acct.AnnualRevenue=1000000;
    insert acct;
    
    MultiplierMetadata__mdt multCheck = new MultiplierMetadata__mdt();
    multCheck.SIC__c = '1111';
    multCheck.Employee_Lower_Bound__c = 100;
    multCheck.Employee_Upper_Bound__c = 102;
    multCheck.Industry__c = 'Test';
    multCheck.Industry_Code__c = 'I';
    multCheck.Addressable_Spend_Multiplier__c = 3.0;
    insert multCheck;
    }
    
    @isTest static void testInitialValues(){
    acct.Sic='';
    system.assertequals(updatedSpendDetails, 0);
    system.assertequals(isPublic, false);
    system.assertequals(accToMult.Sic, NULL);
    system.assertequals(sicCode.size(), 0);
    system.assertequals(multiMap.addressMult, NULL);
    system.assertequals(acct.SC_Addressable_Spend__c, '');
    system.assertequals(acct.Account_Segmentation__c, '');
    system.assertequals(acct.Industry, '');
    system.assertequals(acct.Industry_Code__c, '');
    }
    
    @isTest static void testInvalidSIC(){
    acct.Sic='1110';
    try{
    update acct;
    throw new Exception('This should have failed, but instead succeeded.')
    }
    catch (Exception e){
    Boolean expectedExceptionThrown =  e.getMessage().contains('SIC not found')) ? true : false;
    System.AssertEquals(expectedExceptionThrown, true);
    system.assertequals(updatedSpendDetails, 0);
    system.assertequals(isPublic, false);
    system.assertequals(accToMult.Sic, NULL);
    system.assertequals(sicCode.size(), 0);
    system.assertequals(multiMap.addressMult, NULL);
    system.assertequals(acct.Addressable_Spend__c, '');
    system.assertequals(acct.Account_Segmentation__c, '');
    system.assertequals(acct.Industry, '');
    system.assertequals(acct.Industry_Code__c, '');
    }
    }
    
    @isTest static void testSicAdd(){
    acct.Sic = '1111';
    update acct;
    system.assert(multiMap.addressMult.size()>0, 'Error: sicCode not properly adding Account SIC to set');
    system.assert(addressMult.size()>0, 'Error: query of MultiplierMetadata__mdt table did not return and store records');
    }
        
    @isTest static void testIndustryCode(){
    acct.Sic='1111';
    update acct;
    system.assertequals(acct.Industry_Code__c, 'I');
    }
    
    @isTest static void testIndustryName(){
    acct.Sic='1111';
    update acct;
    system.assertequals(acct.Industry, 'Test');
    }
    
    @isTest static void testOneFieldBlank(){
    acct.NumberOfEmployees='';
    update acct;
    system.assertequals(acct.SIC__c, '1111');
    system.assertequals(acct.AnnualRevenue, 1000000);
    system.assertequals(updatedSpendDetails, 0);
    system.assertequals(acct.Addressable_Spend__c, '');
    system.assertequals(acct.Segment, '');
    }
    
    @isTest static void testNegativeEmployees(){
    acct.NumberOfEmployees = -1;
    system.assert(acct.SC_Addressable_Spend__c=0);
    system.assert(acct.Account_Segmentation__c='Emerging');
    }
    
    @isTest static void testPositiveEmployees(){
    acct.NumberOfEmployees = 101;
    update acct;
    system.assert(acct.);
    }
    
    @isTest static void testPutInRevenue(){
    update acct;
    system.assert(acct.Addressable_Spend__c=3000000);
    }
    
    @isTest static void testOverrideSegment(){
    acct.Account_Segmentation__c='C';
    acct.Override_Account_Segment__c=true;
    update acct;
    system.assertequals(acct.Account_Segmentation__c, 'Commercial');
    system.assertequals(acct.Segment_Calculated__c, 'SMB');
    }
    
    @isTest static void testNonOverridenSegment(){
    acct.Account_Segmentation__c='C';
    acct.Override_Account_Segment__c=false;
    update acct;
    system.assertequals(acct.Account_Segmentation__c, 'SMB');
    system.assertequals(acct.Segment_Calculated__c, 'SMB');
    }

    @isTest static void testPublicSectorSegment(){
    acct.NumberOfEmployees='';
    acct.AnnualRevenue=0;
    acct.Account_Segmentation__c='Commercial';
    acct.Sic='9621';
    update acct;
    system.assertequals(acct.Account_Segmentation__c, 'P');
    system.assertequals(acct.Segment_Calculated__c, 'P');
    }
    
}

I'm having issues when I save where it says "Error: Compile Error: Unexpected token '{'. at line 2 column 33"

I'm guessing I did something wrong in the formatting for creating my test data, but I'm not sure what. Any help is appreciated!
SandhyaSandhya (Salesforce Developers) 
Hi,

Check below line, I guess there is one extra closing bracket.
 
Boolean expectedExceptionThrown =  e.getMessage().contains('SIC not found')) ? true : false;

Best Regards,
Sandhya
VancouverDevVancouverDev
Thanks for catching that! Unfortunately that does not fix the unexpected token Account error that I'm getting.

Thanks!
@Amit Kumar Giri@Amit Kumar Giri
CreateTestData is a method. so it will be like below
public static void CreateTestData(){
Then once u save the code u will see some other error as i can see you are using instance variable "acct" in other method (like line no 21). You can not use like that. You inserted Account so u need to query that ans use again. Also in line no 22 you are usning "updatedSpendDetails" variable which is not exist. You need to declare , have assigned value and use in assert/assert equals
 
Raj VakatiRaj Vakati
try this code
 
@isTest 
private class TestValidateCorrectSIC{
     @testSetup 
	 static void CreateTestData{
    Account acct = new Account(Name='Test Account');
    acct.Sic='1111';
    acct.NumberOfEmployees=101;
    acct.AnnualRevenue=1000000;
    insert acct;
    
    MultiplierMetadata__mdt multCheck = new MultiplierMetadata__mdt();
    multCheck.SIC__c = '1111';
    multCheck.Employee_Lower_Bound__c = 100;
    multCheck.Employee_Upper_Bound__c = 102;
    multCheck.Industry__c = 'Test';
    multCheck.Industry_Code__c = 'I';
    multCheck.Addressable_Spend_Multiplier__c = 3.0;
    insert multCheck;
    }
    
    @isTest
	static void testInitialValues(){
		Account acct = [Select Id ,Name, Sic ,NumberOfEmployees ,SC_Addressable_Spend__c ,  Industry_Code__c , Account_Segmentation__c , AnnualRevenue from Account Limit 1 ] ; 
    acct.Sic='';
	 system.assertequals(acct.SC_Addressable_Spend__c, '');
    system.assertequals(acct.Account_Segmentation__c, '');
    system.assertequals(acct.Industry, '');
    system.assertequals(acct.Industry_Code__c, '');
    }
    
    @isTest 
	static void testInvalidSIC(){
    acct.Sic='1110';
			Account acct = [Select Id ,Name, Sic ,NumberOfEmployees ,SC_Addressable_Spend__c ,  Industry_Code__c , Account_Segmentation__c , AnnualRevenue from Account Limit 1 ] ; 

    try{
    update acct;
    throw new Exception('This should have failed, but instead succeeded.')
    }
    catch (Exception e){
     
    system.assertequals(sicCode.size(), 0);
     
    system.assertequals(acct.Addressable_Spend__c, '');
    system.assertequals(acct.Account_Segmentation__c, '');
    system.assertequals(acct.Industry, '');
    system.assertequals(acct.Industry_Code__c, '');
    }
    }
    
    @isTest static void testSicAdd(){
				Account acct = [Select Id ,Name, Sic ,NumberOfEmployees ,SC_Addressable_Spend__c ,  Industry_Code__c , Account_Segmentation__c , AnnualRevenue from Account Limit 1 ] ; 

    acct.Sic = '1111';
    update acct;
    
    
    }
        
    @isTest static void testIndustryCode(){
				Account acct = [Select Id ,Name, Sic ,NumberOfEmployees ,SC_Addressable_Spend__c ,  Industry_Code__c , Account_Segmentation__c , AnnualRevenue from Account Limit 1 ] ; 

    acct.Sic='1111';
    update acct;
    system.assertequals(acct.Industry_Code__c, 'I');
    }
    
    @isTest static void testIndustryName(){
				Account acct = [Select Id ,Name, Sic ,NumberOfEmployees ,SC_Addressable_Spend__c ,  Industry_Code__c , Account_Segmentation__c , AnnualRevenue from Account Limit 1 ] ; 

    acct.Sic='1111';
    update acct;
    system.assertequals(acct.Industry, 'Test');
    }
    
    @isTest static void testOneFieldBlank(){
				Account acct = [Select Id ,Name, Sic ,NumberOfEmployees ,SC_Addressable_Spend__c ,  Industry_Code__c , Account_Segmentation__c , AnnualRevenue from Account Limit 1 ] ; 

    acct.NumberOfEmployees='';
    update acct;
    system.assertequals(acct.SIC__c, '1111');
    system.assertequals(acct.AnnualRevenue, 1000000);
   
    system.assertequals(acct.Addressable_Spend__c, '');
    
    }
    
    @isTest static void testNegativeEmployees(){
				Account acct = [Select Id ,Name, Sic ,NumberOfEmployees ,SC_Addressable_Spend__c ,  Industry_Code__c , Account_Segmentation__c , AnnualRevenue from Account Limit 1 ] ; 

    acct.NumberOfEmployees = -1;
    system.assert(acct.SC_Addressable_Spend__c=0);
    system.assert(acct.Account_Segmentation__c='Emerging');
    }
    
    @isTest static void testPositiveEmployees(){
				Account acct = [Select Id ,Name, Sic ,NumberOfEmployees ,SC_Addressable_Spend__c ,  Industry_Code__c , Account_Segmentation__c , AnnualRevenue from Account Limit 1 ] ; 

    acct.NumberOfEmployees = 101;
    update acct;
    
    }
    
    @isTest static void testPutInRevenue(){
				Account acct = [Select Id ,Name, Sic ,NumberOfEmployees ,SC_Addressable_Spend__c ,  Industry_Code__c , Account_Segmentation__c , AnnualRevenue from Account Limit 1 ] ; 

    update acct;
 
    }
    
    @isTest static void testOverrideSegment(){
				Account acct = [Select Id ,Name, Sic ,NumberOfEmployees ,SC_Addressable_Spend__c ,  Industry_Code__c , Account_Segmentation__c , AnnualRevenue from Account Limit 1 ] ; 

    acct.Account_Segmentation__c='C';
    acct.Override_Account_Segment__c=true;
    update acct;
    system.assertequals(acct.Account_Segmentation__c, 'Commercial');
    system.assertequals(acct.Segment_Calculated__c, 'SMB');
    }
    
    @isTest static void testNonOverridenSegment(){
				Account acct = [Select Id ,Name, Sic ,NumberOfEmployees ,SC_Addressable_Spend__c ,  Industry_Code__c , Account_Segmentation__c , AnnualRevenue from Account Limit 1 ] ; 

    acct.Account_Segmentation__c='C';
    acct.Override_Account_Segment__c=false;
    update acct;
    system.assertequals(acct.Account_Segmentation__c, 'SMB');
    system.assertequals(acct.Segment_Calculated__c, 'SMB');
    }

    @isTest static void testPublicSectorSegment(){
				Account acct = [Select Id ,Name, Sic ,NumberOfEmployees ,SC_Addressable_Spend__c ,  Industry_Code__c , Account_Segmentation__c , AnnualRevenue from Account Limit 1 ] ; 

    acct.NumberOfEmployees='';
    acct.AnnualRevenue=0;
    acct.Account_Segmentation__c='Commercial';
    acct.Sic='9621';
    update acct;
    system.assertequals(acct.Account_Segmentation__c, 'P');
    system.assertequals(acct.Segment_Calculated__c, 'P');
    }
    
}