In Chapter 13: Email Services with the Force Platform, you learned how to use email to extend the recruiting application. In this section, you go one step further and create public Web pages to accomplish similar goals. If you want to let public users apply online for open positions, you need to create a new Visualforce page, named PublicJobApplication, to accept applications.
Use the standard controller for the Candidate object, and create a new extension controller, named myPublicJobApplicationExtension, to do the following:
Create a new Candidate record
Attach the uploaded resume file to the Candidate record
Create a new Job Application record that’s linked to the Position and Candidate records
Redirect users to the confirmation page
This topic covers the following steps:
Creating the Application Page and Linking to Job Details
Testing the Online Application Process and Verifying the Results
By adding an extension to the standard controller, you can add powerful functionality without having to create an entire custom controller. The extension in this example allows users to apply online and upload files—functions not available in the standard controller. On application, the controller extension creates new candidate and job application records related to the position. You will see how this is used in Creating the Application Page and Linking to Job Details on page 453.
Your Apex extension should look like this:
public class PublicJobApplicationExtension { // This controller extends the standard controller, overwrites // the actions, creates a candidate record, creates an attachment // on the candidate record based on the uploaded file, creates a // job application record that links the candidate record and // the related position. private final Candidate__c candidate; private ID positionid = ApexPages.currentPage().getParameters().get('jobid'), private Job_Application__c jobapplication {get; private set;} public Blob resume {get; set;} public String contentType {get; set;} public String fileName {get; set;} // Extends the standard controller for the candidate object public PublicJobApplicationExtension (ApexPages.StandardController stdController) { candidate = (Candidate__c)stdController.getRecord(); } public Position__c getPosition() { return [SELECT id, name, Position_type__r.Name, Job_Description__c FROM Position__c WHERE id = :positionid]; } public PageReference saveApplication() { // Creates the candidate record try { insert(candidate); } catch(System.DMLException e) { ApexPages.addMessages(e); return null; } jobapplication = new Job_Application__c(); jobapplication.Candidate__c = candidate.id; jobapplication.Position__c = positionid; // Creates an attachment to the candidate record if a resume file is uploaded if (resume != null) { Attachment attach = new Attachment(); attach.Body = resume; attach.Name = fileName; attach.ContentType = contentType; attach.ParentId = candidate.id; try { insert(attach); } catch(System.DMLException e) { ApexPages.addMessages(e); return null; } } // Creates the job application record to link the candidate and the related position try { insert(jobapplication); } catch(System.DMLException e) { ApexPages.addMessages(e); return null; } PageReference p = Page.PublicJobApplicationConfirmation; p.setRedirect(true); return p; } }
3.148.103.210