These sort of errors are tough, but you have some options.
1. Contact support and get the GACK details
If you email support the details of the internal server they can look it up on there back-end and find a stack trace. In many cases the stack trace may give a much clearer picture of what the error is and allow you to work around it.
2. Binary Search plus Trial and Error Workarounds
Use a binary search algorithm to identify the specific line of code leading to the error. In other words, comment out one half of the code, if the error still occurs, comment out the other. Keep reducing the amount commented out until you end up with a single line.
If you get to this point try and put yourself in the mind of the developers who built the underlying Salesforce functionality. What sort of things might be tricky to implement? What sort of things could lead to errors if not handled properly? Use trial and error to see if you can alter anything about the code to get the error to go away while still accomplishing your goal. Hack it to pieces, whatever it takes to work around the error and get back to working on new features.
3. Contact support and get their help
If your issues is consistently reproducible you can contact support and have them do the troubleshooting. This is not fun. Support is much better at handling user issues than platform bugs. It can take a very, very long time to even get support to understand the error, let alone believe it's something that's broken. Many a time I find a bug, work through endless emails, calls, and goto meetings only for them to tell me it's a known issue (that's not on the known issues list), and they won't fix it for fear that fixing the bug might break someone else's code (aka the "Bug as a Feature Response").
That said, if you stick with it, you'll get to the real support guys (Tier 3 and R&D) who are very skilled and can assist in fixing the issue. Provided of course, you don't mind waiting 3 months to a year for a patch to go out. And at the end of event, you'll get the satisfaction you made Salesforce just a little bit better.
Once you are authenticated you don't need to re-authenticate with external service again.
Every external system provide refresh token with access token
and using that refresh token
you need to refresh the access token.
You can use batch which will run in backend and refresh your access token. Schedule this batch to run in 7 hours.
To refresh the access token
using refresh token
you can follow these links.
- OAuth 2.0 Refresh Token Flow
Although this is link for SF token but the basic idea will remain same here.
Sample code.
POST /services/oauth2/token HTTP/1.1
Host: https://login.salesforce.com/
grant_type=refresh_token&client_id=Your client id here&client_secret=Your client secert here
&refresh_token=your token here
For the second point where you need to re-authentication you can do one thing. Create a checkbox and if checkbox is true then update record type with a button for re-authentication and once user click on this button and re-authenticate you can again change the pagelayout
and hide the button.
In your batch if you get time 0 then update the record with checkbox true.so user can see the button for re-authenticate.
And as you are system admin so you need to store their access token and refresh token in some place and your code can access it from there.
Best Answer
It seems that now SonarQube provides support for Apex by default since version 7.5
https://docs.sonarqube.org/display/PLUG/SonarApex