+ Start a Discussion
Sainath VenkatSainath Venkat 

test class for metadata

I am working on Custom Metadata and I wrote the below trigger.
trigger userSignature on User (before insert,after insert){
     if(trigger.isBefore && Trigger.isInsert){
        Org_Email_Signature__mdt[] signature = [SELECT MasterLabel,Email_Signature__c FROM Org_Email_Signature__mdt];
        if(signature!=nulll & !signature.isEmpty()){
            for(user usr : Trigger.new){
                usr.Signature = signature[0].Email_Signature__c;
Can anyone help me out in writing a test class for the above trigger please.
Best Answer chosen by Sainath Venkat
Steven NsubugaSteven Nsubuga
try this
private class userSignatureTest {
	@isTest static void testTrigger() {
		Profile pf= [Select Id from profile where Name='System Administrator']; 
		String orgId=UserInfo.getOrganizationId(); 
		User uu=new User(firstname = 'ABC', 
						 lastName = 'XYZ', 
						 email =  'uniqueName@test' + orgId + '.org', 
						 Username = 'uniqueName@test' + orgId + '.org', 
						 EmailEncodingKey = 'ISO-8859-1', 
						 Alias = 'ABC', 
						 TimeZoneSidKey = 'America/Los_Angeles', 
						 LocaleSidKey = 'en_US', 
						 LanguageLocaleKey = 'en_US', 
						 ProfileId = pf.Id

		insert uu;
		User testUser = [SELECT Signature FROM User where Id =:uu.id];
		System.assert(testUser.Signature != null);