I have created email service and its activate and anyone can send email. When i'm sending email from gmail into salesforce it showing error in debug log that
Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Assigned To ID: id value of incorrect type: 0039E000002PRSZQA4: [OwnerId]
how to create task when email match to existing email of contact
global class ContactFrmEmail implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
String con_Email = envelope.fromAddress;
System.debug('--@@--con_Email--'+con_Email);
List<Contact> con = [SELECT Id, Email FROM contact WHERE email =: con_EMail LIMIT 1];
System.debug('--@@--con--'+con);
if(con[0].email == con_Email) {
Task T = new Task();
T.Type = 'Email';
T.OwnerId = con[0].id; //user id
//T.WhatId = ; //record id
insert T;
}
result.success = true;
return result;
}
}