You need to sign in to do that
Don't have an account?
Manish Verma 4
Contact and account should be created on LEAD CREATION.
Hi friends,
I have a reuirement : whenever user creates a lead, an account and contact should be created. I have written a trigger for this.
I am able to create a contact on lead creation but account is not getting created.
here is my trigger,your help is really appreciated !
trigger CreateUserContact on Lead(after insert) {
List<Contact> userContact = new List<Contact>();
Id rtypeId = [SELECT DeveloperName,Id FROM RecordType where SobjectType='Lead' AND
DeveloperName = 'Birlasoft_Lead' AND IsActive=true limit 1].Id;
for (Lead u: Trigger.New) {
if (u.recordTypeId== rtypeId){
Contact c = new Contact ();
c.FirstName= u.FirstName;
c.LastName= u.LastName;
c.Phone= u.Phone;
c.Email= u.Email;
c.Designation__c= u.Designation__c;
c.Role__c= u.Role__c;
userContact.add(c);
}
}
insert userContact;
}
Thanks and regards
Manish Verma
I have a reuirement : whenever user creates a lead, an account and contact should be created. I have written a trigger for this.
I am able to create a contact on lead creation but account is not getting created.
here is my trigger,your help is really appreciated !
trigger CreateUserContact on Lead(after insert) {
List<Contact> userContact = new List<Contact>();
Id rtypeId = [SELECT DeveloperName,Id FROM RecordType where SobjectType='Lead' AND
DeveloperName = 'Birlasoft_Lead' AND IsActive=true limit 1].Id;
for (Lead u: Trigger.New) {
if (u.recordTypeId== rtypeId){
Contact c = new Contact ();
c.FirstName= u.FirstName;
c.LastName= u.LastName;
c.Phone= u.Phone;
c.Email= u.Email;
c.Designation__c= u.Designation__c;
c.Role__c= u.Role__c;
userContact.add(c);
}
}
insert userContact;
}
Thanks and regards
Manish Verma
Where is the Account creation code? it shouldn't be very different to the one you already have for contacts.
Regards
here is the complete code..
trigger CreateUserContact2 on Lead(after insert) {
List<Contact> userContact = new List<Contact>();
List<Account> userAccount = new List<Account>();
Id rtypeId = [SELECT DeveloperName,Id FROM RecordType where SobjectType='Lead' AND DeveloperName = 'AMN_Lead' AND
IsActive=true limit 1].Id;
for (Lead u: Trigger.New) {
if (u.recordTypeId== rtypeId){
Contact c = new Contact ();
Account a = new Account();
a.Name= u.Account_Name__c;
c.FirstName= u.FirstName;
c.LastName= u.LastName;
c.Phone= u.Phone;
c.Email= u.Email;
c.Designation__c= u.Designation__c;
c.Role__c= u.Role__c;
userContact.add(c);
userAccount.add(a);
}
}
insert userContact;
insert userAccount;
}
Regards,
Manish
Hava a look at this code.