You need to sign in to do that
Don't have an account?
wixxey
Test Code for the trigger
Kindly help me in writing the test code for the below trigger, i will be thankful
trigger detectClone on Contact (before insert, after update){ for(Contact acc : trigger.new){ if(Trigger.isInsert){ Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {acc.Email}; mail.setToAddresses(toAddresses); mail.setSenderDisplayName('Support Team'); mail.setSubject('LogIn information'); mail.setBccSender(false); mail.setUseSignature(false); Double rnd = math.random(); String str_rnd = String.valueOf(rnd); String temp_pass = str_rnd.replace('.','1'); String pass = temp_pass.substring(1,6); mail.setHtmlBody('Dear '+acc.LastName+'<br/><br/>'+ 'Welcome to EZQCP! You have been invited to join the EZQCP [Account Name] account team.<br/> '+ 'Your user name is below:<br/><br/>'+ 'User Name: '+ acc.User_Name__c+'<br/>'+ 'Password: '+ pass +'<br/><br/>'+ ' To accept the invitation and set your username, log in automatically by clicking www.xxxxx.xxxxxx<br/> '+ 'If you experience problems with the above link, please contact support@ezqcp.com for assistance.'); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); acc.Password__c = pass; } else if(Trigger.isUpdate ){ List<Contact> admin = [Select Id, Type__c From Contact Where AccountId =:acc.AccountId AND Type__c = 'Customer Admin' ]; if(admin.size()<1){ acc.addError('Each Account must have atleast one Contact with Admin privileges'); } } } }
Hi,
It is custom validation error try below code.
Test Class:
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
All Answers
Hi,
Here is the Test class for your trigger.
Test Class:
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
Thanx for giving your time ...The test code got failed generating the following error code
System.DmlException: Update failed. First exception on row 0 with id 0039000000NoBdxAAF; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Each Account must have atleast one Contact with Admin privileges: []
Hi,
It is custom validation error try below code.
Test Class:
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
I have tried the other code but the same error.. thanx for giving your precious time