• Sergey Baydaluk
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
Hi guys.
Looks like I've stuck here. I've added an Apex class to run at regular intervals in my project. The idea is class should be run every "n" hours and should call our API using named credentials... Here everything is alright, class was covered by a test and it works fine if I run something like
System.schedule('SyncCompletedMeetings', '0 0 * * * ? *',  new SyncCompletedMeetings());
in the developer console.
The problem is - I want to add the job to schedule only when user login thru custom AuthProvider PrezentorCognito (extension of AuthProviderPluginClass). My expectation is adding similar code somewhere at the end of getUserInfo method will create new job in scheduled jobs but unfortunately, everything goes wrong. Code:
global Auth.UserData getUserInfo(Map<String, String> authProviderConfiguration, Auth.AuthProviderTokenResponse response) {
        ...
        String userId = UserInfo.getUserId();
        System.debug('UserInfo ' + userId);
        String jobId = System.schedule('SyncCompletedMeetings', '0 33 * * * ? *',  new SyncCompletedMeetings());
        System.debug('jobId ' + jobId );
        System.debug('Jobs have been added to scheduler');
        return new Auth.UserData(
          ...
        );
    }

does not raise any errors, shows all debug messages with ids but does not create job(I don't see job in scheduled jobs and even in developer console query editor return 0 for query SELECT Id, TimesTriggered, NextFireTime FROM CronTrigger WHERE Id = 'job Id' )

Please help me to understand what I'm doing wrong if you have any ideas.
Hi,
We have extended AuthProviderPluginClass for Amazon Cognito and now I'm fighting the issue when cognito returns an error 'Already found an entry for username...' (the situation is standard for linking of existing cognito account with the third party accounts). Next request to authentication should be successfull so I need to catch this error somewhere in handleCallback and restart the flow. Unfortunately, I don't see how to do this. All my tries to call initiate method and stop current flow are unsuccessful because system expects that handleCallback will return Auth.AuthProviderTokenResponse or raise an error. 
Does somebody face a similar issue?  I really need help.
Thanks