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
Arnold BrownArnold Brown 

if statement fails with boolean error for picklist field on Account Team Member Object

I'm just trying to write a simple if statement to check the piclist value for TeammemberRole on Account Team object. I've tried it with double equalls signs "==" and using string method .equals().  No matter what I try I continue to get the error. "Condition expression must be of type boolean.  It should be a simple thing but it's stopping me cold. 
Here's how it looks currently:
 
for(AccountTeamMember member:  ATM ){
            if (member.TeamMemberRole == 'CRD - Back-up' ){
               BackupCRDMap.put(member.Account.id, member.user.name);
               }

 



 
Best Answer chosen by Arnold Brown
Prateek Singh SengarPrateek Singh Sengar
The issue is in statement
else if (member.TeamMemberRole = 'CRM')

change it to

else if (member.TeamMemberRole == 'CRM')

this should fix the error. Hope this helps.

All Answers

Prateek Singh SengarPrateek Singh Sengar
Hi Arnold,
The correct syntax is using == in if statement. Can you please share the exact error message and larger code snippet. 
Arnold BrownArnold Brown
Sure thing, thanks for helping 

Error is "Condition expression must be of type boolean"

What I'm trying to do is write a scheduled class to iterate through our Account Team member records each night and populate custom fields I've set up on the account record itself to show the values.   This is because reporting on Oppotunities for instance and including Account Team membership is difficult.  So since I can't trigger the update to the Account Custom fields from the Account Team Member object I'm trying a solution with schedulable batch apex.  Here's the (unfinished ) code I have so far: 
 
global class UpdateAccountTeamFields implements Schedulable {
    
    global void execute (SchedulableContext ctx){
        Map< id, string> BackupCRDmap            = New Map <id, String>();
        List<Account> backupAccts2Update    = New List <Account>();
        Map< id, string> CollegeCoachCRDMap = New Map <id, String>();
        Map< id, string> BackupNCRDMap      = New Map <id, String>();
        Map< id, string> CenterCRDMap       = New Map <id, String>();
        Map< id, string> EdAssistCRD        = New Map <id, String>();
        Map< id, string> UKCRDMap           = New Map <id, String>();
        Map< id, string> TransitionCRDmap   = New Map <id, String>();
        Map< id, string> CSDMap             = New Map <id, String>();
        Map< id, string> EdassistCSDMap     = New Map <id, String>();    
        
        List <AccountTeamMember> ATM = [SELECT id,  AccountId, User.Name, TeamMemberRole,
                                                    Account.CRD_Back_up_gsrule__c,
                                            		Account.CRD_Center_gsrule__c,
        									  		Account.CRD_College_Coach_gsrule__c,
        									  		Account.CRD_EdAssist__c,
        									 		Account.CRD_UK_gsrule__c,
                                                 	Account.CSD_gsrule__c,
        									 		Account.CSD_Edassist__c,
        									 		Account.CSD_UK_gsrule__c
                                        FROM AccountTeamMember ORDER BY Accountid];
        system.debug('....number of Acct team member records = ' +ATM.size());
        system.debug(ATM.size()); 
      
        for(AccountTeamMember member:  ATM ){
            if(member.TeamMemberRole == 'CRD - Back-up'){
             BackupCRDMap.put(member.Account.id, member.user.name);
              } 
            else if (member.TeamMemberRole == 'CRD - College Coach'){
                CollegeCoachCRDMap.put(member.Accountid, member.user.name);
            }
            else if (member.TeamMemberRole == 'CRD - College Coach/Backup'){
                BackupNCRDMap.put(member.AccountId, member.user.name);
            }
            else if (member.TeamMemberRole == 'CRD - Center'){
                BackupNCRDMap.put(member.AccountId, member.user.name);
            }            
            else if (member.TeamMemberRole == 'CRD - EdAssist'){
                BackupNCRDMap.put(member.AccountId, member.user.name);
            }           
             else if (member.TeamMemberRole == 'CRD - Transition'){
                BackupNCRDMap.put(member.AccountId, member.user.name);
            }         
             else if (member.TeamMemberRole == 'CRD - UK'){
                BackupNCRDMap.put(member.AccountId, member.user.name);
            }
            else if (member.TeamMemberRole == 'CRD & CSD UK'){
                BackupNCRDMap.put(member.AccountId, member.user.name);
            }            
            else if (member.TeamMemberRole == 'CSD'){
                BackupNCRDMap.put(member.AccountId, member.user.name);
            }           
             else if (member.TeamMemberRole == 'CSD - EdAssist'){
                BackupNCRDMap.put(member.AccountId, member.user.name);
            }        
            else if (member.TeamMemberRole == 'CSD - UK'){
                BackupNCRDMap.put(member.AccountId, member.user.name);
            }           
             else if (member.TeamMemberRole = 'CRM'){
                BackupNCRDMap.put(member.AccountId, member.user.name);
            }             
         //    else if (member.TeamMemberRole != any other remaining values'){
                //Then create an email message warning of a new Acct team name value and alerting admins of a need to 
                //edit this scheduled batch update class. ;
            }
          // Next step is to find a way to write the values in the maps of Account id and User Name to the               
          //Account custom fields that mirror account team info.              
        }
    }

 
Prateek Singh SengarPrateek Singh Sengar
The issue is in statement
else if (member.TeamMemberRole = 'CRM')

change it to

else if (member.TeamMemberRole == 'CRM')

this should fix the error. Hope this helps.
This was selected as the best answer
Arnold BrownArnold Brown
Wow.  This is great.   The error message was calling out line 29.  The error you pointed out is on line 62 and I completely missed looking that far down the code.  That means the whole if > else logic is reported in the compler on the first "if" line.  I had no idea and wasn't looking any further down in the code.  Thanks so much!  Lesson learned.