public class GoverningLimitsExample { /* With in a single Transaction we can only have 150 DML statements 1.50 DML statements on Account 2.100 DML statements on contact 3.1 Update on account 4.1 Delete in Contact This is trying to make 152 DML statements which give an Exception to TOO Many DML :151 statments */ public void dmlCall(){ /* This loop will be executed 50 times which means 50 insert statments will run */ for(Integer i=1;i<=50;i++){ Account a=new Account(Name='DML Statement'); insert a; } /* This loop will be executed 50 times which means 100 insert statments will run */ for(Integer i=1;i<=100;i++){ Contact c=new Contact(LastName='aaa'); insert c; } /* This is calling DML of update statement once's */ Account a=[select id ,description from Account limit 1]; a.description='This is a test DML'; update a; /* This is calling DML of delete statement once's */ List<Contact> cons=[select id from Contact limit 5]; delete cons; } /* * We can at max 100 SOQl queries with in a single Transaction * Total 102 SOQL Queries it throws Too many SOQLQueries : 101 */ public void soqlCall(){ Account a=[select id ,name from Account limit 1]; Contact c=[select id ,lastName from Contact limit 1]; for(Integer i=1;i<=50;i++){ List<Account> accs=[select id,phone from Account ]; } for(Integer i=1;i<=50;i++){ List<Contact> cons=[select id,lastname from Contact]; } } /* SOSL Limits : 20 */ public void soslCall(){ List<List<Sobject>> result=[FIND 'satish' In ALL FIELDS Returning Account(Name)]; for(Integer i=1;i<=20;i++){ List<List<Sobject>> result1=[FIND 'satish' In ALL FIELDS Returning Account(Name)]; } } /* DML ROWS: 10,000 records * This methods is performing DML on 10010 records so this will throw * TOO MANY DML ROWS : 10001 Exception */ public void dmlrows(){ /* This will perform insert of 9000 records in this loop */ List<Account> accs=new List<Account>(); for(Integer i=1;i<=9000;i++){ Account a=new Account(Name='Aaaa'); accs.add(a); } insert accs; /* This loop will insert 1000 contacts in this loop */ List<Contact> cons=new List<Contact>(); for(Integer i=1;i<=1000;i++){ Contact c=new Contact(lastname='testing'); cons.add(c); } insert cons; /* This loop will update 5 Accounts in this loop */ List<Account > accResult=[select id ,description from Account limit 5]; for(Account a1:accResult){ a1.description='Testing'; } update accResult; /* This loop will delete 5 contact in this loop */ List<Contact> clist=[select id from Contact limit 5]; delete clist; } }
Tuesday, 12 April 2016
Governing Limits
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment