You need to sign in to do that
Don't have an account?
Visithra
Help me with the below trigger scenario
Get help with this trigger, when an no.contacts in account is entered same contacts should be created with its related account, and it should update as well.for eg when created with 3 no of contacts and while updating as 5, total 5 contacts should be created.,
i have trigger for inserted, got stuck in updation,
rigger AccountContactCaaseStudy3 on Account (after insert) {
Switch On Trigger.OperationType
{
When AFTER_INSERT
{
List<Contact> conList=new List<Contact>();
for(Account accRecord:trigger.new)
{
for(integer i=1;i<=accRecord.NumberofLocations__c; i++)
{
Contact ConRecord=new Contact();
ConRecord.AccountID=accRecord.Id;
ConRecord.LastName= accRecord.Name +'Contact' +i;
conList.add(ConRecord);
}
}
if(conList.size()>0)
insert conList;
}
}
}
Thanks.
i have trigger for inserted, got stuck in updation,
rigger AccountContactCaaseStudy3 on Account (after insert) {
Switch On Trigger.OperationType
{
When AFTER_INSERT
{
List<Contact> conList=new List<Contact>();
for(Account accRecord:trigger.new)
{
for(integer i=1;i<=accRecord.NumberofLocations__c; i++)
{
Contact ConRecord=new Contact();
ConRecord.AccountID=accRecord.Id;
ConRecord.LastName= accRecord.Name +'Contact' +i;
conList.add(ConRecord);
}
}
if(conList.size()>0)
insert conList;
}
}
}
Thanks.
To handle the update scenario and ensure that the correct number of contacts is created or updated based on the "NumberofLocations__c" field in the Account, you can use a combination of "after insert" and "after update" triggers.
Try this code wherein I have added logic to handle both insert and update scenarios.
If this information helps, please mark the answer as best. Thank you