You need to sign in to do that
Don't have an account?
sudhirn@merunetworks.com
Test class for approval process class
Hi,
Please suggest me test class for below controller it has approval process.
Thanks
Sudhir
Please suggest me test class for below controller it has approval process.
public class check_spr_coterm { Integer Olicheck; Integer Athcheck; String PageID; String P_SPR_Approver_Director; String P_SPR_Approver_RVP; String P_SPR_Approver_GVP; String P_SPR_Approver_EVP; public check_spr_coterm() { SPR__c SP; //OpportunityLineItem OLI; SP = [select id,Opportunity__c from SPR__c where Id = : ApexPages.currentPage().getParameters().get('id') limit 1]; PageID = ApexPages.currentPage().getParameters().get('id'); List<SPR__c> SPRO = new List<SPR__c>(); SPRO = [select id,SPR_Approver_Director__c,SPR_Approver_RVP__c,SPR_Approver_GVP__c,SPR_Approver_EVP__c from SPR__c where id = :ApexPages.currentPage().getParameters().get('id') and ( SPR_Approver_Director__c = null or SPR_Approver_RVP__c = null or SPR_Approver_GVP__c = null or SPR_Approver_EVP__c = null ) limit 1 ]; if(!SPRO.isEmpty()) // check if list is not empty { P_SPR_Approver_Director = SPRO[0].SPR_Approver_Director__c; P_SPR_Approver_RVP = SPRO[0].SPR_Approver_RVP__c; P_SPR_Approver_GVP = SPRO[0].SPR_Approver_GVP__c; P_SPR_Approver_EVP = SPRO[0].SPR_Approver_EVP__c; } else { P_SPR_Approver_Director = 's'; P_SPR_Approver_RVP = 's'; P_SPR_Approver_GVP = 's'; P_SPR_Approver_EVP = 's'; } List<AggregateResult> OLI = [select count(id) olicnt from OpportunityLineItem where opportunityid = :SP.Opportunity__c and name like '%COTERM%' ]; List<AggregateResult> ATH = [select count(id) athcnt from Attachment where parentid = :ApexPages.currentPage().getParameters().get('id')]; Olicheck = (Integer)OLI[0].get('olicnt'); Athcheck = (Integer)ATH[0].get('athcnt'); } public void pageAction(){ if ( P_SPR_Approver_Director == NULL || P_SPR_Approver_RVP == NULL || P_SPR_Approver_GVP == NULL || P_SPR_Approver_EVP == NULL ) { ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info,'Your SPR approvers have not been set up, please contact the SFDC Administrator @ SFDC@fortinet.com')); } else if( Olicheck > 0 && Athcheck ==0) // COTERM product exist and attached is missing this will fire { ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info,'An RTS Quote is required for the COTERM product.Please attach quote(s) and then resubmit your SPR for approval')); } else if ( P_SPR_Approver_Director <> NULL && P_SPR_Approver_RVP <> NULL && P_SPR_Approver_GVP <> NULL && P_SPR_Approver_EVP <> NULL ) { Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest(); req.setObjectId(PageID); Approval.ProcessResult result = Approval.process(req); ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info,'Sucessfully submitted for approval')); redirectpage(); } } public PageReference redirectpage() { PageReference pageRef = new PageReference('/' + PageID); pageRef.setRedirect(true); return pageRef; } }
Thanks
Sudhir
sudhirn@merunetworks.com
Wrote below test class but its not working or giving code coverage