You need to sign in to do that
Don't have an account?
Arul Bernard I 14
How to write a test class for attachment?
public class ProcessSheet_MergeController {
Date myDate = system.today();
Private Process_Sheet__c pageOpp;
public Boolean initialised{get; set;}
public id PageOppId {get; set;}
public Process_Sheet__c getID {get; set;}
public ProcessSheet_MergeController(ApexPages.StandardController controller) {
this.pageOpp = (Process_Sheet__c)controller.getRecord();
PageOppId = ApexPages.currentPage().getParameters().get('processsheetId');
initialised=false;
system.debug('id = ' + pageOpp.id + ' id2' +PageOppId);
initialised=false;
}
public PageReference savePDF(){
getID = new Process_sheet__c();
getID = [Select id,name, xParts__c,Part_ID__c from Process_Sheet__c where id=:PageOppId];
System.debug('!!!'+getID);
if (!initialised && getID.ID !=NULL) {
System.debug('GetID'+getId.Id);
//PageReference pdf = Page.ProcessSheet;
PageReference pdf ; //= Page.ProcessSheet;
pdf = new PageReference('/apex/ProcessSheet');
pdf.getParameters().put('processsheetId',PageOppId);
pdf.getParameters().put('PartProcessFieldset', 'ProcessSheetTemplate');
pdf.getParameters().put('ProcessSheetFieldset', 'ProcessSheetTemplate');
// create the new attachment
List<Attachment> attachList = new List<Attachment>();
Attachment attach = new Attachment();
Blob body;
try {
body = pdf.getContentAsPDF();
system.debug('body should be fine');
} catch (VisualforceException e) {
system.debug('in the catch block');
body = Blob.valueOf('Some Text');
}
attach.Body = body;
attach.Name = 'PSA_'+ getID.name +'.pdf' ;
attach.IsPrivate = false;
attach.ParentId = getID.Id;
List<Attachment> a = [Select ID, ParentID, body, Name from Attachment Where ParentID = :getID.Id];
delete a;
attachList.add(attach);
insert attachList;
system.debug('<<>>'+attach);
initialised=true;
} else system.debug('tried to run twice');
return new PageReference('/apex/pdfMerge?processsheetId='+getID.id+'&PartProcessFieldset=ProcessSheetTemplate&ProcessSheetFieldset=ProcessSheetTemplate');
}
public ProcessSheet_MergeController (){}
}
Date myDate = system.today();
Private Process_Sheet__c pageOpp;
public Boolean initialised{get; set;}
public id PageOppId {get; set;}
public Process_Sheet__c getID {get; set;}
public ProcessSheet_MergeController(ApexPages.StandardController controller) {
this.pageOpp = (Process_Sheet__c)controller.getRecord();
PageOppId = ApexPages.currentPage().getParameters().get('processsheetId');
initialised=false;
system.debug('id = ' + pageOpp.id + ' id2' +PageOppId);
initialised=false;
}
public PageReference savePDF(){
getID = new Process_sheet__c();
getID = [Select id,name, xParts__c,Part_ID__c from Process_Sheet__c where id=:PageOppId];
System.debug('!!!'+getID);
if (!initialised && getID.ID !=NULL) {
System.debug('GetID'+getId.Id);
//PageReference pdf = Page.ProcessSheet;
PageReference pdf ; //= Page.ProcessSheet;
pdf = new PageReference('/apex/ProcessSheet');
pdf.getParameters().put('processsheetId',PageOppId);
pdf.getParameters().put('PartProcessFieldset', 'ProcessSheetTemplate');
pdf.getParameters().put('ProcessSheetFieldset', 'ProcessSheetTemplate');
// create the new attachment
List<Attachment> attachList = new List<Attachment>();
Attachment attach = new Attachment();
Blob body;
try {
body = pdf.getContentAsPDF();
system.debug('body should be fine');
} catch (VisualforceException e) {
system.debug('in the catch block');
body = Blob.valueOf('Some Text');
}
attach.Body = body;
attach.Name = 'PSA_'+ getID.name +'.pdf' ;
attach.IsPrivate = false;
attach.ParentId = getID.Id;
List<Attachment> a = [Select ID, ParentID, body, Name from Attachment Where ParentID = :getID.Id];
delete a;
attachList.add(attach);
insert attachList;
system.debug('<<>>'+attach);
initialised=true;
} else system.debug('tried to run twice');
return new PageReference('/apex/pdfMerge?processsheetId='+getID.id+'&PartProcessFieldset=ProcessSheetTemplate&ProcessSheetFieldset=ProcessSheetTemplate');
}
public ProcessSheet_MergeController (){}
}
Steven Nsubuga