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
DoondiDoondi 

Why after update trigger is giving 0% test coverage?

Trigger
 
trigger CreateRecord on Deal__c (after insert, after update) 
{
set<id> triggerIds = trigger.newMap.keyset();
List <Project__c> Project = [select id, Name, Deal__r.Property__r.Name from Project__c where id in :triggerIds];

List <Project__c> projectsForInsert = new List<Project__c>() ;


for(Deal__c deal : [Select id, Type__c, Property__r.Name, Property__c from Deal__c where id in :triggerIds])
{
	if( deal.Type__c == 'New' ) {
		projectsForInsert.add(new Project__c
						  (
							Name = deal.Property__r.Name, // this field is giving ID instead of Name
							Property__c = deal.Property__c // This field is giving correct update.
						  )
		);
	}
}
insert projectsForInsert;
}

Test Class
 
@isTest
public class CreateNewRecordTest{
	public static testMethod void CreateNewRecordTestMethod(){
	
	Deal__c DL = new Deal__c (type__c='interested', status__c = 'Quik');
	
	Project__c Proj = new Project__c( Name = 'King size project', Deal__c = 'ultimate');
	
	insert Proj;
	}}}

 
Mohd  RaisMohd Rais
Hi Doondi,
You can use an update keyword after insert record. Your problem will be solving.
Please check below URL how to write the test class:
1) https://developer.salesforce.com/forums/?id=906F0000000MMlgIAG
2) https://stackoverflow.com/questions/10070130/test-case-for-triggerbefore-insert-before-update-in-apex
Thanks
Mohd Rais
Raj VakatiRaj Vakati
try this cide
 
@isTest
public class CreateNewRecordTest{
	public static testMethod void CreateNewRecordTestMethod(){
	
	Deal__c DL = new Deal__c (type__c='interested',Type__c ='New', status__c = 'Quik');
	insert DL ; 
	
	Project__c Proj = new Project__c( Name = 'King size project', Deal__c = DL.Id);
	
	insert Proj;
	}
}

 
DoondiDoondi
Still, my code coverage is Zero. 

Do we need to pass user details?