Skip to content

Instantly share code, notes, and snippets.

@ccoenraets
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccoenraets/0ce6978905802731e2b1 to your computer and use it in GitHub Desktop.
Save ccoenraets/0ce6978905802731e2b1 to your computer and use it in GitHub Desktop.
SpeakerControllerExtension
public 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;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment