• VancouverDev
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 7
    Replies
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!
Hi All,

I've been working on this trigger for a few days and I'm stumped. I think I've managed to mostly bulkify it properly, but every time I go in and touch records using the Data Loader it fails to update the fields I would expect. If I edit/save through the UI it fires perfectly every time.
 
trigger ValidateCorrectSIC on Account (before update) {
    //First, create a set of all the SICs present in the Account update
    Set<String> setOfSics = new Set<String>();
    for(Integer i= 0 ; i < Trigger.new.size(); i++)
    {
    setOfSics.add(Trigger.new[i].Sic);
    }
    //Then, set up a list to store records returned by our query (based on SIC)
    List <MultiplierMetadata__mdt> queryDetails = [SELECT Id,Addressable_Spend_Multiplier__c,Employee_Lower_Bound__c,Employee_Upper_Bound__c,Industry__c,Industry_Code__c,SIC__c FROM MultiplierMetadata__mdt WHERE SIC__c IN :setOfSics];
    Set<String> accurateSics = new Set<String>();
    for(Integer i= 0 ; i < querydetails.size(); i++){
    accurateSics.add(querydetails[i].SIC__c);
    }
    for (Account a : Trigger.new) {
    //IF wrapper to check if SIC is filled. If it's not, then exit.
    IF (a.Sic!=NULL){
    //Check if any records were returned for the SIC query above

        IF (accurateSics.contains(a.SIC)) {
        //Assuming that there's a valid SIC, fill in the industry code from that SIC
        for (MultiplierMetadata__mdt q:queryDetails){
                    IF(q.SIC__c.equals(a.SIC)){
                    a.Industry_Code__c = q.Industry_Code__c;
                    a.Industry = q.Industry__c;
                    }
                }
            //IF wrapper to check that all three fields are filled in. If they aren't, no need to do anything further.
            IF (a.NumberOfEmployees!=NULL && a.Sic!=NULL && a.AnnualRevenue!=NULL) {
            UpdateAccountSegment thisAccount= new UpdateAccountSegment();
                //IF wrapper to catch employees 0 and negative employees (why? who knows?) and set the Addressable Spend to 0
                IF (a.NumberOfEmployees>0){
                Decimal multiplierAmount = 0;
                //Once we've established that the data is all there, call the class
                for (MultiplierMetadata__mdt q:queryDetails){
                    IF(q.Employee_Lower_Bound__c<=a.NumberOfEmployees&&q.Employee_Upper_Bound__c>=a.NumberOfEmployees){
                            multiplierAmount=q.Addressable_Spend_Multiplier__c;
                    }
                }
               //Multiply the data passed to the method by the multiplierAmount from the query to get the final value
               Decimal finalSpendAmount = multiplierAmount * a.AnnualRevenue;
               //Return the correctly calculated Addressable Spend value and the industry code to the trigger for updating on the Account
               a.SC_Addressable_Spend__c= finalSpendAmount;
               if(a.Override_Account_Segment__c!=true){
                        a.Account_Segmentation__c=thisAccount.UpdateSegment(finalSpendAmount, a.Sic);
                        a.Segment_Calculated__c=thisAccount.UpdateSegment(finalSpendAmount, a.Sic);
                        return;
                    }
                    else{
                    a.Segment_Calculated__c=thisAccount.UpdateSegment(finalSpendAmount, a.Sic);
                    return;
                    }
                }
                else{
                    a.SC_Addressable_Spend__c=0;
                    if(a.Override_Account_Segment__c!=true){
                        a.Account_Segmentation__c=thisAccount.UpdateSegment(0, a.Sic);
                        a.Segment_Calculated__c=thisAccount.UpdateSegment(0, a.Sic);
                        return;
                    }
                    else{
                    a.Segment_Calculated__c=thisAccount.UpdateSegment(0, a.Sic);
                    return;
                    }
                }
            }
            else {
                return;
                }
        } else {
            //If no records were returned for the SIC on the initial query, prevent the Account update and throw an error
            a.addError('SIC not found, please add a correctly formatted SIC from internal list');
            }
    }else{
return;}}}

And here's the class it calls for Update Segment
 
