You need to sign in to do that
Don't have an account?
Miguel Roa
Writing my first test class
Hello, I'm new to Salesforce and I've been told to write a test class for this class and frankly I don't know where to start.
The thing is that the examples I've found on trailblaze only cover really simple classes with numeric returns.
Could you please provide some guidance? Thanks in advance.
This is the aforementioned class:
The thing is that the examples I've found on trailblaze only cover really simple classes with numeric returns.
Could you please provide some guidance? Thanks in advance.
This is the aforementioned class:
public class BlacklistLeadValidation { public static string errorMsg { get { return 'Your attempt to change the [FieldName] status was not successful due to insufficient privileges. Please send a chatter post to #help with supporting documentation for the change request.'; } } public static void OptInWireless_Wireline(Map<Id, Lead> leadRecord, Map<Id, Lead> leadRecordOld) { if (leadRecord != null && leadRecordOld != null) { List<Profile> currentUserProfile = [Select Id, Name From Profile Where Id = :UserInfo.getProfileId()]; if (currentUserProfile.size() > 0) { if (!Label.AP_VBM_ApprovalAllowedProfiles.containsIgnoreCase(currentUserProfile[0].Name)) { for(id recId : leadRecord.keySet()) { Lead leadOld = leadRecordOld.get(recId); Lead leadNew = leadRecord.get(recId); // Wireline consent validation (booleans cannot moved from true to false) if (leadOld.Do_Not_Call__c == true && leadNew.Do_Not_Call__c == false) { leadNew.Do_Not_Call__c.addError(errorMsg.replace('[FieldName]', 'Do Not Call')); } if (leadOld.Do_Not_Mail__c == true && leadNew.Do_Not_Mail__c == false) { leadNew.Do_Not_Mail__c.addError(errorMsg.replace('[FieldName]', 'Do Not Mail')); } if (leadOld.HasOptedOutOfEmail == true && leadNew.HasOptedOutOfEmail == false) { leadNew.HasOptedOutOfEmail.addError(errorMsg.replace('[FieldName]', 'Do Not Email')); } // Wireless consent validation (booleans cannot moved from true to false) if (leadOld.Do_Not_Email_VZW__c == true && leadNew.Do_Not_Email_VZW__c == false) { leadNew.Do_Not_Email_VZW__c.addError(errorMsg.replace('[FieldName]', 'Do Not Email Wireless')); } if (leadOld.Do_Not_Call_VZW__c == true && leadNew.Do_Not_Call_VZW__c == false) { leadNew.Do_Not_Call_VZW__c.addError(errorMsg.replace('[FieldName]', 'Do Not Call Wireless')); } if (leadOld.Do_Not_Mail_VZW__c == true && leadNew.Do_Not_Mail_VZW__c == false) { leadNew.Do_Not_Mail_VZW__c.addError(errorMsg.replace('[FieldName]', 'Do Not Mail Wireless')); } // Not Opt In cannot be change either for wireline or wireless if (leadOld.Email_Opt_In__c == 'No Opt In' && leadNew.Email_Opt_In__c != 'No Opt In') { leadNew.Email_Opt_In__c.addError(errorMsg.replace('[FieldName]', 'Email Opt In')); } if (leadOld.Email_Opt_In_VZW__c == 'No Opt In' && leadNew.Email_Opt_In_VZW__c != 'No Opt In') { leadNew.Email_Opt_In_VZW__c.addError(errorMsg.replace('[FieldName]', 'Email Opt In Wireless')); } } } } } } }
Hi Please find the test class
do some need full changes according to your code.
Please mark it as the Best Answer if it helps you.
Thank You
All Answers
Hi Please find the test class
do some need full changes according to your code.
Please mark it as the Best Answer if it helps you.
Thank You
and for this
test class: