4

I am working on an app and in one of the triggers there is this exotic bird:

if( UserInfo.getUserId().indexOf('pnet') != -1 ) {
    return;
}

Looks terribly hard coded or is there a general rule that users with a certain role / profile / superpowers have this sequence in their Id's?

  • It appears to have to do something with Salesforce-to-Salesforce, as you can find pnet referenced but unexplained in this documentation. – Phil Rymek Sep 13 '13 at 13:38
5

This code couldn't be correct. The Tips for Using Salesforce to Salesforce document that Phil R linked in the original question comments refers to pnet being embedded in the alias, while this code checks the User.Id field for those characters, which has an incredibly low probability of appearing.

Either it's meant to work in a single organization where a user happens to have some combination of pnet, which would be sensitive to the exact organization this code was written in, or they meant to try and check User.Alias so they could detect Salesforce to Salesforce connection updates, which is the more likely scenario. I'd consider changing the code to:

User currentUser = [select id, alias from user where id = :userinfo.getuserid()];
if(currentUser.Id.indexOf('pnet') != -1 || currentUser.Alias.indexOf('pnet') != -1) {

This supports the current (possibly incorrect) logic as well as what the author probably meant to begin with-- detecting Salesforce to Salesforce connections.

Given that the documentation suggests that the user alias will contain pnet, it's safe to assume that a Salesforce to Salesforce user-- a proxy user created by the system to represent updates from the connected system-- will always contains this string in its alias.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.