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
sforcedeveloperssforcedevelopers 

Trigger test coverage

Hi..It may sound silly but this is my trigger.I have written a test class for this.It shows all the values in debug log.But still trigger test coverage is 0%

Any help please.

 

I have fedex application installed in my org.when i create a shipment and ship it,it generates a master tracking number.

Due to security issues i created a custom object and a trigger to copy tracking number in to my custom field on custom object.

 

 

 

trigger shippinginfoupdate on zkfedex__Shipment__c (after update) {
    List<customobject__c> shipList =new List<customobject__c>();
    for(zkfedex__Shipment__c zfs :trigger.new){

    customobject__c s1 =new customobject__c();
        if(zfs != null){

            s1.Tracking_Number__c = zfs.zkfedex__MasterTrackingId__c;
            s1.Ship_Date__c       = zfs.zkfedex__ShipDate__c;
            s1.Lead__c = zfs.zkfedex__RecipientLead__c;
            s1.FedexShipment__c =   zfs.id;
            shipList.add(s1);
        }
    }
    insert shipList;
}

 

Thanks in advance!!!

Best Answer chosen by Admin (Salesforce Developers) 
digamber.prasaddigamber.prasad

Hi,

 

Could you please try below test class. Actually your trigger will run on update of record, where as in your test class you have not updated recorded, but inserted only. I have made amendmant in your test class.

 

@isTest(seealldata=true)
public class test_shippinginfoupdate {
	public static testMethod void mytestmethod(){
		Lead l = new Lead(LastName='Test',Company='Test');
		insert l;

		zkfedex__Shipment__c fed = new zkfedex__Shipment__c();
		fed.zkfedex__RecipientStreet__c ='8-6-237,Stacy road';
		fed.zkfedex__MasterTrackingId__c ='1234567898764';
		fed.zkfedex__RecipientLead__c =l.id;
		insert fed;
		
		fed.zkfedex__MasterTrackingId__c ='12345678987641234';
		update fed;

		Shipping_Info__c s1 =new Shipping_Info__c();
		s1.Lead__c =fed.zkfedex__RecipientLead__c;
		s1.FedexShipment__c =fed.id;
		s1.Tracking_Number__c = fed.zkfedex__MasterTrackingId__c;
		insert s1;
	}
}

 

Let me know if you have any question.

 

Happy to help you!

All Answers

digamber.prasaddigamber.prasad

Hi,

 

Please share your test class which you have written, so that I can make amendmant into that.

sforcedeveloperssforcedevelopers
My test class

@isTest(seealldata=true)
public class test_shippinginfoupdate {
public static testMethod void mytestmethod(){
Lead l = new Lead(LastName='Test',Company='Test');
insert l;

zkfedex__Shipment__c fed = new zkfedex__Shipment__c();
fed.zkfedex__RecipientStreet__c ='8-6-237,Stacy road';
fed.zkfedex__MasterTrackingId__c ='1234567898764';
fed.zkfedex__RecipientLead__c =l.id;
insert fed;

Shipping_Info__c s1 =new Shipping_Info__c();
s1.Lead__c =fed.zkfedex__RecipientLead__c;
s1.FedexShipment__c =fed.id;
s1.Tracking_Number__c = fed.zkfedex__MasterTrackingId__c;
insert s1;
}
}
digamber.prasaddigamber.prasad

Hi,

 

Could you please try below test class. Actually your trigger will run on update of record, where as in your test class you have not updated recorded, but inserted only. I have made amendmant in your test class.

 

@isTest(seealldata=true)
public class test_shippinginfoupdate {
	public static testMethod void mytestmethod(){
		Lead l = new Lead(LastName='Test',Company='Test');
		insert l;

		zkfedex__Shipment__c fed = new zkfedex__Shipment__c();
		fed.zkfedex__RecipientStreet__c ='8-6-237,Stacy road';
		fed.zkfedex__MasterTrackingId__c ='1234567898764';
		fed.zkfedex__RecipientLead__c =l.id;
		insert fed;
		
		fed.zkfedex__MasterTrackingId__c ='12345678987641234';
		update fed;

		Shipping_Info__c s1 =new Shipping_Info__c();
		s1.Lead__c =fed.zkfedex__RecipientLead__c;
		s1.FedexShipment__c =fed.id;
		s1.Tracking_Number__c = fed.zkfedex__MasterTrackingId__c;
		insert s1;
	}
}

 

Let me know if you have any question.

 

Happy to help you!

This was selected as the best answer
sforcedeveloperssforcedevelopers
That worked.I tired updating S1. but not fed.Thank you!!