-
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
Salesforce Chatbot: Streamlining Customer Service and Support
Introduction Salesforce Chatbot is an AI-powered conversational agent designed to interact with customers in a natural and human-like manner. It leverages advanced NLP algorithms and…
Why Do Businesses Need Salesforce in 2021?
As a cloud-based CRM platform, Salesforce provides businesses with the means to manage their events and tasks and track customer cases. It also allows the…
Salesforce Loops in Apex | The Developer Guide
Introduction A loop is a programming structure that repeats a sequence of instructions again and again until a specific/desired condition is met. In a loop…
Popular Salesforce Videos
TrailheaDX 2020 Opening Film | Salesforce
Now more than ever, Trailblazers are using the Salesforce Platform from anywhere in the world to collaborate, innovate, make a change, and build a brighter…
How to Set Up Salesforce Knowledge?
Watch this video to learn how to set up Salesforce Knowledge so you can help your team more easily find answers to common customer requests.…
Skill Based Routing with Apex/Flows in Salesforce
This video is the sequel to the omnichannel Salesforce tutorial (LINK) In this video, we will cover: 1. What is Skill-based routing 2. Why is…
Popular Salesforce Infographics
Salesforce Administrator Salaries – Around The World
A Salesforce administrator; the gatekeeper to an organisation’s Salesforce capabilities. With the huge acceleration of data in our lives, it’s no surprise that job roles…
Management: Salesforce – 27 Incredible Sales Tips
Get a complete view of your customers, including activity history, key contacts, customer communications, and internal account discussions.. With sales software from Salesforce (Salesforce Sales…
Top Benefits of Integrating Salesforce and NetSuite
Salesforce, on the one hand, is the world’s number cloud-based CRM. NetSuite, on the other hand, is one of the best ERP systems. And when…