Created
October 24, 2016 10:57
-
-
Save kurunve/0293b16fe54a05b3b58f4dac6465c7af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MegaQueueable implements Queueable, Database.AllowsCallouts { | |
public Map<Id, String> AssetData; | |
public MegaQueueable (Map<Id,String> asset_data){ | |
AssetData = asset_data; | |
} | |
public void execute(QueueableContext context) { | |
Map<Id, Asset> asset_map = new Map<Id, Asset>([SELECT Id, assetLastValidatedLogicHistory__c FROM Asset WHERE Id in :AssetData.keySet()]); | |
for(Id asset_id : asset_map) { | |
Asset asset_record = asset_map.get(asset_id); | |
asset_record.assetLastValidatedLogicHistory__c = ('' + asset_record.assetLastValidatedLogicHistory__c + AssetData.get(asset_id)).right(131072); | |
} | |
update asset_map.values(); | |
} | |
} | |
public static void setUpdatedAssetLastValidatedFields() { | |
Map<Id, String> asset_data = new Map<Id, String>(); | |
List<Id> asset_ids = new List<Id>(); | |
for (Asset assetProcess : (List<Asset>) Trigger.new) { | |
Asset oldAsset = (Asset) Trigger.oldMap.get(assetProcess.id); | |
String change_history = | |
'Timestamp = ' + System.now() + '\n' + | |
'User ID = ' + UserInfo.getUserId() + '\n' + | |
'User Name = ' + UserInfo.getUserName() + '\n' + | |
'INPUTS:\n' + | |
'old Install_Street1__c = ' + oldAsset.Install_Street1__c + '\n' + | |
'old Install_Street2__c = ' + oldAsset.Install_Street2__c + '\n' + | |
'old Install_City__c = ' + oldAsset.Install_City__c + '\n' + | |
'old Install_State_Province__c = ' + oldAsset.Install_State_Province__c + '\n' + | |
'old Install_Zip_Code__c = ' + oldAsset.Install_Zip_Code__c + '\n' + | |
'old Install_Country__c = ' + oldAsset.Install_Country__c + '\n' + | |
'new Install_Street1__c = ' + assetProcess.Install_Street1__c + '\n' + | |
'new Install_Street2__c = ' + assetProcess.Install_Street2__c + '\n' + | |
'new Install_City__c = ' + assetProcess.Install_City__c + '\n' + | |
'new Install_State_Province__c = ' + assetProcess.Install_State_Province__c + '\n' + | |
'new Install_Zip_Code__c = ' + assetProcess.Install_Zip_Code__c + '\n' + | |
'new Install_Country__c = ' + assetProcess.Install_Country__c + '\n' + | |
'LOGIC DECISIONS:\n'; | |
asset_data.put(assetProcess.Id, change_history); | |
asset_ids.add(assetProcess.Id); | |
} | |
for(Integer i = 0; i < asset_ids.size(); i+=10) { | |
Map<Id, String> partial_asset_data = new Map<Id, String>(); | |
integer k = i; | |
while(k < asset_data.length && k < i + 10) { | |
partial_asset_data.put(asset_ids.get(k), asset_data.get(asset_ids.get(k))); | |
} | |
System.enqueueJob(new MegaQueueable(partial_asset_data)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It will reach the heap size when for loop is iterating in setUpdatedAssetLastValidatedFields method . So how could you queue a job after the loop is completed.