-
Create multiple records with one email
Hello,
I have created a feedback object in my org. I want to create a record whenever I send a mail to salesforce. So with the help of email services I generated an email address and whenever I send a mail from my Gmail to that email address a new record is created in feedback.
What is want now is to create multiple feedback.
Suppose email template format is:
Article ID: 10001;10002;10003;
Description: Link not working
For the above format what I want is to create 3 records with the same description for all 3.
Here is my code. Can you tell me what changes I have to make in it so that the above functionality is working?global class CreateTaskEmailExample implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email,
Messaging.InboundEnvelope env){
// Create an InboundEmailResult object for returning the result of the
// Apex Email Service
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
String myPlainText= '';
// Add the email plain text into the local variable
myPlainText = email.plainTextBody;
// New Task object to be created
Feedback__c[] newFeedback = new Feedback__c[0];
// Try to look up any contacts based on the email from address
// If there is more than one 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 Task to the contact record we just found above.
newFeedback.add(new Feedback__c(Description__c = myPlainText,
Status__c = 'Inbound Email',
Subject__c = email.subject,
IsRemainderSet__c = true,
Date__c = System.now()+1));
// Insert the new Task
insert newFeedback;
System.debug('New Task Object: ' + newFeedback );
}
// If an exception occurs when the query accesses
// the contact record, a QueryException is called.
// The exception is written to the Apex debug log.
catch (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 Apex Email Service
return result;
}Thanks
Log In to reply.
Popular Salesforce Blogs
What is Salesforce Community Cloud?
Originally named ‘Salesforce Customer and Partner Portals’, Community Cloud is among the most popular cloud options from Salesforce. As with the rest of the platform,…
What are the top Salesforce Implementation and Consulting Partners for 2023?
Businesses are constantly improving their operations in order to maximize returns on investment. Salesforce CRM is the platform that provides the highest ROI. However, implementing it…
Navigate your Career in Salesforce | Salesforce Guidance
How to start a career in Salesforce as a fresher or how to switch in Salesforce from any technology or domain? Salesforce is a Saas-based…
Popular Salesforce Videos
What is Salesforce Hyperforce?
In this video, you will take a look at Salesforce Hyperforce, Salesforce's new re-architecting of the Salesforce platform. 00:00 Introduction 00:28 What is Salesforce Hyperforce?…
What is Salesforce Apex Trigger | When to use Salesforce Apex Trigger | Type of Salesforce Apex Trigger
In this video, we are going to learn some basic concepts of Apex trigger. Below is the Agenda. Video Resource: SFDC Panther
Dreamforce 2020 FAQs | Dreamforce To You | Salesforce Event
As the COVID-19 situation continues to evolve, questions around virtual Dreamforce 2020 continue to increase and that's why we've gone ahead and answered all the…
Popular Salesforce Infographics
How Your Business Can Leverage The Power of Salesforce Community Cloud?
Community Cloud is a cloud-based platform that enables businesses (small, medium, big) to build exceptional and interactive CRM-powered portals, forums, and sites that are faster…
7 Must Know Features on the New Salesforce AppExchange
Personalized recommendations, intelligent search, and new solutions are just a few of the exciting new features on the brand new AppExchange. Check it out at…
Salesforce Marketing Automation: Sales or Marketing Tool? [infographic]
Marketing automation has a hidden talent. Despite being marketed for years as a tool for, well, marketers, automation is changing the shape of the modern…