Hi I'm getting this error on the code below:

Error: Compile Error: Comparison arguments must be compatible types: User, String at line 147 column 15

Can anyone help with the last line (147)?

    if(currentCase.RecordTypeId == custReqRecType.Id 
       && currentCase.Status == '01-New' 
       && currentCase.Kinnser_closed_on_create__c == FALSE
       && currentCase.Email__c != NULL
       && currentCase.Do_Not_Send_Case_Email__c == FALSE
       && currentCase.CreatedBy != 'Client Services Integrations'){
  • And also make sure you have queried currentCase.CreatedBy.Name.
    – Keith C
    Commented Aug 16, 2017 at 15:36

2 Answers 2


It needs to be currentCase.CreatedBy.Name when you do currentCase.CreatedBy it is expecting the User object.

  • 2
    @Heather - When an answer solves your problem you can Thank the person who answered by uprooting and accepting the answer. Both you and the person who answered get +rep for that. More importantly, it helps others with similar questions find answers.
    – Eric
    Commented Aug 16, 2017 at 16:32

Use currentCase.CreatedBy.name

createdby is storing an id of a related record so you need to specify the field in the related record that you want to compare

  • 2
    Technically the CreatedBy is a User object. If it was an Id the string comparison would be valid and throw a runtime 'Invalid Id" error and not a compile time error.
    – Eric
    Commented Aug 16, 2017 at 16:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .