forked from deepikakhanna/SalesforcePlatformDeveloper1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorial41SOQLGovernorLimit
38 lines (33 loc) · 2.03 KB
/
tutorial41SOQLGovernorLimit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class CustomerTriggerHelper {
public static void isAfterUpdateCall(List<apex_customer__c> customerList, Map<id, apex_customer__c> newMapCustomer, Map<id, apex_customer__c> oldMapCustomer) {
createInvoiceRecords(customerList,oldMapCustomer);//Method call
updateCustomerDescription(customerList,newMapCustomer);
}
//Method To Create Invoice Records
public static void createInvoiceRecords (List<apex_customer__c> customerList, Map<id, apex_customer__c> oldMapCustomer) {
List<apex_invoice__c> InvoiceList = new List<apex_invoice__c>();
for (APEX_Customer__c objCustomer: customerList) {
if (objCustomer.APEX_Customer_Status__c == 'Active' && oldMapCustomer.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);
}
}
insert InvoiceList;//DML to insert the Invoice List in SFDC
}
//Method to update the invoice records
public static void updateCustomerDescription (List<apex_customer__c> customerList,Map<id, apex_customer__c> newMapVariable) {
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>invList=new List<apex_invoice__c>();
invList=customerListWithInvoice[0].Invoices__r;
for (APEX_Customer__c objCust: customerList) {
for (APEX_Invoice__c objInv: invList) {
objInv.APEX_Description__c = 'OK To Pay';
invoiceToUpdate.add(objInv);
}
}
update invoiceToUpdate;
}
}