New 3
New 3
************************************************************************/
/*****************************************
* Purpose: to retrieve a list of billing entities
* Parameters: set of account ids
* Returns: list of billing entities
* Exceptions: N/A
*******************************************/
if (accountIds != null) {
RegAddrLine_5__c,RegAddrState__c,RegAddrZip__c,
Parent__c,
Status_Miro__c, Airline_Tier__c,
Cust_Alpha_code__c, Membership__c,
RegAddrCountry__r.ISO_Country_Code__c,
Frozen_SITA_Membership__c
FROM Legal_entities__c
WHERE Parent__c In :accountIds
LIMIT 20000];
}
return billingObjects;
}
/*****************************************
* Purpose:
* Parameters: list of billing entities
* Returns: N/A (void)
* Exceptions: N/A
*******************************************/
if (billingCodes != null) {
return billingObjectsMap;
}
/*****************************************
* Purpose:
* Parameters:
* Returns: N/A (void)
* Exceptions: N/A
*******************************************/
if (billingCodes != null) {
String currentStatus;
if(billingCode.Status_Miro__c == 'Active') {
accountBillingStatus.put(billingCode.parent__c,
billingCode.Status_Miro__c);
}
if(billingCode.Status_Miro__c == 'Suspended') {
currentStatus =
accountBillingStatus.get(billingCode.parent__c);
if(currentStatus != 'Active') {
accountBillingStatus.put(billingCode.parent__c,
billingCode.Status_Miro__c);
}
}
if(billingCode.Status_Miro__c == 'Dead') {
currentStatus =
accountBillingStatus.get(billingCode.parent__c);
return accountBillingStatus;
}
/*****************************************
* Purpose: to retrieve a map of accounts
* Parameters: set of account ids
* Returns: map of accounts
* Exceptions: N/A
*********************************************/
if(accountIds != null) {
return accountMap;
}
/*****************************************
* Purpose: to process the accounts field updates to match the new NCC code.
* Parameters: A list of accounts and a map of the old account provided by a
trigger. i.e. Trigger.new and Trigger.oldmap
* Returns: N/A
* Exceptions: N/A
*******************************************/
try {
prospectRecordType = [Select Id
From RecordType
where DeveloperName = 'Prospect' AND
sObjectType = 'Account'].id;
}
catch (exception e) {
return;
}
if(accounts != null) {
billingCodesListForValues = getBillingEntities(accountIds);
billingObjectsMap =
createBillingCodeMap(billingCodesListForValues);
accountBillingStatus =
createStatusValues(billingCodesListForValues);
acc.addError(system.label.UpdateAccountToMatchBilling_processAccountBillingUpdates_
NCCError);
}
//if the above criteria is not met, perform the account update.
if (billObj != null && billObj.Parent__c == acc.id) {
// acc = updateAccountWithBillingData(acc, billObj);
// acc.RegAddrCountry_Code__c =
billObj.RegAddrCountry__r.ISO_Country_Code__c;
if(accountBillingStatus.get(acc.id) != null) {
acc.Account_status__c =
accountBillingStatus.get(acc.id);
}
else{acc.Account_status__c = null;}
}
}
}
}
}
/*****************************************
* Purpose: to update the account status value
* Parameters: A list of billing codes and a map of the old billing codes
provided by a trigger. i.e. Trigger.new and Trigger.oldmap
* Returns: N/A
* Exceptions: N/A
*******************************************/
if(billingEntities!= null) {
Legal_entities__c preBillEntData =
beforeUpdatebillingEntityData.get(billCode.id);
if(billCode.Parent__c != null) {
if (billCode.Status_Miro__c != preBillEntData.Status_Miro__c) {
billingCodeParentAccIds.add(billCode.Parent__c);
billingCodeStatusUpdateList.add(billCode);
}
}
}
if(billingCodeParentAccIds != null) {
accountMap = getAccounts(billingCodeParentAccIds);
if(accountBillingStatus.get(acc.id) != null) {
acc.Account_status__c =
accountBillingStatus.get(acc.id);
try {
update updatedAccountsList;
}
catch (exception e) {
Database.rollback(sp);
system.debug('Account Status failed to update');
}
}
}
}
}
/*****************************************
* Purpose: to process the accounts field updates to match the new NCC code.
* Parameters: A list of accounts and a map of the old account provided by a
trigger. i.e. Trigger.new and Trigger.oldmap
* Returns: N/A
* Exceptions: N/A
*******************************************/
/*****************************************
* Purpose: to retrieve the debtor values from a CSV file and return those
values in a map.
* Parameters: N/A
* Returns: Map of String, Strings
* Exceptions: custom exception which triggers if the code fails to retrieve the
debtor document.
*******************************************/
Document debtors;
Map<String, String> debtorMap;
try {
String debtorFileName =
InternalApplicationSettings__c.getValues('DebtorFileName').Application_Setting__c;
debtors = [Select id, body From Document Where
DeveloperName=:debtorFileName limit 1];
}
catch (exception e) {
throw new updateAccountToMatchBillingException('Your batch job -
retrieveDebtorValues failed : ' + e.getMessage());
}
if (debtors != null) {
List<String> debtorString = debtors.Body.toString().split('\n');
debtorMap = new Map<String, String>();
return debtorMap;
/*****************************************
* Purpose: to process the debtor updates in the billing codes and accounts.
* Parameters: N/A
* Returns: N/A
* Exceptions: custom exception which triggers if the code fails to update the
accounts or biiling codes.
*******************************************/
bCode.Debtor__c = boolean.valueOf(debtorMap.get(bCode.NCC__c));
bCodeupdatesSet.add(bCode);
//fix here - duplicated account due to looping bcodes which share the same
account!!
Account acc = new Account(id=bCode.Parent__c);
acc.Debt_Current_Debt_Status__c =
boolean.valueOf(debtorMap.get(bCode.NCC__c));
accUpdatesSet.add(acc);
}
bCode.Debtor__c =
boolean.valueOf(debtorMap.get(bCode.Parent_NCC_code__c));
bCodeupdatesSet.add(bCode);
}
Savepoint sp = Database.setSavepoint();
try {
update bCodeupdatesList;
update accUpdatesList;
}
catch (exception e) {
Database.rollback(sp);
throw new updateAccountToMatchBillingException('Your batch job-
processDebtorUpdate failed : ' + e.getMessage());
}
/*****************************************
* Purpose: set the billing code GEO / territory values
* Parameters: list of billing codes
* Returns: N/A
* Exceptions:
*******************************************/
if(billingEntities!= null) {
childParentNCCs.add(bc.Parent_NCC_code__c);
childBcList.add(bc);
if (parentBcMap.get(child.Parent_NCC_code__c) != null) {
if
(parentBcMap.get(child.Parent_NCC_code__c).RegAddrCountry__c != null) {
child.Parent_Code_Country__c =
parentBcMap.get(child.Parent_NCC_code__c).RegAddrCountry__c;
}
}
}
/*****************************************
* Purpose: overloads the initial method for an update version which compares
the parent NCC code values, if the parent NCC code changes it updates the child
with the new parent ncc code country.
* Parameters: list of billing codes and Map of the old version of the billing
codes.
* Returns: N/A
* Exceptions:
*******************************************/
if (bc.Parent_NCC_Code__c != oldBc.Parent_NCC_Code__c) {
parentNCCChangeList.add(bc);
/*****************************************
* Purpose: set the child billing code GEO / territory values when the parent
billing codes country changes.
* Parameters: list of billing codes and Map of the old version of the billing
codes.
* Returns: N/A
* Exceptions:
*******************************************/
if (bc.RegAddrCountry__c != oldBc.RegAddrCountry__c) {
parentBcMap.put(bc.NCC__c, bc);
if (parentBcMap.get(child.Parent_NCC_code__c) != null) {
if
(parentBcMap.get(child.Parent_NCC_code__c).RegAddrCountry__c != null) {
child.Parent_Code_Country__c =
parentBcMap.get(child.Parent_NCC_code__c).RegAddrCountry__c;
}
}
update childBcList;
// Insert records
insert accounts;
insert legalEntities;
insert contacts;
try {
insert newContact;
System.debug('Contact created successfully. Contact ID: ' +
newContact.Id);
} catch (Exception e) {
System.debug('Error creating contact: ' + e.getMessage());
}
}
if (contactToUpdate != null) {
contactToUpdate.FirstName = newFirstName;
contactToUpdate.LastName = newLastName;
contactToUpdate.Email = newEmail;
try {
update contactToUpdate;
System.debug('Contact updated successfully. Contact ID: ' +
contactToUpdate.Id);
} catch (Exception e) {
System.debug('Error updating contact: ' + e.getMessage());
}
} else {
System.debug('Contact not found with ID: ' + contactId);
}
}
public void createSampleData() {
List<Account> accounts = new List<Account>();
List<Legal_Entities__c> legalEntities = new List<Legal_Entities__c>();
insert accounts;
insert legalEntities;
}
}