You need to sign in to do that
Don't have an account?
Small Problem on Trigger re Events & Inbound mail Service
Error: Compile Error: unexpected token: 'Messaging.InboundEmail' at line 71 column 3 is the error received on below.
Any ideas ?
global class tasks implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email,
Messaging.InboundEnvelope env){
// Create an inboundEmailResult object for returning
// the result of the Force.com Email Service
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
String myPlainText = '';
// Add the email plain text into the local variable
try
{
myPlainText = email.plainTextBody.substring(0, email.plainTextBody.indexOf('<stop>'));
}
catch (System.StringException e)
{
myPlainText = email.plainTextBody;
System.debug('No <stop> in email: ' + e);
}
// new Event object to be created
Event[] newEvent = new Event[0];
// Try to lookup any contacts based on the email from address
// If there is more than 1 contact with the same email address
// an exception will be thrown and the catch statement will be called
try {
Contact vCon = [Select Id, Name, Email
From Contact
Where Email = :email.fromAddress
Limit 1];
// Add a new Event to the contact record we just found above
newEvent.add(new Event(Description = myPlainText,
Subject = email.subject,
ActivityDate = Date.today(),
IsReminderSet = false,
ReminderDateTime = System.now()+1,
IsAllDayEvent = True,
WhoId = vCon.Id));
// Insert the new Task and it will be created and appended to the contact record
insert newEvent;
System.debug('New Event Object: ' + newEvent );
}
// If there is an exception with the query looking up
// the contact this QueryException will be called.
// and the exception will be written to the Apex Debug logs
catch (System.QueryException e) {
System.debug('Query Issue: ' + e);
}
// Set the result to true, no need to send an email back to the user
// with an error message
result.success = true;
// Return the result for the Force.com Email Service
return result;
}
static testMethod void testEvents {
// Create a new email and envelope object
Messaging.InboundEmail email = new Messaging.InboundEmail();
Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
// Create the plainTextBody and fromAddres for the test
email.plainTextBody = 'Here is my plainText body of the email';
email.fromAddress ='rmencke@salesforce.com';
Events eventObj = new Events();
taskObj.handleInboundEmail(email, env);
}
}