+ Start a Discussion
satyamsatyam 

Please help to solve the error in test class

Hi,

 

Below is my trigger and Test Class

 

Red Colur line i am not covering in test class means if condition is not checking here

Trigger:
trigger Recruitervalidation on Recruiter__C (before Update) {  
    for (Recruiter__c a : Trigger.new) {
        system.debug('a.Status__c '+a.Status__c);
        system.debug('a.jobname__C '+a.jobname);
        
        if ((a.Status__c == 'waiting')&&(a.jobname__c==null)) {
                
            a.addError('Please fill the "Jobname" for the Job');
        }
       else if ((a.Status__c == 'Pending')&&(a.Jobdesc==null)) {
                
            a.addError(‘Some Error Message');
        }                                                         
    }
}

Test Class:

@istest

private class Recruitervalidation_test{

public static testmethod void Recruitervalidation_test()

{

Recruiter__c rc = new Recruiter_c();

rc.status__c='waiting';

rc.jobname__c='';

rc.joblocation__C='INDIA';

rc.jobtype__C='Technical';

insert rc;

rc.status__C='pending';

rc.jobdesc__C='';

rc.joblocation__C='INDIA';


update rc;

}}

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
SRajesh8SRajesh8

Hi Satyam,

 

 

Exactly i don't know how to get url in trigger try this

s.adderror('< a href = \' www.shivasoft.in \ ' > This is Test < / a >. ');

 

 

Regards,

Rajesh.

All Answers

SRajesh8SRajesh8

Hi

 

here I am getting 80% vode coverage.

 

try this

 

@istest
private class Recruitervalidation_test{
public static testmethod void Recruitervalidation_test()
{
Recruiter__c rc = new Recruiter_c();
rc.status__c='waiting';
rc.jobname__c='';
rc.joblocation__C='INDIA';
rc.jobtype__C='Technical'; //see here it can be __c or as it is
insert rc;

 

rc.status__C='pending';
rc.jobdesc__C='';
rc.joblocation__C='INDIA';

try
{
    update rc;
}
Catch(Exception e)
{
  system.debug('Some Error Message:'+e);
}
}}


Plz makes as solution once it solve ur issue  so that  other can be helpful.

 

Regards,

rajesh.

satyamsatyam

Hi ,

 

Many many Thanks for your help, Its working pretty fine and giving 80% code coverage.

 

Unfortunately i forget to ask one more thing user want that

 

"In error message he want the record detail page link in trigger"

 

How i can do this ?

 

Thanks:)))

satyamsatyam

Hi,

 

Thanks its working pretty fine

 

Unfortunately i forget to ask one thing that i want to give record detail page link so how i can do this ,

 

How i  can do this?

 

Trigger Recruitervalidation on Recruiter__C (before Update) {  
    for (Recruiter__c a : Trigger.new) {
        system.debug('a.Status__c '+a.Status__c);
        system.debug('a.jobname__C '+a.jobname);
        
        if ((a.Status__c == 'waiting')&&(a.jobname__c==null)) {
                
            a.addError('Please fill the "Jobname" for the Job');
        }
       else if ((a.Status__c == 'Pending')&&(a.Jobdesc==null)) {
                
            a.addError(‘Some Error Message');
        }                                                 

        
    }
}

 

Thanks:))))

SRajesh8SRajesh8

Hi Satyam,

 

 

Exactly i don't know how to get url in trigger try this

s.adderror('< a href = \' www.shivasoft.in \ ' > This is Test < / a >. ');

 

 

Regards,

Rajesh.

This was selected as the best answer