You need to sign in to do that
Don't have an account?
iswarya sekar 7
Test Class to get 80% code Coverage.. Anyone help me!!
trigger UpdateStage on Account (after insert, after update, before insert, before Update) { // Performs Custom actions after Record gets saved. List<Id> accountId = new List<Id>(); // get the list of all Account's ID to be Updated. for(Account acc : Trigger.new) { if(acc.All_Opportunities_Won__c==True) // Checks if the Condition is True. accountId.add(acc.Id); } List<Opportunity> oppsToUpdate = new List<Opportunity>(); for(Opportunity opp : [select id, StageName, Amount from Opportunity where AccountId in: accountId AND Amount != 0]) // used to get all records from above ID. { opp.StageName='Closed-Won'; //Update StageName in Opportunity oppsToUpdate.add(opp); } update oppsToUpdate; // Update all Opportunity in List. }
Then try below test class.
Let us know if this will help you
All Answers
Code coverage for Trigger is to insert/update/delete test records in the test class. Trigger will be fired whenever an Insert/Update/Delete event occurs. So, to test the trigger code, need to perform insert/update/delete operations.
In your Trigger, you had written only for Insert and Update event. So you need to perform Insert and Update operations.
Try this,
Thanks.
If it helps you, please mark is as best answer, so it will be helpful for other developers.
This is the error i'm getting when running the test,
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpdateStage: execution of BeforeInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.UpdateStage: line 3, column 1: []
Can you try following code.
Please mark above answer as SOLVED and BEST ANSWER if it helps you.
Regards,
Yogesh More
Salesforce consultant || Salesforce Developer
more.yogesh422@gmail.com || yogeshsfdc11@gmail.com
www.yogeshmore.com || Skype:-yogesh.more44
You need to change your trigger code:
Line 1 as : trigger UpdateStage on Account (after insert, after update) {
(or)
Thanks,
Then try below test class.
Let us know if this will help you