You need to sign in to do that
Don't have an account?
Srinivas Testing
Can you write test class below code
Hi Team,
I am new resource i don't know how to write test class i have written triggerhandler class on opportunity and i post the code below , can you make test class
public class OpportunityTriggerHandler{
public void handleTrigger (Opportunity[] trigNew){
if (trigger.isBefore){
if(trigger.isUpdate){
handleBeforeInsert(trigNew);
}
}
else if (trigger.isInsert){
handleBeforeInsert(trigNew);
}
}
public void handleBeforeInsert(Opportunity[] trigNew)
{
for (Opportunity objOpps : trigNew)
{
if ((objOpps.StageName == 'Prospecting') || (objOpps.StageName == 'Perception Analysis') || (objOpps.StageName == 'Qualification') || (objOpps.StageName == 'Needs Analysis')
|| (objOpps.StageName == 'Value Proposition')||(objOpps.StageName == 'Id.Decision Markers')||(objOpps.StageName == 'Proposal/Price Quote'))
{
if ( objOpps.Win_Lose_Comment__c != null){
objOpps.Win_Lose_Comment__c.addError('Donfill the value Win/Lose Comment');
}
if ( objOpps.Win_Lose_Reason__c != null){
objOpps.Win_Lose_Reason__c.addError('Don t fill the value Win/Lose Reason');
}
if( objOpps.Type_Lose__c != null)
{
objOpps.Type_Lose__c.addError('Dont fill the value Type Lose');
}
}
else if ((objOpps.StageName == 'Negotiation/Review') || (objOpps.StageName == 'Closed Won'))
{
if ( objOpps.Win_Lose_Comment__c == null){
objOpps.Win_Lose_Comment__c.addError('Please select the value Win/Lose Comment');
}
if ( objOpps.Win_Lose_Reason__c == null)
{
objOpps.Win_Lose_Reason__c.addError('Please select the value Win/Lose Reason');
}
}
else if(objOpps.StageName == 'Closed Lost')
{
if ( objOpps.Win_Lose_Comment__c == null){
objOpps.Win_Lose_Comment__c.addError('Please fill the value Win/Lose Comment');
}
if ( objOpps.Win_Lose_Reason__c == null){
objOpps.Win_Lose_Reason__c.addError('Please fill the value Win/Lose Reason');
}
if( objOpps.Type_Lose__c == null)
{
objOpps.Type_Lose__c.addError('Please fill the value Type Lose');
}
// else{}
}
}
}
}
I am new resource i don't know how to write test class i have written triggerhandler class on opportunity and i post the code below , can you make test class
public class OpportunityTriggerHandler{
public void handleTrigger (Opportunity[] trigNew){
if (trigger.isBefore){
if(trigger.isUpdate){
handleBeforeInsert(trigNew);
}
}
else if (trigger.isInsert){
handleBeforeInsert(trigNew);
}
}
public void handleBeforeInsert(Opportunity[] trigNew)
{
for (Opportunity objOpps : trigNew)
{
if ((objOpps.StageName == 'Prospecting') || (objOpps.StageName == 'Perception Analysis') || (objOpps.StageName == 'Qualification') || (objOpps.StageName == 'Needs Analysis')
|| (objOpps.StageName == 'Value Proposition')||(objOpps.StageName == 'Id.Decision Markers')||(objOpps.StageName == 'Proposal/Price Quote'))
{
if ( objOpps.Win_Lose_Comment__c != null){
objOpps.Win_Lose_Comment__c.addError('Donfill the value Win/Lose Comment');
}
if ( objOpps.Win_Lose_Reason__c != null){
objOpps.Win_Lose_Reason__c.addError('Don t fill the value Win/Lose Reason');
}
if( objOpps.Type_Lose__c != null)
{
objOpps.Type_Lose__c.addError('Dont fill the value Type Lose');
}
}
else if ((objOpps.StageName == 'Negotiation/Review') || (objOpps.StageName == 'Closed Won'))
{
if ( objOpps.Win_Lose_Comment__c == null){
objOpps.Win_Lose_Comment__c.addError('Please select the value Win/Lose Comment');
}
if ( objOpps.Win_Lose_Reason__c == null)
{
objOpps.Win_Lose_Reason__c.addError('Please select the value Win/Lose Reason');
}
}
else if(objOpps.StageName == 'Closed Lost')
{
if ( objOpps.Win_Lose_Comment__c == null){
objOpps.Win_Lose_Comment__c.addError('Please fill the value Win/Lose Comment');
}
if ( objOpps.Win_Lose_Reason__c == null){
objOpps.Win_Lose_Reason__c.addError('Please fill the value Win/Lose Reason');
}
if( objOpps.Type_Lose__c == null)
{
objOpps.Type_Lose__c.addError('Please fill the value Type Lose');
}
// else{}
}
}
}
}
To write test class for Trigger, need to do Insert, update or delete operation in your test class based on the Trigger code you written.
Try this for your code:
Thanks,
Gokula Krishnan
If it helps you, please mark is as best answer, so it will be helpful for other developers.