0

I have a custom code that I am inserting a Account and open the Standard Account screen as Edit. I would like after the Save button pressed, go to the Standard Account view screen.

So, I am using RetURL for this adding the AccountID on that. It is working fine for internal user.

On the other hand, it does not work for Partner users. I know that if I added the Partner Community Name in the RetURL, it will work fine.

it is the code that is working fine for internal users:

       Map<String,String> parameters = new Map<String,String>{
      'objectName' => 'Account',
      'recordId' => NewAccount.ID,
      'retUrl' => NewAccount.ID
    };      



   PageReference redirectPage = new ApexPages.StandardController(NewAccount).Edit();
   redirectPage.getParameters().putAll(parameters);  
   redirectPage.setRedirect(True);
   return redirectPage; 

And here, the code that works fine for Partner Community. However, I do not want to hard code the Partner Community Name.

       Map<String,String> parameters = new Map<String,String>{
      'objectName' => 'Account',
      'recordId' => NewAccount.ID,
      'retUrl' => 'Partner/' + NewAccount.ID
    };      



   PageReference redirectPage = new ApexPages.StandardController(NewAccount).Edit();
   redirectPage.getParameters().putAll(parameters);  
   redirectPage.setRedirect(True);
   return redirectPage; 

So, how could I discover the Partner Community name. Or is there another way to use RetURL?

2 Answers 2

1

I'm a little late on this, but to detect whether the user is a partner or an internal one you can use the Network class.

There's a method called getNetworkId, which will return the user's current community Id if it is a partner. If it is an internal user, it will return null.

If you need the exact base URL, you can have a method like below to retrieve the path prefix, and simply build the URL yourself.

public static String getPathPrefix () {
    Id net_id = Network.getNetworkId();
    if (net_id  != null) {
        return [SELECT Id, UrlPathPrefix
                FROM Network
                WHERE Id = :net_id].UrlPathPrefix;
    }
    return '';
}
3
  • this solution looks better then I found. I will test! Thx a lot.
    – m Peixoto
    Commented Aug 25, 2017 at 12:08
  • 1
    It works very well. I will send you a 'pão de queijo'
    – m Peixoto
    Commented Aug 25, 2017 at 13:04
  • Haha, thank you :) glad to help, as I've been there myself (working with communities). Commented Aug 25, 2017 at 13:57
0

I solved this issue testing If it is a Partner user and using the code below:

URL = ApexPages.currentPage().getHeaders().get('referer'); //Get the complete URL
URL = URL.Replace(System.URL.getSalesforceBaseURL().toExternalForm(), ''); //Taking out the Instance URL
URL = URL.mid(1, URL.length()-1); //take out the First /
URL = URL.mid(0, URL.indexOf('/')); //take out the next /

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .