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 Aug 16 '17 at 15:36

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 Aug 16 '17 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 Aug 16 '17 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.