Trying to write a trigger to set a lookup field (Account) on the Lead object, which is based on Account ID as a string that is passed through from an external form)... I have a working trigger (100% coverage), and what seems to be a working test class, but when I deploy in production, the validation fails due to 0% code coverage. No other exceptions. I know this should be simple! I also know it's a bad idea to pass a static ID in the test, but don't know how else to test this? If successful, will be using a custom Lead conversion tool to create new custom objects that are automatically associated with the Account ID with limited user input. Thanks in advance!!
Trigger Code:
trigger LeadSetAccount on Lead (before insert) {
// Initiate a For Loop
for (Lead newLead : Trigger.new) {
// If a Lead has a value in the Account ID field, then execute
if (newLead.Account_ID__c!=null) {
// Set Account ID based on the Account_ID string
String AccountString = newLead.Account_ID__c;
Id AccountID = AccountString;
newLead.Account__c = AccountID;
}
}
}
Test Class:
@IsTest
public class TestLeadSetAccount {
//Sets method as testMethod, so any new data generated by this test will be removed after execution
static testmethod void insertLead() {
//Name new Lead
Lead newLead = new Lead();
// Set values for new Lead
newLead.Company = 'Treadway';
newLead.FirstName = 'Marty';
newLead.LastName = 'Treadway';
newLead.Status = 'Open';
newLead.Account_ID__c = '001c000000gULKV';
// Insert new Lead
insert newLead;
}
}