You need to sign in to do that
Don't have an account?
Sateesh Kumar
Test Class
CAN SOME ONE HELP ME WITH TEST CLASS.
global class CreateTaskAttchmentEmailExample implements Messaging.InboundEmailHandler { global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env){ Messaging.InboundEmailResult result = new Messaging.InboundEmailResult(); String myPlainText= ''; myPlainText = email.plainTextBody; Task[] newTask = new Task[0]; try { Contact vCon = [SELECT Id, Name, Email FROM Contact WHERE Email = :email.toAddresses LIMIT 1]; newTask.add(new Task( Priority = 'Normal', Status = 'Inbound Email', Subject = email.subject, WhoId = vCon.Id)); insert newTask; system.debug('===Addresses==>>>'+vCon.Id); System.debug('New Task Object: ' + newTask ); Attachment attachment = new Attachment(); attachment.Body = Blob.valueOf(email.plainTextBody); attachment.Name = email.subject; attachment.ParentId = vCon.Id; insert attachment; } catch (QueryException e) { System.debug('Query Issue: ' + e); } result.success = true; return result; } }
global class CreateTaskAttchmentEmailExample implements Messaging.InboundEmailHandler { global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env){ Messaging.InboundEmailResult result = new Messaging.InboundEmailResult(); String myPlainText= ''; myPlainText = email.plainTextBody; Task[] newTask = new Task[0]; try { Contact vCon = [SELECT Id, Name, Email FROM Contact WHERE Email = :email.toAddresses LIMIT 1]; newTask.add(new Task( Priority = 'Normal', Status = 'Inbound Email', Subject = email.subject, WhoId = vCon.Id)); insert newTask; system.debug('===Addresses==>>>'+vCon.Id); System.debug('New Task Object: ' + newTask ); Attachment attachment = new Attachment(); attachment.Body = Blob.valueOf(email.plainTextBody); attachment.Name = email.subject; attachment.ParentId = vCon.Id; insert attachment; } catch (QueryException e) { System.debug('Query Issue: ' + e); } result.success = true; return result; } }
Hre is the sample code:
https://developer.salesforce.com/page/Code_Sample_-_Testing_Email_Services_with_Inbound_Attachments
Thanks,
Pratik