+ Start a Discussion
yash mehta 12yash mehta 12 

CAN ANYONE WRITE TEST CLASS FOR THIS


trigger cc_contactUpdateOnApplication on Application__c (after update) {
    Map<id,id> applicationMap = new Map<id,id>();
    List<contact>conList = new List<contact>();
    for(Application__c application : [SELECT id,Name,Contact__c,CC_Term__c,Admissions_Status__c FROM Application__c Order By LastModifiedDate DESC Limit 1]){
        system.debug('@@@@@application'+application);
        if(application.Admissions_Status__c != Trigger.oldMap.get(application.Id).Admissions_Status__c){
            // if(application.Admissions_Status__c !=null){
            applicationMap.put(application.Contact__c, application.Id);
            system.debug('#####applicationMap'+applicationMap);
        }
    } 
    for(contact con :[SELECT id,Name,Active_Application_CC__c FROM contact WHERE Id IN :applicationMap.keySet()] ){
        con.Active_Application_CC__c = applicationMap.get(con.Id);
        conList.add(con);
        system.debug('$$$$conList'+conList);
    }
    if(conList.size() >0){
        update conList;
        system.debug('####conList'+conList);
    }
}
Sandeep WaliaSandeep Walia
Hi Yash,

Please add relevant values in the fields as mentioned in the comments. This class should provide sufficient code coverage.
@isTest
private  class cc_TriggerOnapplicationTest{
	static testMethod testMethod1(){
		Contact objContact = new Contact();
		//Insert Contact Object
		objContact.Name = 'test Name';
		objContact.Active_Application_CC__c = ; //Enter valid value
		insert objContact;
		//Insert Application 
		Application__c objApplication = new Application__c();
		objApplication.name                 = 'test Application';
		objApplication.Contact__c 			= objContact.Id;
		objApplication.CC_Term__c 			= ;//Enter a valid value
		objApplication.Admissions_Status__c = ;//Enter a valid value
		insert objApplication;
		objApplication.Admissions_Status__c = ;//Enter a different value this time
		update objApplication;//Your trigger will fire now
		//You can add an assert statement if you wish to validate values
	}
}

Hope this helps,
Sandeep
 
sukanya banekarsukanya banekar
Also, add system.assertEquals to your test class.
IN above test class add below lines
Contact con= [SELECT id, Active_Application_CC__c  from contact where Id =: objContact.Id];
system.assertEquals(con.Active_Application_CC__c , objApplication.id);