+ Start a Discussion
KyoKyo 

Code Coverage 18% I can add it to me?

Code Coverage 18% 

 

 

trigger UpdateType on Quotes__c (after update) {
    for(Quotes__c Q:trigger.new){
    
    if(Q.Status__c== 'Rejected'){
        Opportunities__c[] OP = [Select Id,name,Stage__c from Opportunities__c Where Id =: Q.OpportunitiesID__c];
        for(Opportunities__c O:OP){
        O.Stage__c = 'Closed Lost';
        O.Reason_for_Lost__c = 'Please input Data';
        }
         update OP;
        }
    else if(Q.Status__c== 'Accepted'){
        Opportunities__c[] OPP = [Select Id,name,Stage__c from Opportunities__c Where Id =: Q.OpportunitiesID__c];
        for(Opportunities__c OA:OPP){
        OA.Stage__c = 'Closed Won';
        }
        update OPP;
        }        
        }
    }

 Test

 

@isTest
private class TestUpdateType{

   static testMethod void myUnitTest() {
        Account Acc = new Account(Name='test');
        insert Acc;
        Opportunities__c O = new Opportunities__c(Account_Name__c=Acc.Id,Stage__c='Prospecting',Probability__c='10%',Unit__c = 'Kg',Currency__c = 'Bath',Reason_for_Lost__c ='Test');
        insert O;
        
        Quotes__c Q = new Quotes__c(OpportunitiesID__c=O.Id);
        insert Q;
   
    } 
}

 

 

Thank you so much.

 

Best Answer chosen by Admin (Salesforce Developers) 
Ankit AroraAnkit Arora

Hi Kyo,

 

Please try this and let me know if you face any problem, also if doesn't resolve your problem.

 

 

@isTest
private class TestUpdateType{

   static testMethod void myUnitTest() {
        Account Acc = new Account(Name='test');
        insert Acc;
        Opportunities__c O = new Opportunities__c(Account_Name__c=Acc.Id,Stage__c='Prospecting',Probability__c='10%',Unit__c = 'Kg',Currency__c = 'Bath',Reason_for_Lost__c ='Test');
        insert O;
        
        Quotes__c Q = new Quotes__c(name = 'TestQuote' , OpportunitiesID__c=O.Id);
        insert Q;
	Q.name = 'Change Name' ;
	Q.Status__c = 'Rejected' ;
	update Q ;
	Q.Status__c = 'Accepted' ;
	update Q ;
   
    } 
}

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

 

All Answers

Ankit AroraAnkit Arora

Hi Kyo,

 

Please try this and let me know if you face any problem, also if doesn't resolve your problem.

 

 

@isTest
private class TestUpdateType{

   static testMethod void myUnitTest() {
        Account Acc = new Account(Name='test');
        insert Acc;
        Opportunities__c O = new Opportunities__c(Account_Name__c=Acc.Id,Stage__c='Prospecting',Probability__c='10%',Unit__c = 'Kg',Currency__c = 'Bath',Reason_for_Lost__c ='Test');
        insert O;
        
        Quotes__c Q = new Quotes__c(name = 'TestQuote' , OpportunitiesID__c=O.Id);
        insert Q;
	Q.name = 'Change Name' ;
	Q.Status__c = 'Rejected' ;
	update Q ;
	Q.Status__c = 'Accepted' ;
	update Q ;
   
    } 
}

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

 

This was selected as the best answer
KyoKyo

Thank you so much Ankit. Code Coverage 100% Perfect!