You need to sign in to do that
Don't have an account?
Tucko
Trigger for creating Account records
Hello,
I am new to this platform. I started to learn about triggers and I stuck with this code, I can't get what is not right about it. Every help will be great. Thank you!
trigger AccountTrigger on Account (after update,after insert, before update, before insert) { List<Account>listAccounts = new List<Account>(); for(Account a: Trigger.new){ if(a.CheckPayment__c == True){ Account account1 = new Account(); account1.Name = 'Akaunt1'; account1.First_Name__c = 'Acount1'; account1.Second_Name__c = 'Surname1'; account1.Status__c = 'Idle'; Account account2 = new Account(); account2.Name = 'Akaunt2'; account2.First_Name__c = 'Acount2'; account2.Second_Name__c = 'Surname2'; account2.Status__c = 'Idle'; Account account3 = new Account(); account3.Name = 'Akaunt3'; account3.First_Name__c = 'Acount3'; account3.Second_Name__c = 'Surname3'; account3.Status__c = 'Idle'; Account account4 = new Account(); account4.Name = 'Akaunt4'; account4.First_Name__c = 'Acount4'; account4.Second_Name__c = 'Surname4'; account4.Status__c = 'Idle'; Account account5 = new Account(); account5.Name = 'Akaunt5'; account5.First_Name__c = 'Acount5'; account5.Second_Name__c = 'Surname5'; account5.Status__c = 'Idle'; } } insert listAccounts; }
Try with below code .
Thanks
Manoj
All Answers
Try with below code .
Thanks
Manoj
Above trigger will work ,I don't know your requirment but as you have added before insert and after insert ,So it will create 10 Accouns on insert of one account and 10 Accounts on update of one Account if your CheckPayment__c is true .