We want to develop an application that would monitor other companies/people Salesforce sandbox/production instances and produce notifications about some changes that happen there (user configures what he wants to be notified about). For example, user wants to be notified whenever an Account is removed from his instance.
I understand this is possible by REST API and that was our initial approach. Bottom line is: user defines what he wants to be informed about in our app we create a monitor and we use some interval based rest call to salesforce inside it with a specialized query (f.e SELECT Name, [other fields user wants to see] FROM Opportunity WHERE LastModifiedDate > start AND LastModifiedDate <= end.
The WHERE clause changes because of interval, thus allowing us to have constant monitoring over customer instance. That of course has a drawback that it uses a lot of API calls, and because its interval based, it is not instant (its delayed depending how long interval is). The other thing is we don't have any information about how the data looked before change (access to history), we only see what is in Salesforce at a moment of making a call (this is important for updates).
We started to wonder if there aren't any other ways of handling that problem (monitoring customer salesforce orgs). We aim towards having instant notifications and maximal availability (among as many editions as possible).
I have noticed that it is possible to create ApexTriggers(https://xxx.salesforce.com/services/data/v32.0/sobjects/ApexClass) and ApexClasses through REST API as well. I was thinking that maybe I could generate such Trigger/Class and add it to customer Salesforce instance, and then it would have a callback to our application with the data. This would give us instant notifications and would not eat away API calls as well as let us see history. I managed to create such trigger class and get it working. The flow is user configures his monitor on our app side, we make REST call to add trigger to his instance. When the trigger is 'triggered' it calls back our app endpoint with data.
Only obstacle I see now is Remote Site Settings, since the endpoint I'm making callbacks to from trigger has to be added there. Is there a way to add it without involving Salesforce user (customer)? We want to avoid manual steps to have an easy customer experience.
I'm also wondering if there aren't any more obstacles, like limitations of actual different salesforce editions that would make my idea invalid in some way or anything else really that I'm not seeing (it is an ongoing learning process). I also am not sure if I can create Apex Classes on production instances.
We don't want to create an App that is build into Salesforce using appexchange (and go through all that approval process). We want to connect to users Salesforce instance (authentication through OUATH) and get some data from there, but we want to do it in a smart way, so not eat API calls when its not needed (so theoretically put triggers on SF to inform us when something happens instead of making calls all the time).
To put it shortly: We want to react on changes, see what changed to what and have this data reliably and fast without making unnecessary calls.
What do you think about both approaches, which would you use and why or is there anything else I need to keep in mind (limitations)? Are there any other approaches you would choose? Any help with this is greatly appreciated. Sorry for a long question, I wanted to explain the problem as detailed as possible.