- ·上一篇文章:Apex - 触发设计模式
- ·下一篇文章:Apex - 批量处理
Apex - Governer Limits调节器限制
Customer__c objCustomer: customerList) { if (objCustomer.APEX_Customer_Status__c == 'Active' && mapOldItToCustomers.get(objCustomer.id).APEX_Customer_Status__c == 'Inactive') {//condition to check the old value and new value APEX_Invoice__c objInvoice = new APEX_Invoice__c(); objInvoice.APEX_Status__c = 'Pending'; objInvoice.APEX_Customer__c = objCustomer.id; InvoiceList.add(objInvoice); } } system.debug('InvoiceList&&&'+InvoiceList); insert InvoiceList;//DML to insert the Invoice List in SFDC. This also follows the Bulk pattern } //Method to update the invoice records public static void updateCustomerDescription (List<apex_customer__c> customerList, Map<id, apex_customer__c> newMapVariable, Map<id, apex_customer__c> oldCustomerMap) { List<apex_customer__c> customerListWithInvoice = [SELECT id, Name,(SELECT Id, Name, APEX_Description__c FROM Invoices__r) FROM APEX_Customer__c WHERE Id IN :newMapVariable.keySet()];//Query will be for only one time and fetches all the records List<apex_invoice__c> invoiceToUpdate = new List<apex_invoice__c>();List<apex_invoice__c> invoiceFetched = new List<apex_invoice__c>();invoiceFetched = customerListWithInvoice[0].Invoices__r;system.debug('invoiceFetched'+invoiceFetched); system.debug('customerListWithInvoice****'+customerListWithInvoice);for (APEX_Customer__c objCust: customerList) {system.debug('objCust.Invoices__r'+objCust.Invoices__r); if (objCust.APEX_Active__c == true && oldCustomerMap.get(objCust.id).APEX_Active__c == false) {for (APEX_Invoice__c objInv: invoiceFetched) {system.debug('I am in For Loop'+objInv);objInv.APEX_Description__c = 'OK To Pay';invoiceToUpdate.add(objInv);//Add the modified records to List}} }system.debug('Value of List ***'+invoiceToUpdate); update invoiceToUpdate;//This statement is Bulk DML which performs the DML on List and avoids the DML Governor limit } }//Trigger Code for this class: Paste this code in 'Customer_After_Insert' trigger on Customer Objecttrigger Customer_After_Insert on APEX_Customer__c (after update) { CustomerTriggerHelper.isAfterUpdateCall(Trigger.new, trigger.newMap, trigger.oldMap);//Trigger calls the helper class and does not have any code in Trigger}其他Salesforce Governor限制以下是一些重要的Salesforce Governor限制,我们需要记住。 你可以检查其他Salesforce Governor限制以及使用Salesdorce.com Apex开发人员指南。 描述限制Total heap size总堆大小6 MB / 12 MBTotal number of DML statements issued发出的DML语句的总数150Total number of records retrieved by a single SOSL query单个SOSL查询检索的记录总数2000Total number of SOSL queries issued发出的SOSL查询的总数20Total number of records retrieved by Database.getQueryLocatorDatabase.getQueryLocator检索的记录总数10000Total number of records retrieved by SOQL queries通过SOQL查询检索的记录总数50000
Apex - Governer Limits调节器限制