cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Action URL to Open Record in Salesforce

Highlighted
Roast Chef
Roast Chef

Custom Action URL to Open Record in Salesforce

Jump to solution

Hi All,

I have a question in regards to SFM Custom Actions, I will give some background to the requirements for this request below.

We are currently in the process of deploying the ability for payment in the field to our field service teams. We have installed an app called Chargnet into our developer org and set up the integration piece between the app and our merchant gateway. This allows us to capture credit card payment on completion of a work order, one small issue exists though.

We are able to create the Chargnet order from the service call via a custom SFM transaction and include all the required mappings, but once the record is created we need the technician to then navigate to the record that has been created in Salesforce. The reason for this is that the Salesforce environment is PCI compliant and it authorized to process credit card details. The app cannot do this as the data is stored on the device until a sync has been completed. 

Does anyone have a way of once the Chargnet record is created then having a custom action with a URL to the newly created record within Salesforce that the technician can click on to navigate directly to this record?

Thanks,

Brenden

1 Solution

Accepted Solutions
Pastry Chef
Pastry Chef

Re: Custom Action URL to Open Record in Salesforce

Jump to solution

Hi Brendan, we have a use case where we need to open a record in the browser from the mobile app and had to write a small visualforce page and controller to achieve this. Below is the code:

VF Page: SVMXRedirectPage

<apex:page controller="SVMXGenericRedirectController" action="{!validateAndRedirect}">

  <apex:pageMessages ></apex:pageMessages>

</apex:page>

Apex Controller: SVMXGenericRedirectController

public class SVMXGenericRedirectController {

    public Id objId {get; set;}

   

    public PageReference validateAndRedirect(){

       

        if (ApexPages.currentPage().getParameters().get('objId') != null && ApexPages.currentPage().getParameters().get('objId') != '') {

            objId = ApexPages.currentPage().getParameters().get('objId');

           

            PageReference retURL = new PageReference('/' + objId);

            retURL.setRedirect(true);

            return retURL;

        } else {

            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.WARNING, Label.SVMXMissingId));

        }

       

        return null;

    }

   

}

Apex Controller Test Class: SVMXGenericRedirectControllerTest

@isTest

public class SVMXGenericRedirectControllerTest {

    public testmethod static void SVMXGenericRedirectControllerTest() {

        

        Test.StartTest();

       

        PageReference pageRef = Page.SVMXRedirectPage;

        pageRef.getParameters().put('objId', 'a3R6C0000000FHF');

        Test.setCurrentPage(pageRef);

       

        SVMXGenericRedirectController svmxController = new SVMXGenericRedirectController();

        svmxController.validateAndRedirect();

       

        Test.StopTest(); 

         

    } 

   

    public testmethod static void SVMXGenericRedirectControllerWithoutParamsTest() {

        

        Test.StartTest();

       

        PageReference pageRef = Page.SVMXRedirectPage;

        Test.setCurrentPage(pageRef);

       

        SVMXGenericRedirectController svmxController = new SVMXGenericRedirectController();

        svmxController.validateAndRedirect();

       

        Test.StopTest(); 

         

    } 

   

}

If you pass in the record ID as parameter "objId", the custom action should launch this record in the default browser.

You will also need to create a custom label called: "SVMXMissingId" which contains an error message if the page is called but is missing the objId

An example of the Custom Action setup is like this:

Full URL to launch is this: https://na37.salesforce.com/apex/SVMXRedirectPage

You will obviously need to change this to be your instance name, e.g. na37 or na12 etc.

You will also need to give the SF Profiles that will use this access to the VF Page: SVMXRedirectPage, but no need to add the controller too. It works without this.

Hope that helps!

View solution in original post

Pastry Chef
Pastry Chef

Re: Custom Action URL to Open Record in Salesforce

Jump to solution

Hi Brendan, we have a use case where we need to open a record in the browser from the mobile app and had to write a small visualforce page and controller to achieve this. Below is the code:

VF Page: SVMXRedirectPage

<apex:page controller="SVMXGenericRedirectController" action="{!validateAndRedirect}">

  <apex:pageMessages ></apex:pageMessages>

</apex:page>

Apex Controller: SVMXGenericRedirectController

public class SVMXGenericRedirectController {

    public Id objId {get; set;}

   

    public PageReference validateAndRedirect(){

       

        if (ApexPages.currentPage().getParameters().get('objId') != null && ApexPages.currentPage().getParameters().get('objId') != '') {

            objId = ApexPages.currentPage().getParameters().get('objId');

           

            PageReference retURL = new PageReference('/' + objId);

            retURL.setRedirect(true);

            return retURL;

        } else {

            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.WARNING, Label.SVMXMissingId));

        }

       

        return null;

    }

   

}

Apex Controller Test Class: SVMXGenericRedirectControllerTest

@isTest

public class SVMXGenericRedirectControllerTest {

    public testmethod static void SVMXGenericRedirectControllerTest() {

        

        Test.StartTest();

       

        PageReference pageRef = Page.SVMXRedirectPage;

        pageRef.getParameters().put('objId', 'a3R6C0000000FHF');

        Test.setCurrentPage(pageRef);

       

        SVMXGenericRedirectController svmxController = new SVMXGenericRedirectController();

        svmxController.validateAndRedirect();

       

        Test.StopTest(); 

         

    } 

   

    public testmethod static void SVMXGenericRedirectControllerWithoutParamsTest() {

        

        Test.StartTest();

       

        PageReference pageRef = Page.SVMXRedirectPage;

        Test.setCurrentPage(pageRef);

       

        SVMXGenericRedirectController svmxController = new SVMXGenericRedirectController();

        svmxController.validateAndRedirect();

       

        Test.StopTest(); 

         

    } 

   

}

If you pass in the record ID as parameter "objId", the custom action should launch this record in the default browser.

You will also need to create a custom label called: "SVMXMissingId" which contains an error message if the page is called but is missing the objId

An example of the Custom Action setup is like this:

Full URL to launch is this: https://na37.salesforce.com/apex/SVMXRedirectPage

You will obviously need to change this to be your instance name, e.g. na37 or na12 etc.

You will also need to give the SF Profiles that will use this access to the VF Page: SVMXRedirectPage, but no need to add the controller too. It works without this.

Hope that helps!

View solution in original post

Roast Chef
Roast Chef

Re: Custom Action URL to Open Record in Salesforce

Jump to solution

Adam Cooper this is exactly what I am after, thank you for taking the time to respond and sharing your code with me, absolute legend.

Pastry Chef
Pastry Chef

Re: Custom Action URL to Open Record in Salesforce

Jump to solution

No problem! Would be great if ServiceMax could implement this as part of custom actions so we didn't need custom code to achieve it.

Roast Chef
Roast Chef

Re: Custom Action URL to Open Record in Salesforce

Jump to solution

It would make this a lot easier to manage if this was provided as standard functionality, once again thanks, Adam Cooper