You need to sign in to do that
Don't have an account?
Arun Yadav 13
test class for approval process
Hi
I need to write a test class from below approval process. Can anyone please help me
public static Approval.ProcessResult removeQuoteFromApproval(Id quoteId) {
List<ProcessInstance> piList = [Select p.TargetObjectId, p.Status From ProcessInstance p where TargetObjectId = :quoteId];
Approval.ProcessResult result = null;
if(piList.size() > 0 && piList[0].Status == 'Pending') {
Approval.ProcessWorkitemRequest pwr = new Approval.ProcessWorkitemRequest();
pwr.setAction('Removed');
pwr.setComments('Quote submitted with updated discounts');
pwr.setWorkitemId(quoteId);
result = Approval.process(pwr);
if(!result.isSuccess()) {
Database.Error[] errors = result.getErrors();
for(Database.Error dbe : errors) {
system.debug(dbe.getMessage());
}
}
}
return result;
}
Thanks
I need to write a test class from below approval process. Can anyone please help me
public static Approval.ProcessResult removeQuoteFromApproval(Id quoteId) {
List<ProcessInstance> piList = [Select p.TargetObjectId, p.Status From ProcessInstance p where TargetObjectId = :quoteId];
Approval.ProcessResult result = null;
if(piList.size() > 0 && piList[0].Status == 'Pending') {
Approval.ProcessWorkitemRequest pwr = new Approval.ProcessWorkitemRequest();
pwr.setAction('Removed');
pwr.setComments('Quote submitted with updated discounts');
pwr.setWorkitemId(quoteId);
result = Approval.process(pwr);
if(!result.isSuccess()) {
Database.Error[] errors = result.getErrors();
for(Database.Error dbe : errors) {
system.debug(dbe.getMessage());
}
}
}
return result;
}
Thanks
Anyways, hope this helps
https://developer.salesforce.com/forums/?id=906F00000008zyqIAA
In your test class, you need to create a Quote. And then u need to submit your Quote record for approval using apex. refer: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_process_example.htm.
Post that, call your method "removeQuoteFromApproval" and your test class shall work.
Best Regards
Veenesh
I'm not understanding the class code. Hence can you please write the test class for this method.
Arun
Kindly mark as solved if it helps.
Best Regards
Veenesh