I'm developing a connected app that will be available in the App Exchange. I'm struggling to understand what user my app should connect to Salesforce as. The app has a component that monitors the realtime API for events. This process needs to run continuously.
My remote service is NodeJS and I'm utilizing the NForce library to connect to PushTopics on the Streaming API. I'm monitoring for inserts and updates on certain objects, e.g. Opportunities.
If a new org installs my app from the App Exchange, do I use my existing system user to monitor the new org or do I create a new user for the new org? If I create a new user what is the sequence of steps from app install to my remote application connecting to the realtime API?
I've started working on an APEX post install script that creates a user and sets a password. That way I will have a user in the org that I can use. I'm planning to use an Apex callout to trigger my application to connect to the realtime API with the newly created user.
I'm concerned that this is the wrong approach and might be rejected by Salesforce on security grounds.
Post install script:
global class PostInstallClass implements InstallHandler {
String Password = 'pword' ;
global void onInstall(InstallContext context) {
if(context.previousVersion() == null) {
User u = new User();
u.username = 'uname.com';
u.email = 'email.com';
u.lastName = 'lname';
u.firstName = 'fname';
u.alias = 'alias';
u.languagelocalekey = 'en_US';
u.localesidkey = 'en_US';
u.emailEncodingKey = 'UTF-8';
u.timeZoneSidKey = 'America/Los_Angeles';
u.profileId = '00ei00000013M1P';
insert u;
system.setPassword(u.id, Password);
pushData(context.organizationId(), context.installerId()) ;
}
}