Given An existing Contact
When A user updates an existing Contact email address
Then Timestamp a field on the Contact record, Email_Updated_Date__c, with the current date/time
Test Driven Development
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
private class ProcessContacts_Test { | |
@testSetup static void setup() { | |
// Create contact record | |
List<Contact> testContacts = new List<Contact>(); | |
for(Integer i=0;i<1;i++) { | |
testContacts.add(new Contact(FirstName = 'GoogleBard'+i, | |
LastName = 'Test')); | |
} | |
insert testContacts; | |
} | |
@isTest static void email_updated_date() { | |
// Get the first Contact from testSetup data | |
Contact varContact = [SELECT Email | |
FROM Contact | |
WHERE FirstName='GoogleBard0' | |
LIMIT 1]; | |
// Verify that test contact Email is null. | |
System.assertEquals(null, varContact.Email); | |
Test.startTest(); | |
// Update the contacts email field to a new value | |
varContact.Email = 'update.bard@ai.com'; | |
update varContact; | |
Test.stopTest(); | |
// Assert the Bard generated trigger worked as expected | |
System.assertEquals(System.now(), | |
[SELECT Email_Updated_Date__c | |
FROM Contact | |
WHERE FirstName = 'GoogleBard0'] | |
.Email_Updated_Date__c); | |
} | |
} |
I want you to act as a salesforce apex language interpreter. Write an apex trigger to process contacts before update and check if the field Email is being updated. If yes then update a field on that contact record Email_Updated_Date__c to the current date time
Unit Test Results
Resources:
https://bard.google.com/
No comments:
Post a Comment