You need to sign in to do that
Don't have an account?
sumit d
trigger to create contact on Account when Account is inserted
Hi All,
When a new Account is created, create a new Contact that has the following data points:
First Name = “Info”
Last Name = “Default”
Email = “info@websitedomain.tld”
Only_Default_Contact = TRUE
When the Account has more than 1 Contact, update Only_Default_Contact to FALSE.
When a new Account is created, create a new Contact that has the following data points:
First Name = “Info”
Last Name = “Default”
Email = “info@websitedomain.tld”
Only_Default_Contact = TRUE
When the Account has more than 1 Contact, update Only_Default_Contact to FALSE.
you can try the below code:
Trigger 1: on Account object(for creating the default Contact)
Trigger 2: on Contact object (to check the respective account, if it has more than 1 contact)
Apex Handler class for both above Triggers
All Answers
Below is the sample code modify according to your needs.
Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.
Best Regards
Sandhya
Please try this below Code:
Add these two triggers:
Add this as class file:
Please like and mark this as best answer if you find it positive.
Thanks
Jolly Birdi
con.Only_Default_Contact__c = TRUE;
how it will access it? contact is the child of Account how wil it access the Accounts field?
you can try the below code:
Trigger 1: on Account object(for creating the default Contact)
Trigger 2: on Contact object (to check the respective account, if it has more than 1 contact)
Apex Handler class for both above Triggers
"Try this code."
If you find your Solution then Mark this as Best Answer
Thank you!
Regards,
Suraj Tripathi
Hi,
Follow this link:
{
list<contact> listContact = new list<contact>();
for(Account acc:trigger.new)
{
for(integer i=0;i<acc.NumberofLocations__c;i++)
{
contact newContact=new contact();
newContact.accountid=acc.Id;
newContact.lastname='contact'+i;
listContact.add(newContact);
}
}
if(listContact.size()>0 && listContact!=null)
{
insert listContact;
}