Skip to content

Instantly share code, notes, and snippets.

Created December 17, 2017 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2414bb5d0bbdbe7f234b3c7fcd058ce4 to your computer and use it in GitHub Desktop.
Save anonymous/2414bb5d0bbdbe7f234b3c7fcd058ce4 to your computer and use it in GitHub Desktop.
@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