You need to sign in to do that
Don't have an account?
Wajeed Khan Hb
need code coverage atleast 85% for below code
public with sharing class Call_Controller { public apexpages.StandardController stdctrl{get;set;} public Call__c call{get;set;} // public List<Account> acc{get;set;} public List<Account_Affiliation__c> accAf{get;Set;} public List<wrapperClass> wrapClassList{get;set;} public wrapperClass wc{get;set;} public Call_Controller(ApexPages.StandardController ctrl) { wrapClassList = new List<wrapperClass>(); accAf = new List<Account_Affiliation__c>(); call=[Select Id,Status__c,Created__c,Account__c,Account__r.Name,Call_Date__c,Comments__c,Out_of_Office__c from Call__c where Account__c=:ApexPages.currentPage().getparameters().get('accId')][0]; accAf=[Select Status__c,To__r.name,From__c,To__c From Account_Affiliation__c where From__c=:ApexPages.currentPage().getparameters().get('accId')]; for(Account_Affiliation__c af:accAf) { wc = new wrapperClass(af.To__r.Name); wc.flag=false; wc.accWrap=af; wrapClassList.add(wc); } stdctrl=ctrl; } public class wrapperClass { public boolean flag{get;set;} public Account_Affiliation__c accWrap{get;set;} public String accName{get;set;} public wrapperClass(String Name) { accName=Name; flag=false; } } //Record Creation for Related Records on Save public void createRelRecordOnSave() { for(wrapperClass wc:wrapClassList) { if(wc.flag==true ) { Call__c Rcl =new Call__c(); Rcl.Account__c=wc.accWrap.To__c; Rcl.Call_Date__c=call.Call_Date__c; Rcl.Comments__c=call.Comments__c; Rcl.Out_of_office__c=call.Out_of_office__c; Rcl.Status__c='Draft'; upsert rcl; } } } //Record Creation for Related Records on Submit public void createRelRecordOnSubmit() { for(wrapperClass wc:wrapClassList) { if(wc.flag==true ) { Call__c Rcl =new Call__c(); Rcl.Account__c=wc.accWrap.To__c; Rcl.Call_Date__c=call.Call_Date__c; Rcl.Comments__c=call.Comments__c; Rcl.Out_of_office__c=call.Out_of_office__c; Rcl.Status__c='Submitted'; upsert rcl; } } } //Validation on EditButton /** public PageReference validate() { PageReference pgectrl=new PageReference('/a0B?fcf'); if(call.Status__c=='Submitted') { ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR,'You Cannot Edit the Submitted Record')); return null; } return null; }**/ /** public PageReference relRecordOnSave() { for(Account_Affiliation__c Af: accAf) { Call__c Rcl =new Call__c(); Rcl.Account__c= Af.To__c; Rcl.Call_Date__c=call.Call_Date__c; Rcl.Comments__c=call.Comments__c; Rcl.Out_of_office__c=call.Out_of_office__c; rcl.Status__c='Draft'; upsert rcl; } PageReference reRend = new PageReference('/a0B?fcf'); reRend.setRedirect(true); return reRend; } public PageReference relRecordOnSubmit() { for(Account_Affiliation__c Af: accAf) { Call__c Rcl =new Call__c(); Rcl.Account__c= Af.To__c; Rcl.Call_Date__c=call.Call_Date__c; Rcl.Comments__c=call.Comments__c; Rcl.Out_of_office__c=call.Out_of_office__c; rcl.Status__c='Submitted'; upsert rcl; } PageReference reRend = new PageReference('/a0B?fcf'); reRend.setRedirect(true); return reRend; }**/ //Save Button public PageReference Save() { if(call.Call_Date__c>System.today() ) { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'You Cannot Enter A future Date')); return null; } /** else if(call.Status__c=='Submitted') { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'You Cannot Edit which is alredy Submitted')); return null; }**/ else { try{ Call__c Call1=New Call__C(); call1.Account__c=call.Account__c; call1.Call_Date__c=call.Call_Date__c; call1.Comments__c=call.Comments__c; call1.Out_of_office__c=call.Out_of_office__c; call1.Status__c='Draft'; upsert call1; createRelRecordOnSave(); } catch(Exception ex) { ApexPages.addMessages(ex); } } PageReference reRend = new PageReference('/a0B?fcf'); reRend.setRedirect(true); return reRend; } //Submit Button public PageReference Submit() { if(call.Call_Date__c>system.today()) { call.Call_Date__c.addError('The Date Should not be Future Date'); } try{ Call__c Call1=New Call__C(); call1.Account__c=call.Account__c; call1.Call_Date__c=call.Call_Date__c; call1.Comments__c=call.Comments__c; call1.Out_of_office__c=call.Out_of_office__c; call1.Status__c='Submitted'; upsert call1; createRelRecordOnSubmit(); } catch(Exception ex) { ApexPages.addMessages(ex); } PageReference reRend = new PageReference('/a0B?fcf'); reRend.setRedirect(true); return reRend; } }