User Story
As a Salesforce administrator, I want to develop a trigger named "LeadTrigger" that operates before lead insertion and updates. This trigger will evaluate the lead source of incoming or modified leads and assign appropriate ratings based on predefined criteria:
- If the lead source is identified as "Web" or "Phone Inquiry", the trigger will set the lead's rating to "Hot".
- If the lead source is "Partner Referral" or "Purchased List", the trigger will assign a rating of "Warm".
- For all other lead sources, the trigger will assign a rating of "Cold"
Codes
trigger LeadTrigger on Lead (before insert, before update) {
for (Lead leadRecord : Trigger.new) {
if (leadRecord.LeadSource == 'Web' || leadRecord.LeadSource == 'Phone Inquiry') {
leadRecord.Rating = 'Hot';
} else if (leadRecord.LeadSource == 'Partner Referral' || leadRecord.LeadSource == 'Purchased List') {
leadRecord.Rating = 'Warm';
} else {
leadRecord.Rating = 'Cold';
}
}
}
Test Class
@isTest
public class LeadTriggerTest {
@isTest
static void testLeadRatingAssignment() {
Lead testLeadWeb = new Lead(FirstName='Test', LastName='Lead', Company='Test Company', LeadSource='Web');
Test.startTest();
insert testLeadWeb;
Test.stopTest();
}
}
Video
Video does not exists.