//when ever a record is inserted to the account automatically inserted to the contact// //limit reached the records //edhi oka doubt undi kanukovali// trigger Scenario1 on Account (after insert,before insert,before update,after update,before delete) { User u = [SELECT Id,Name From User WHERE username = 'ramasiva094@gmail.com']; List<Account>Acc = new List<Account>([SELECT Id,Name FROM Account WHERE createddate = today or lastmodifieddate = today]); List<Contact>lstcons = new List<Contact>(); for(Account acc: trigger.new){ Contact con = new Contact(); con.LastName = acc.Name; con.AccountId = acc.Id; lstcons.add(con); if(acc.NumberofLocations__c>2){ acc.adderror('reached limit today'); if(u.Name =='sivakrishna1837@gmail.com'){ if(trigger.isdelete){ for(Account acc2 : trigger.old){ acc2.adderror('This Account cannot be deleted');
//limit reached the records //edhi oka doubt undi kanukovali//
trigger Scenario1 on Account (after insert,before insert,before update,after update,before delete) {
User u = [SELECT Id,Name From User WHERE username = 'ramasiva094@gmail.com'];
List<Account>Acc = new List<Account>([SELECT Id,Name FROM Account WHERE createddate = today or lastmodifieddate = today]);
List<Contact>lstcons = new List<Contact>();
for(Account acc: trigger.new){
Contact con = new Contact();
con.LastName = acc.Name;
con.AccountId = acc.Id;
lstcons.add(con);
if(acc.NumberofLocations__c>2){
acc.adderror('reached limit today');
if(u.Name =='sivakrishna1837@gmail.com'){
if(trigger.isdelete){
for(Account acc2 : trigger.old){
acc2.adderror('This Account cannot be deleted');
}
}
}
if(trigger.Isupdate){
for(Account acc3 : trigger.new){
acc3.adderror('ca not update');
}
}
if(trigger.isinsert){
for(Account acc4 : trigger.new){
acc4.adderror('ca not insert');
}
}
}
}
insert lstcons;
}