Skip to content

Instantly share code, notes, and snippets.

Created Dec 17, 2017
Embed
What would you like to do?
@future(callout=true)
public static void populateLimits(){
Datetime now = DateTime.Now();
List<sfLimit> lim = runAPI();
Map<String,sfLimit> lMap = new Map<String,sfLimit>();
for(sfLimit l : lim){
system.debug(l);
lMap.put(l.name, l);
}
List<Limits__c> limitList = new List<Limits__c>();
for(sfLimit l : lMap.values()){
Limits__c limitInstance = new Limits__c();
limitInstance.Name = l.name != null ? l.name : 'Missing Name';
limitInstance.Max__c = l.max != null ? l.max : 0;
limitInstance.Remaining__c = l.remaining != null ? l.remaining : 0;
limitInstance.Used__c = l.max != null && l.remaining != null ? l.max - l.remaining : 0;
limitList.add(limitInstance);
}
try{
upsert limitList Name;
} catch(DMLException e){
system.debug('Error: ' + e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment