0

I am trying to read the "toAddresses" field in apex in global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env)

I getting an error: Invalid initial expression type for field Email_PO__c.email_toAddresses__c, expecting: String

I suspect I need some code to convert this field of data to a string separated by commas? enter image description here

1 Answer 1

1

email.toAddresses is a String[] (List of strings);

What you will need to do is iterate through them to get the one you want.

If all you want is the first one, without checking to confirm its value you can use

email_toAddresses__c = email.toAddresses.isEmpty() ? null : email.toAddresses[0];

if you want the entire list of strings and the email_toAddress__c is NOT an email field but rather a text field you can simply use

email_toAddresses__c = email.toAddresses.isEmpty() ? null : string.valueOf(email.toAddresses);

You must log in to answer this question.

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