You need to sign in to do that
Don't have an account?
John 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,
does anybody know how to do step 3: add Image Upload Suppot?
Thanks,
sandeep
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.