global class UpdateAccountSegment {
    public String UpdateSegment(Decimal spendTotal, String accountSIC){
        List<String> segment = new List<String>();
        IF(accountSIC =='8211' ||
        accountSIC =='8221'){ 
                segment.add('P');
            }
        if(spendTotal<500){
            segment.add('E');
        }
        if(spendTotal>=500 && spendTotal<2000){
            segment.add('S');
        }
        if(spendTotal>=2000 && spendTotal<10000){
            segment.add('C');
        }
        if(spendTotal>=10000 && spendTotal<50000){
            segment.add('E2');
        }
        if(spendTotal>=50000){
            segment.add('G') ;
        }
        if(segment.size()>0){
        return segment[0];
        }
        else{
        return null;
        }
    }
}

 
Hi everyone,

Running into issues with this code. It's just supposed to respond to different SIC with different values to be put in the Segment field.
trigger UpdateAccountSegment on Account (after update) {
List<String> segment() = new List<String>();
for (Account a : Trigger.new){
IF( 
a.Sic ='8211' || 
a.Sic ='8221' || 
a.Sic ='8222' || 
a.Sic ='8231' || 
a.Sic ='8243' || 
a.Sic ='8244' || 
a.Sic ='8249' || 
a.Sic ='8299' || 
a.Sic ='9111' || 
a.Sic ='9121' || 
a.Sic ='9131' || 
a.Sic ='9199' || 
a.Sic ='9211' || 
a.Sic ='9221' || 
a.Sic ='9222' || 
a.Sic ='9223' || 
a.Sic ='9224' || 
a.Sic ='9229' || 
a.Sic ='9311' || 
a.Sic ='9411' || 
a.Sic ='9431' || 
a.Sic ='9441' || 
a.Sic ='9451' || 
a.Sic ='9511' || 
a.Sic ='9512' || 
a.Sic ='9531' || 
a.Sic ='9532' || 
a.Sic ='9611' || 
a.Sic ='9621' || 
a.Sic ='9631' || 
a.Sic ='9641' || 
a.Sic ='9651' || 
a.Sic ='9661' || 
a.Sic ='9711' || 
a.Sic ='9721'){ 
segment.add('Butter')
};
else if(a.Spend__c<500000 && a.Spend__c<>0){
segment.add('Avocado')
};
else if(a.Spend__c>=500000 && a.Spend__c<2000000){
segment.add('Toast')
};
else if(a.Spend__c>=2000000 && a.Spend__c<10000000){
segment.add('Bagels')
};
else if(a.Spend__c>=10000000 && a.Spend__c<50000000){
segment.add('Donuts')
};
else if(a.SC_Addressable_Spend__c>=50000000){
segment.add('Pizza') 
};
else return
};
IF (segment=a.Account_Segmentation__c){
return
};
else {
a.Account_Segmentation__c=segment;
update a;
};
}

I'm getting the following errors:
Unexpected Token '<' at Line 2, for both <
And then "Extra ; at }" on 41, 44, 47, 50, 53, 56, 58, 61
And finally "Extra { at ;" on line 65

If anyone can provide editing help or tell me what I'm doing wrong I'd appreciate it!
Hi everyone,

I'm confused about the errors I'm getting on my code below. It's a trigger meant to fire on the Account object, check that there's a matching metadata table entity, call a class to query the metadata table, and provide an updated number prior to the Account update operation.
 
trigger ValidateCorrectSIC on Account (before update) {
	for (Account a : Trigger.new) {
	//IF wrapper to check that all three fields are filled in. If they aren't, no need to do anything further.
	IF (a.NumberOfEmployees!=NULL && a.Sic!=NULL && a.AnnualRevenue!=NULL) {
	//First, set up a list to store records returned by our validation query
		List<> spendTableRecords = new List<>();
		//Find if there's any Addressable Spend Multiplier records with a matching SIC
		spendTableRecords.add([SELECT * FROM MultiplierMetadata__mdt WHERE SIC__c = get(a.Sic)]);
		//Check if any records were returned for the SIC query above
			IF (spendTableRecords.size() > 0) {
			//Assuming the SIC query returned a value, and therefore it's a correct SIC, call the class
			Decimal updatedSpendAmount = AddressableSpend.CalculateAddressableSpend (a.NumberOfEmployees, a.Sic, a.AnnualRevenue);
			//Check that the returned value and the current value are different. If they are, update the Account. If not, then exit.
				IF (updatedSpendAmount != get(a.Addressable_Spend__c)&&Override_Account_Segment__c!=1){
					a.Addressable_Spend__c = updatedSpendAmount;
					update a;
				} else {
				return;
				}
			} else {
			//If no records were returned for the SIC, prevent the Account update and throw an error
			a.addError('SIC not found, please add a correctly formatted SIC from internal list');
			}
	}
}
}

