I need to update a huge amount of records, that are being updated by an integration.
i have the following code:
private void populateRelatedAssetsFields() {
System.debug('LicenseTriggerHandler.populateRelatedAssetsFields');
Set<Id> licenseIdSet = new Set<Id>();
Map<Id,Id> licenseIdToAccountIdMap = new Map<Id,Id>();
Map <Id, License__c> oldLicenseMap = (Map <Id, License__c>) Trigger.oldMap;
for (License__c license_i : (List<License__c>)Trigger.new) {
if (license_i.Account__c != null && (Trigger.isInsert || (oldLicenseMap.get(license_i.Id).Account__c != license_i.Account__c))) {
licenseIdSet.add(license_i.Id);
licenseIdToAccountIdMap.put(license_i.Id,license_i.Account__c);
}
}
List<Asset> assetList = [SELECT Id,AccountId,License__c FROM Asset WHERE License__c IN: licenseIdSet];
if (!assetList.isEmpty()) {
for(Asset asset_i : assetList) {
asset_i.AccountId = licenseIdToAccountIdMap.get(asset_i.License__c);
}
system.debug('assetList.size(): ' + assetList);
Update assetList;
}
}
UPDATE
There is a limit to the amount of time we allow a trigger to run in one transaction. AssetTrigger runs every time i update 200 records at a time, and i want the AssetTrigger to run once\run in different transactions.
How is it possible?