You need to sign in to do that
Don't have an account?

java button to run approval process class code coverage
Hi,
I have created a custom button on the Opportunity object. When clicked it runs a class which in turn starts off the approval process.
This works fine in my developer sandbox but is not deploying due to code coverage issues. I wonder if anyone can help, bearing in mind I have got as far as I can with some research as I am not a programmer and wanting to learn
Thanks
Class code with no coverage: -
global class Opportunity_Approval_to_PrepBid {
public String myopi {get; set;}
Webservice static String callApproval(String myopi) {
Opportunity op = new Opportunity(Id=myopi);
update op;
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setComments('Submitted for Approval');
req1.setObjectId(myopi);
Approval.ProcessResult res = Approval.Process(req1);
return null;
}
}
Test class I tried: -
@IsTest
Public Class testApprovePrepare
{
static testMethod void testApprovePrepare()
{
Account a = new Account();
a.Name ='demo';
a.Industry = 'Education';
a.BillingCountry = 'United Kingdom';
insert a;
Opportunity o = new Opportunity();
o.AccountId = a.Id;
o.StageName = 'Pipeline';
o.Business_Unit__c = '1Spatial United Kingdom';
o.Name = 'Test';
o.Opportunity_Type__c = 'Contract Renewal';
o.Contract_Type__c = 'Framework';
o.Estimated_Value_Number__c = 10000;
o.Opportunity_Submission_Date__c = Date.TODAY();
o.CloseDate = Date.TODAY() +2;
o.Probability__c = '80-99%';
o.Purchase_Order__c = 'PO Pending';
o.Solution_Summary__c = 'Hardware';
o.Description = 'Renewal Contract for the next financial year';
o.Opportunity_Process_Stage__c= 'Qualified Opportunity';
insert o;
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setComments('Submitted for Approval');
req1.setObjectId(o.Id);
req1.setProcessDefinitionNameOrId('Auto_Approval_to_Prepare_Bid');
Approval.ProcessResult res = Approval.Process(req1);
try{
res = Approval.process(req1);
}catch(Exception e){
System.debug('No approval process has been setup yet.');
}
}
}
Any help would be appreciated in getting this deployed to production
Many Thanks
I have created a custom button on the Opportunity object. When clicked it runs a class which in turn starts off the approval process.
This works fine in my developer sandbox but is not deploying due to code coverage issues. I wonder if anyone can help, bearing in mind I have got as far as I can with some research as I am not a programmer and wanting to learn
Thanks
Class code with no coverage: -
global class Opportunity_Approval_to_PrepBid {
public String myopi {get; set;}
Webservice static String callApproval(String myopi) {
Opportunity op = new Opportunity(Id=myopi);
update op;
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setComments('Submitted for Approval');
req1.setObjectId(myopi);
Approval.ProcessResult res = Approval.Process(req1);
return null;
}
}
Test class I tried: -
@IsTest
Public Class testApprovePrepare
{
static testMethod void testApprovePrepare()
{
Account a = new Account();
a.Name ='demo';
a.Industry = 'Education';
a.BillingCountry = 'United Kingdom';
insert a;
Opportunity o = new Opportunity();
o.AccountId = a.Id;
o.StageName = 'Pipeline';
o.Business_Unit__c = '1Spatial United Kingdom';
o.Name = 'Test';
o.Opportunity_Type__c = 'Contract Renewal';
o.Contract_Type__c = 'Framework';
o.Estimated_Value_Number__c = 10000;
o.Opportunity_Submission_Date__c = Date.TODAY();
o.CloseDate = Date.TODAY() +2;
o.Probability__c = '80-99%';
o.Purchase_Order__c = 'PO Pending';
o.Solution_Summary__c = 'Hardware';
o.Description = 'Renewal Contract for the next financial year';
o.Opportunity_Process_Stage__c= 'Qualified Opportunity';
insert o;
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setComments('Submitted for Approval');
req1.setObjectId(o.Id);
req1.setProcessDefinitionNameOrId('Auto_Approval_to_Prepare_Bid');
Approval.ProcessResult res = Approval.Process(req1);
try{
res = Approval.process(req1);
}catch(Exception e){
System.debug('No approval process has been setup yet.');
}
}
}
Any help would be appreciated in getting this deployed to production
Many Thanks
For now you can use below code and your code coverage will be fine.
All Answers
System.AssertException: Assertion Failed: Expected: null, Actual: null
lie 32, do you know what this means?
Thanks
Nick
For now you can use below code and your code coverage will be fine.