The errors I'm getting start at line 6 where it's throwing "Unexpected token 'List'" twice, an "Expecting '<' but was '<>'," and an "Unexpected token ')'"

All subsequent errors are either more unexpected token errors, or are based out of the fact the spendTableRecords wasn't declared. Any help with identifying what changes I need to make to prevent it from throwing unexpected token errors? Thanks!
Hi everyone,

Hoping someone can have a look and help me identify my problem. I've been working on the code in a fragmented, few-minutes-at-a-time way and I'm kind of stuck.

Here's the class:
global class AddressableSpend  {

public static Decimal CalculateAddressableSpend(Integer employees, Integer accountSIC, Decimal revenue){
	//Create a variable to store the results of our query, Query the Addressable Spend metadata table to get the appropriate records.
	Decimal multiplierResults = new Decimal
	multiplierResults = [SELECT Addressable_Spend_Multiplier__c FROM MultiplierMetadata__mdt  WHERE (employees>=Employee_Lower_Bound__c && employees <= Employee_Upper_Bound__c && accountSIC == SIC__c) LIMIT 1]
	//Use the Addressable Spend Multiplier from the retrieved record to multiply the revenue
	Decimal finalSpendAmount = multiplierResults * revenue;
	return finalSpendAmount;
	}
}

I'm trying to call this class from a trigger, which will pass in the three variables employees, accountSIC, and revenue. The class is supposed to return the multiplied revenue value (here labeled as finalSpendAmount) to the trigger to update the Account.

I'm getting four errors on the above code. Two are "expecting ; but was )" and "expecting ; but was ]" so I'm putting them aside for the moment. The ones I'm more concerned about are "Unexpected token 'multiplierResults'" and "Unexpected token 'Employee_Lower_Bound__c'" I've declared the multiplierResults variable, and I've encapsulated the query in [], so I'm not sure why those two are throwing errors.

If anyone can point me to the probably-quite-simple fix I'd appreciate it. Thanks for the help!
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!
Hi All,

I've been working on this trigger for a few days and I'm stumped. I think I've managed to mostly bulkify it properly, but every time I go in and touch records using the Data Loader it fails to update the fields I would expect. If I edit/save through the UI it fires perfectly every time.
 
