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
John LinJohn Lin 

Build a Conference Management App - Creating a controller Extension

https://developer.salesforce.com/trailhead/project/salesforce_developer_workshop/creating_controller_extension

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

Thanks,

 
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
sandeep
Maharajan CMaharajan C
Hi John,
Can you please try this class and Visuaforce page

Class:
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>


Thanks,
RAJ.