You need to sign in to do that
Don't have an account?
Craig Grove
Error on Trigger deployment to production (worked in sandbox)
I'm new to triggers and apex, but was attempting a simple trigger to create a child object on Contact object. Goal is to establish a contact to account relationship when creating a contact using the contacts Name and Account to populate the relationship object. Here is the trigger I wrote, which worked in Sandbox.
trigger CreateContactAccountAssociation on Contact (after insert)
{ List<Contact_Account_Association__c> Associations = new List<Contact_Account_Association__c>();
//For each Contact processed by the trigger, add a new
//Association record for the specified user.
//Note that Trigger.New is a list of all new Contacts
//That are being created.
for (Contact newContact: Trigger.New) {
if (newContact.RecordTypeId !='012700000009iHg' ) {
Associations.add(new Contact_Account_Association__c(
Account__c = newContact.AccountId,
Contact__c = newContact.Id));
}
}
insert Associations;
}
Trigger worked in Sandbox......Created below apex class which passed in Sandbox
@IsTest(SeeAllData=True)
public class TestTrigger {
static testmethod void insertContact() {
Contact u = new Contact();
u.Salutation = 'Mr.';
u.FirstName = 'Test';
u.LastName = 'Trigger';
u.AccountId = '00170000011BckQ';
insert u;
}
}
Received below errors when deploying to production
Any assistance is appreciated!!
trigger CreateContactAccountAssociation on Contact (after insert)
{ List<Contact_Account_Association__c> Associations = new List<Contact_Account_Association__c>();
//For each Contact processed by the trigger, add a new
//Association record for the specified user.
//Note that Trigger.New is a list of all new Contacts
//That are being created.
for (Contact newContact: Trigger.New) {
if (newContact.RecordTypeId !='012700000009iHg' ) {
Associations.add(new Contact_Account_Association__c(
Account__c = newContact.AccountId,
Contact__c = newContact.Id));
}
}
insert Associations;
}
Trigger worked in Sandbox......Created below apex class which passed in Sandbox
@IsTest(SeeAllData=True)
public class TestTrigger {
static testmethod void insertContact() {
Contact u = new Contact();
u.Salutation = 'Mr.';
u.FirstName = 'Test';
u.LastName = 'Trigger';
u.AccountId = '00170000011BckQ';
insert u;
}
}
Received below errors when deploying to production
Any assistance is appreciated!!
All Answers