trigger ValidateCorrectSIC on Account (before update) {
    //First, create a set of all the SICs present in the Account update
    Set<String> setOfSics = new Set<String>();
    for(Integer i= 0 ; i < Trigger.new.size(); i++)
    {
    setOfSics.add(Trigger.new[i].Sic);
    }
    //Then, set up a list to store records returned by our query (based on SIC)
    List <MultiplierMetadata__mdt> queryDetails = [SELECT Id,Addressable_Spend_Multiplier__c,Employee_Lower_Bound__c,Employee_Upper_Bound__c,Industry__c,Industry_Code__c,SIC__c FROM MultiplierMetadata__mdt WHERE SIC__c IN :setOfSics];
    Set<String> accurateSics = new Set<String>();
    for(Integer i= 0 ; i < querydetails.size(); i++){
    accurateSics.add(querydetails[i].SIC__c);
    }
    for (Account a : Trigger.new) {
    //IF wrapper to check if SIC is filled. If it's not, then exit.
    IF (a.Sic!=NULL){
    //Check if any records were returned for the SIC query above

        IF (accurateSics.contains(a.SIC)) {
        //Assuming that there's a valid SIC, fill in the industry code from that SIC
        for (MultiplierMetadata__mdt q:queryDetails){
                    IF(q.SIC__c.equals(a.SIC)){
                    a.Industry_Code__c = q.Industry_Code__c;
                    a.Industry = q.Industry__c;
                    }
                }
            //IF wrapper to check that all three fields are filled in. If they aren't, no need to do anything further.
            IF (a.NumberOfEmployees!=NULL && a.Sic!=NULL && a.AnnualRevenue!=NULL) {
            UpdateAccountSegment thisAccount= new UpdateAccountSegment();
                //IF wrapper to catch employees 0 and negative employees (why? who knows?) and set the Addressable Spend to 0
                IF (a.NumberOfEmployees>0){
                Decimal multiplierAmount = 0;
                //Once we've established that the data is all there, call the class
                for (MultiplierMetadata__mdt q:queryDetails){
                    IF(q.Employee_Lower_Bound__c<=a.NumberOfEmployees&&q.Employee_Upper_Bound__c>=a.NumberOfEmployees){
                            multiplierAmount=q.Addressable_Spend_Multiplier__c;
                    }
                }
               //Multiply the data passed to the method by the multiplierAmount from the query to get the final value
               Decimal finalSpendAmount = multiplierAmount * a.AnnualRevenue;
               //Return the correctly calculated Addressable Spend value and the industry code to the trigger for updating on the Account
               a.SC_Addressable_Spend__c= finalSpendAmount;
               if(a.Override_Account_Segment__c!=true){
                        a.Account_Segmentation__c=thisAccount.UpdateSegment(finalSpendAmount, a.Sic);
                        a.Segment_Calculated__c=thisAccount.UpdateSegment(finalSpendAmount, a.Sic);
                        return;
                    }
                    else{
                    a.Segment_Calculated__c=thisAccount.UpdateSegment(finalSpendAmount, a.Sic);
                    return;
                    }
                }
                else{
                    a.SC_Addressable_Spend__c=0;
                    if(a.Override_Account_Segment__c!=true){
                        a.Account_Segmentation__c=thisAccount.UpdateSegment(0, a.Sic);
                        a.Segment_Calculated__c=thisAccount.UpdateSegment(0, a.Sic);
                        return;
                    }
                    else{
                    a.Segment_Calculated__c=thisAccount.UpdateSegment(0, a.Sic);
                    return;
                    }
                }
            }
            else {
                return;
                }
        } else {
            //If no records were returned for the SIC on the initial query, prevent the Account update and throw an error
            a.addError('SIC not found, please add a correctly formatted SIC from internal list');
            }
    }else{
return;}}}

And here's the class it calls for Update Segment
 
global class UpdateAccountSegment {
    public String UpdateSegment(Decimal spendTotal, String accountSIC){
        List<String> segment = new List<String>();
        IF(accountSIC =='8211' ||
        accountSIC =='8221'){ 
                segment.add('P');
            }
        if(spendTotal<500){
            segment.add('E');
        }
        if(spendTotal>=500 && spendTotal<2000){
            segment.add('S');
        }
        if(spendTotal>=2000 && spendTotal<10000){
            segment.add('C');
        }
        if(spendTotal>=10000 && spendTotal<50000){
            segment.add('E2');
        }
        if(spendTotal>=50000){
            segment.add('G') ;
        }
        if(segment.size()>0){
        return segment[0];
        }
        else{
        return null;
        }
    }
}

 
Hi everyone,

Hoping someone can have a look and help me identify my problem. I've been working on the code in a fragmented, few-minutes-at-a-time way and I'm kind of stuck.

Here's the class:
global class AddressableSpend  {

public static Decimal CalculateAddressableSpend(Integer employees, Integer accountSIC, Decimal revenue){
	//Create a variable to store the results of our query, Query the Addressable Spend metadata table to get the appropriate records.
	Decimal multiplierResults = new Decimal
	multiplierResults = [SELECT Addressable_Spend_Multiplier__c FROM MultiplierMetadata__mdt  WHERE (employees>=Employee_Lower_Bound__c && employees <= Employee_Upper_Bound__c && accountSIC == SIC__c) LIMIT 1]
	//Use the Addressable Spend Multiplier from the retrieved record to multiply the revenue
	Decimal finalSpendAmount = multiplierResults * revenue;
	return finalSpendAmount;
	}
}

I'm trying to call this class from a trigger, which will pass in the three variables employees, accountSIC, and revenue. The class is supposed to return the multiplied revenue value (here labeled as finalSpendAmount) to the trigger to update the Account.

I'm getting four errors on the above code. Two are "expecting ; but was )" and "expecting ; but was ]" so I'm putting them aside for the moment. The ones I'm more concerned about are "Unexpected token 'multiplierResults'" and "Unexpected token 'Employee_Lower_Bound__c'" I've declared the multiplierResults variable, and I've encapsulated the query in [], so I'm not sure why those two are throwing errors.

If anyone can point me to the probably-quite-simple fix I'd appreciate it. Thanks for the help!