+ Start a Discussion
John LinJohn Lin 

Build a Conference Management App - Creating a controller Extension


does anybody know how to do step 3: add Image Upload Suppot?


Sandeep BhanotSandeep Bhanot
Hi John - the individual steps to support picture upload are documented in that section. Are you having a specific compile or runtime issue after following the instructions? Thanks
Maharajan CMaharajan C
Hi John,
Can you please try this class and Visuaforce page

public with sharing class SpeakerControllerExtension {

    public blob picture { get; set; }
    public String errorMessage { get; set; }
    private final Speaker__c speaker;
    private ApexPages.StandardController stdController;

    public SpeakerControllerExtension(ApexPages.StandardController stdController) {
        this.speaker = (Speaker__c)stdController.getRecord();
        this.stdController = stdController;
       public PageReference save() 
    errorMessage = '';
    try {
        upsert speaker;
        if (picture != null) {
            Attachment attachment = new Attachment();
            attachment.body = picture;
            attachment.name = 'speaker_' + speaker.id + '.jpg';
            attachment.parentid = speaker.id;
            attachment.ContentType = 'application/jpg';
            insert attachment;
            speaker.Picture_Path__c = '/servlet/servlet.FileDownload?file='
                                      + attachment.id;
            update speaker;
        return new ApexPages.StandardController(speaker).view();
    } catch(System.Exception ex) {
        errorMessage = ex.getMessage();
        return null;

Visualforce Page:

<apex:page standardController="Speaker__c" extensions="SpeakerControllerExtension"> <apex:form > <apex:pageBlock title="Edit Speaker"> <apex:pageBlockSection columns="1"> <apex:inputField value="{!Speaker__c.First_Name__c}"/> <apex:inputField value="{!Speaker__c.Last_Name__c}"/> <apex:inputField value="{!Speaker__c.Email__c}"/> <apex:inputFile value="{!picture}" accept="image/*" /> </apex:pageBlockSection> <apex:pageBlockButtons location="bottom" > <apex:commandButton action="{!save}" value="Save"/> </apex:pageBlockButtons> </apex:pageBlock> {!errorMessage} </apex:form> </apex:page>