-
-
Save anonymous/2414bb5d0bbdbe7f234b3c7fcd058ce4 to your computer and use it in GitHub Desktop.
This file contains 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
@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