function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Arun AdepuArun Adepu 

please resolve this issue about inbound email

Hi all,

Inbound email:
if you get any Inbound email from external user to salesforce.
if that email is existing record in contact then go and create case for that
if that email is not exist then automatically send email like this
your email id is not registered please register with us.

please solve immediately and how to write trigger on above requirement

thanks 
arun
Santosh Kumar 275Santosh Kumar 275
Hey refer this code you need to create an email service :
Follow this link for step by step process to setting up email services: https://developer.salesforce.com/page/An_Introduction_To_Email_Services_on_Force.com

Replace your class with this one :
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 Case object to be created
    Case[] newCase = new Case[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 Case to the contact record we just found above.
      newCase.add(new Case(Description =  myPlainText,
           Priority = 'Normal',
           Status = 'Inbound Email',
           Subject = email.subject,
           ContactId =  vCon.Id));
     
     // Insert the new Case 
     insert newCase;    
     
     System.debug('New Case Object: ' + newCase );   
    }
    // 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 False. This will send an email back to the user 
       result.success = false;
       result.message = 'Oops, It Failed';
   }
   
   // Set the result to true. No need to send an email back to the user if inserted successfully
   result.success = true;
   
   // Return the result for the Apex Email Service
   return result;
  }
}