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
SalesforceAddictSalesforceAddict 

test class for this class?

public with sharing class ContactEditController {
    Public Contact con{get;set;}
    Public Boolean DuplicateEmailFound{get;set;}
    Public String ButtonClicked{get;set;}
    Public ApexPages.StandardController stdController{get;set;}
    public ContactEditController(ApexPages.StandardController controller) {
        stdController=controller;
        con=(Contact)controller.getRecord();
        con.ownerId=userinfo.getUserId();
        DuplicateEmailFound=false;
    }
    
    Public pagereference Cancel(){
        Pagereference pref=stdController.Cancel();
        return pref;
    }
    
    Public Void CheckDuplicateEmail(){
        String searchTerms = '';
        if(String.IsNotBlank(con.Email)){
            searchTerms+= '("' + con.Email + '")';
        }
        
        if(String.IsNotBlank(con.E_Mail2__c)){
            if(!String.isEmpty(searchTerms)){
                searchTerms += ' OR ';
            }

            searchTerms+= '("' + con.E_Mail2__c+ '")';
        }
        
        if(String.IsNotBlank(con.E_Mail3__c)){
            if(!String.isEmpty(searchTerms)){
                searchTerms += ' OR ';
            }
            searchTerms+= '("' + con.E_Mail3__c + '")';
        }
        System.debug(searchTerms);
        List<Contact> results=(List<Contact>)[FIND :searchTerms IN EMAIL FIELDS RETURNING Contact(id,Name)][0];
        if(results.size()>0){
            DuplicateEmailFound=true;
        }
    }
    
    Public pagereference SaveContact(){
        try{
            upsert con;
            if(ButtonClicked=='Save'){
                return new ApexPages.StandardController(con).save();
            }else{
                System.debug('Here');
                pagereference pref=new pagereference('/003/e');
                pref.setRedirect(true);
                return pref;
            }
        }catch(exception e){
            return null;
        }
    }
}
Best Answer chosen by SalesforceAddict
Raj VakatiRaj Vakati
Try this code
 
@istest(SeeAlldata=True)
private class testsendemailreciept
{
    private static testmethod void SendEmailCustomerDetailPdf1()
     {

Account a = new Account();
a.Name = 'Test';
insert a ;  


     Contact con= new contact();
     con.Email = 'ram@gmail.com';
	 con.E_Mail3__c  = 'ram@gmail.com';
	 con.E_Mail2__c = 'ram@gmail.com';
	 con.Email = 'ram@gmail.com';
	 
     con.LastName= 'ds';
	 con.AccountId = a.Id ;
     con.MobilePhone= '9898561236';
     insert con;

   

    PageReference pageRef = Page.YOUR_VF_PAGE;
Test.setCurrentPage(pageRef);
pageRef.getParameters().put('Id', String.valueOf(obj.Id));
ApexPages.StandardController sc = new ApexPages.StandardController(con);
ContactEditController  testAccPlan = new ContactEditController(sc);  

testAccPlan.ButtonClicked='Save';

testAccPlan.Cancel();
testAccPlan.CheckDuplicateEmail();
testAccPlan.SaveContact();

testAccPlan.ButtonClicked='Calcenl';

testAccPlan.Cancel();
testAccPlan.CheckDuplicateEmail();
testAccPlan.SaveContact();


         }
     }

 

All Answers

Raj VakatiRaj Vakati
Try this code
 
@istest(SeeAlldata=True)
private class testsendemailreciept
{
    private static testmethod void SendEmailCustomerDetailPdf1()
     {

Account a = new Account();
a.Name = 'Test';
insert a ;  


     Contact con= new contact();
     con.Email = 'ram@gmail.com';
	 con.E_Mail3__c  = 'ram@gmail.com';
	 con.E_Mail2__c = 'ram@gmail.com';
	 con.Email = 'ram@gmail.com';
	 
     con.LastName= 'ds';
	 con.AccountId = a.Id ;
     con.MobilePhone= '9898561236';
     insert con;

   

    PageReference pageRef = Page.YOUR_VF_PAGE;
Test.setCurrentPage(pageRef);
pageRef.getParameters().put('Id', String.valueOf(obj.Id));
ApexPages.StandardController sc = new ApexPages.StandardController(con);
ContactEditController  testAccPlan = new ContactEditController(sc);  

testAccPlan.ButtonClicked='Save';

testAccPlan.Cancel();
testAccPlan.CheckDuplicateEmail();
testAccPlan.SaveContact();

testAccPlan.ButtonClicked='Calcenl';

testAccPlan.Cancel();
testAccPlan.CheckDuplicateEmail();
testAccPlan.SaveContact();


         }
     }

 
This was selected as the best answer
SalesforceAddictSalesforceAddict
thanx allot raj