Recipes by Category

App Distribution (2) Bundle logic, interface and services for distribution. App Logic (37) The Apex programming language, workflow and formulas for logic. Collaboration (5) The Salesforce Chatter collaboration platform. Database (29) Data persistence, reporting and analytics. Integration (33) Web Service APIs and toolkits for integration. Security (9) Platform, application and data security. Tools (4) Force.com tooling User Interface (36) Visualforce MVC and metadata-drive user interfaces. Web Sites (12) Public web sites and apps with optional user registration and login.
Beta Feedback
Cookbook Home » Creating Records from Information in Incoming Email Messages

Creating Records from Information in Incoming Email Messages

Post by Developer Force  (2010-07-16)

Status: Certified
Level: novice

Problem

You want to create and associate the following records based on information retrieved from the job applicant's incoming email message:
  • Candidate
  • Job application

Solution

Using Apex code, create a new candidate and job application and populate them with the information retrieved from the job applicant's incoming email message. Associate the candidate with the job application. This example assumes that the subject of the job applicant's incoming email exactly matches an existing job name.

  // Creates new candidate and job application objects  
    
Candidate__c[] newCandidate = new Candidate__c[0];
Job_Application__c[] newJobApplication = new Job_Application__C[0];

  // Creates a new candidate from the information  
    
  // retrieved from the inbound email  
    
        try
        {
      newCandidate.add(new Candidate__c(email__c = emailAddress,
      first_name__c = fName,
      last_name__c = lName,
      phone__c = phoneNumber,
      city__c = city));
 
      insert newCandidate;
   }
        
   catch (System.DmlException e)
   {
System.debug('ERROR: Not able to create candidate: ' + e);
   }
 
  // Looks for a job name based on the email subject  
    
  // (this example assumes the email subject exactly  
    
  // matches an existing job name)  
    
Position__c pos;
pos = [select ID from Position__c where name = 
			:email.subject limit 1];
ID jobId = pos.ID;
 
  // Associates the candidate with the application  
    
newJobApplication.add(new Job_Application__c(Position__c = jobId,
candidate__c = newCandidate[0].id));
 
        insert newJobApplication;

Discussion

  • This example contains no error handling and assumes the email subject exactly matches the job name. You would need to add error handling and, for example, wildcard matching.
  • For a complete example containing code from all the email recipes, see Email Recipes—Complete Code Example.

Share

Recipe Activity - Please Log in to write a comment

Be the first to comment.

X

Vote to Verify a Recipe

Verifying a recipe is a way to give feedback to others and broaden your own understanding of the capabilities on Force.com. When you verify a recipe, please make sure the code runs, and the functionality solves the articulated problem as expected.

Please make sure:
  • All the necessary pieces are mentioned
  • You have tested the recipe in practice
  • Have sent any suggestions for improvements to the author

Please Log in to verify a recipe

You have voted to verify this recipe.