i need to trigger email when data storage is hitting the limit.i dont see any configuration where i can set the email based on some usage.Please suggest.Is there any way without using the third party(appexchange)tools.
Asked
Active
Viewed 96 times
1 Answers
3
I don't think you can use trigger here. But you can use scheduler class and Limit API to get these details.
Essentially, you have to build an apex class which does a callout to the REST API. You can then schedule that class to run in scheduled Apex. The big problem is that you have to pass a username and password as part of the login call to get a session:
- How to login and get a session -
- Class to call the login:
public class CurrentStorage {
@Future(callout=true)
public static void getStorage() {
String sid = Login.login('', '');
HttpRequest req = new HttpRequest();
req.setMethod('GET');
req.setEndpoint('
https://na2.salesforce.com/services/data/v32.0/limits');
req.setHeader('Authorization', 'OAuth '+ sid);
Http http = new Http();
HTTPResponse res = http.send(req);
Map m = (Map)JSON.deserializeUntyped(res.getBody());
Map dataStorage = (Map)m.get('DataStorageMB');
System.debug('Current Storage: ' + dataStorage.get('Remaining'));
return;
}
}
Reference:
Tushar Sharma
- 29,515
- 7
- 36
- 60