public class CIFController
{
public Lead leadDetail
{get;set;}
public Id leadId
{get;set;}
//attachment Document name
public string businessDocName
{get;set;}
//attachment Document body
public Blob documentBody
{get;set;}
//attachment ID name
public string idCardName
{get;set;}
//attachment ID body
public Blob idCardBody
{get;set;}
//get the lead id record
public CIFController(ApexPages.StandardController ctlr)
{
leadId = ctlr.getRecord().Id;
}
//update the fields on the record
public PageReference UpdateRecord(){
Id leadId ;
//lead custom fields and definitions
leadDetail = [SELECT Customer_Name__c, Licence_c, Email_c, Surname_and_First_Name__c, Job_Title__c, Telephone_Number__c FROM Lead WHERE Id =: leadid];
PageReference pgRef;
if((documentBody != null && businessDocName != null)||(idCardBody != null && idCardName != null))
{
Attachment businessDocument = new Attachment();
Attachment idDocument = new Attachment();
if(documentBody != null && businessDocName != null)
{
businessDocument.Body = documentBody;
businessDocument.Name = businessDocName;
businessDocument.ParentId = leadId;
try
{
if(idCardBody != null && idCardName != null)
{
idDocument.Body = idCardBody;
idDocument.Name = idCardName;
idDocument.ParentId = leadId;
}
insert businessDocument;
insert idDocument;
}catch(DMLException e)
{
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
return null;
}
}
pgRef = new PageReference('http://thank.you/');
pgRef.setRedirect(true);
return pgRef;
}
return null;
}
}
}