You need to sign in to do that
Don't have an account?
Ludivine
Test Trigger Fire Approval on Opportunity
Dear all,
I have amended a trigger in my org.
Pb is when I validate it in production I got an error message.
I think this is because my trigger has 0% code coverage.
Could you tell me how to write the test trigger on this function that fires Approval on Opportunities?
Here is the trigger that I want to implement :
Many thanks for your help.
I have amended a trigger in my org.
Pb is when I validate it in production I got an error message.
I think this is because my trigger has 0% code coverage.
Could you tell me how to write the test trigger on this function that fires Approval on Opportunities?
Here is the trigger that I want to implement :
trigger fireApproval on Opportunity (after insert, after update){ if(runCheck.runOnce()) { for (Opportunity Oppty: Trigger.new){ if(Oppty.StageName == 'Impact Action' && (trigger.isInsert || trigger.oldMap.get(Oppty.id).StageName != 'Impact Action') && ((Oppty.Business_Group__c == 'Australasia' && Oppty.Business_Unit__c=='Corrugated')&& (Oppty.Division__c== 'QLD' ||Oppty.Division__c== 'National' || Oppty.Division__c== 'NSW' || Oppty.Division__c== 'SA' || Oppty.Division__c== 'VIC/TAS'|| Oppty.Division__c== 'WA'))){ //modfied 2010-07-05 by Lee Tsiamis - Velteo //This will auto submit for approval. Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest(); req1.setComments('Submitting request for approval.'); String accountID = Oppty.id; req1.setObjectId(accountID); // Submit the approval request for the account Approval.ProcessResult result = Approval.process(req1); // Verify the result System.assert(result.isSuccess()); System.assertEquals('Pending', result.getInstanceStatus(), 'Instance Status'+result.getInstanceStatus()); } /* // --------------------------------------------- // // added by Ludivine Dos REis- Amcor, 2013-06-19 // // --------------------------------------------- // else if(Oppty.StageName == 'Planned - market' && trigger.oldMap.get(Oppty.id).StageName != 'Planned - market' && Oppty.Business_Group__c == 'Amcor Flexibles Europe & Americas' ) { //This will auto submit for approval. Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest(); req1.setComments('Submitting request for approval.'); String accountID = Oppty.id; req1.setObjectId(accountID); // Submit the approval request for processing Approval.ProcessResult result = Approval.process(req1); // Verify the result System.assert(result.isSuccess()); System.assertEquals('Pending', result.getInstanceStatus(), 'Instance Status'+result.getInstanceStatus()); } */ // --------------------------------------------- // // added by Matt Watson - Salesforce, 2012-02-20 // // --------------------------------------------- // // triggers "AA Beverage" approval processes (x3) else if(Oppty.Business_Group__c == 'Australasia' && Oppty.Business_Unit__c== 'Beverage' && ( (Oppty.StageName == 'Planned Action' && (trigger.isInsert || trigger.oldMap.get(Oppty.id).StageName != 'Planned Action')) || (Oppty.StageName == 'Impact Action' && (trigger.isInsert || trigger.oldMap.get(Oppty.id).StageName != 'Impact Action')) ) ) { //This will auto submit for approval. Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest(); req1.setComments('Submitting request for approval.'); String accountID = Oppty.id; req1.setObjectId(accountID); // Submit the approval request for the account Approval.ProcessResult result = Approval.process(req1); // Verify the result System.assert(result.isSuccess()); System.assertEquals('Pending', result.getInstanceStatus(), 'Instance Status'+result.getInstanceStatus()); } } } }
Many thanks for your help.
So that I can begin the test class and maybe some tips to test the method.
So you don't want to help me?
I suggest you read up on writing test classes :
- writing a test class for a trigger: https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_test.htm
- how to write good unit tests : https://developer.salesforce.com/page/How_to_Write_Good_Unit_Tests
http://forceschool.blogspot.in/2011/06/testing-trigger-structure.html
Thanks again and Have a nice day both of you.
Following your help, I have built a new test class to test my approval process.
Now The Execution Test pass but I only get 22% (4/18) of code coverage, however Ithink I have checked in the test class every main points...
I am stuck here, can you tell me what I should test as well?
I have cleaned up my trigger :
And here is my test class with 22% code coverage :