function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
shruthikashruthika 

Providing the test class for the following trigger...

Hi.. am very new in writing apex code... could anyone please help me out in providing the test class for the following trigger...

 

Merging MQL Trigger:

trigger MQL on Opportunity (before update) 
{    
for(Opportunity a : Trigger.new)
{        
Opportunity beforeUpdate = System.Trigger.oldMap.get(a.Id);         
if(beforeUpdate.StageName =='Lead'||beforeUpdate.StageName == 'Qualified Lead')
{   
If(a.StageName != 'Lead' && a.StageName != 'Qualified Lead' && a.StageName != 'No Opportunity')
{         
a.MQL_Promotion_Date__c = System.today();            
system.debug('*** Oppty changed from Lead to something other than Lead or No Opportunity - date set to ' + System.today()+' ****');
}
if(a.StageName == 'No Opportunity')
{
a.MQL_Rejection_Date__c = System.today();  
system.debug('*** Oppty changed from Lead to No Opportunity-date set to'+System.today() +'****');  
}                     
}   

}

 

Please anyone  provide me the solution.

Thank you.

 

colemabcolemab

See if this works:

 

@isTest

Private class TestTriggers {
public TestMQLTrigger { // Create an account for testing with Account MyAccount = new Account(Name='Test'); insert MyAccount; // Create a opportunity to test with date myDate = date.today(); Opportunity MyOppty = new opportunity(Name='Test',CloseDate=myDate,StageName='Lead'); MyOppty.AccountId = MyAccount.Id; insert MyOppty; // Now test the update code in the trigger
Test.startTest();
 
MyOppty.StageName='No Opportunity'; upsert MyOppty; Test.stopTest(); } // end method
} // end class

 

shruthikashruthika

hi can anyone please write a test class in which u query an opportunity by  name or id

 

Then update the Opp’s Stage name (input will be the one of the stagename) and output would be the updation to the dates ie.. to the promotion date and rejection date based on the condition thats is given in the trigger.

 

thank you

 



colemabcolemab

What no thank you for the above code?  Did it even work?  Why not make a new post for your new request?  Also if the above code worked, please check this thread as having a solution.