You need to sign in to do that
Don't have an account?

Creating a Contact when Creating a New Account with a Field = True
I created a Trigger to create a New Contact when an Account is created. I only want the Contact created when a boolean field is True. The Trigger will create the Contact when the if(acc.Diamond_Contractor__c == '1') is commented out, but never creates a Contact if the statement is included. Am I checking for the field too soon in the Trigger? Thanks! John!
trigger CreateAccountContact on Account (after insert, after update){
if(Trigger.isInsert){
List<Contact> ct = new List <Contact>();
for(Account acc : trigger.new){
if(acc.Diamond_Contractor__c == '1') {
Contact c = new Contact(LastName = 'User',
FirstName = 'Extranet',
AccountId=acc.id,
Fax=acc.Fax,
MailingStreet=acc.BillingStreet,
MailingCity=acc.BillingCity,
/* similarly add all fields which you want */
MailingState=acc.BillingState,
MailingPostalCode=acc.BillingPostalCode,
MailingCountry=acc.BillingCountry,
Phone=acc.Phone);
ct.add(c);
}
insert ct;
}
}
}
trigger CreateAccountContact on Account (after insert, after update){
if(Trigger.isInsert){
List<Contact> ct = new List <Contact>();
for(Account acc : trigger.new){
if(acc.Diamond_Contractor__c == '1') {
Contact c = new Contact(LastName = 'User',
FirstName = 'Extranet',
AccountId=acc.id,
Fax=acc.Fax,
MailingStreet=acc.BillingStreet,
MailingCity=acc.BillingCity,
/* similarly add all fields which you want */
MailingState=acc.BillingState,
MailingPostalCode=acc.BillingPostalCode,
MailingCountry=acc.BillingCountry,
Phone=acc.Phone);
ct.add(c);
}
insert ct;
}
}
}
Thanks,
Balaji
You mentioned it as a boolean variable, where it is not! It is a picklist which has string values Yes,No,None. So you need to verify against those valid values instead you were validating the value against "1". So try the below version now!
Hope it helps:
Thanks,
balaji