2

Im receiving

Invalid type: Schema.EmailMessageRelation

and

Invalid type: EmailMessageRelation

compiler error while saving the code.

public class twilioSmsTriggerHandler {
    public twilioSmsTriggerHandler() {

    }
    list<Id> emailIdList = new list<Id>();

    public void newEmails(List<EmailMessage> emails) {
        for(EmailMessage emailId : emails) {            
            emailIdList.add(emailId.Id);
        }

        for(EmailMessageRelation emailmsgId : [SELECT EmailMessageId,
                                                      RelationAddress,
                                                      RelationId,
                                                      RelationObjectType,
                                                      RelationType
                                               FROM EmailMessageRelation
                                               WHERE EmailMessageId =: emailIdList]) {  

        system.debug(emailmsgId);
    }

    }
}
2
  • 3
    As stated in the SOAP Reference, "EmailMessageRelation is only available for organizations that use Email-to-Case or Enhanced Email, which is automatically enabled for most customers." and is available only in API 37 and up. Are you meeting those conditions?
    – David Reed
    Commented Jan 29, 2019 at 4:02
  • thanks for your response. now the issue is resolved. i got this error when i edit it in code editor. when i saved the code on org i didn't get the error and the code is saved
    – Eswari
    Commented Jan 30, 2019 at 9:32

1 Answer 1

2

I'm moving this comment to an answer because I don't see that the question has been clarified.

The SOAP Reference for EmailMessageRelation states:

EmailMessageRelation is only available for organizations that use Email-to-Case or Enhanced Email, which is automatically enabled for most customers.

Further, the object is available only in API 37 and up.

It's not likely that your org doesn't have Enhanced Email turned on, but it's certainly possible. You should also confirm that the class you are working on is on at least API version 37.0, and preferably more recent.

1
  • Indeed, I had to move my class to 53.0 version
    – Damecek
    Commented Feb 25, 2022 at 15:56

You must log in to answer this question.

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