4

I have a requirement to provide a link to an external system, which will link to an Account in Salesforce. The external system doesn't store the AccountId, but uses an externalId (UUID). The UUID__c field exists (and is unique) on Account I'll be linking to.

So obviously, if the Account Id was held in the external system, we could just construct a link like this:

https://eu1.lightning.force.com/lightning/r/Account/<AccountId>/view

Then after authentication, the user would just be taken to the relevant account page in Lightning.

HOWEVER. As previously mentioned, our external system doesn't store the AccountId. The account identifier it does store is called UUID, which is also in Salesforce, on the Account.UUID__c field, which is a unique external ID field.

To solve this in classic, I would create a visualforce page, and get the external system to construct the following link:

https://eu1.salesforce.com/apex/myPage?uuid=<externalSystemUUID>

Then I'd get the controller for the visualforce page to extract the externalSystemUUID parameter, and query the account using the UUID:

account acc = [select id from account where UUID__c =:externalSystemUUID]

Then I'd get the visualforce page to automatically redirect to the native lightning page.

However, the requirement is to do this in Lightning and I'm not entirely sure what best practice is around this - should I be using a Lightning Component or can I still use a Visualforce page?

Any guidance gratefully received.

2
  • 1
    Just trying to understand - why would you need a VF page or LC here? As long as your External System has the URL for the record, they can directly navigate to it with authentication. What's your exact requirement here?
    – Jayant Das
    Oct 5, 2018 at 15:47
  • So, the problem is that the external system doesn't hold the actual record id of the account they want to link to - only a unique external id that's also held in Salesforce. I'll edit my original question to clarify. Oct 8, 2018 at 8:56

2 Answers 2

4

In lightning you can use "lightning:isUrlAddressable" interface with "force:navigateToURL" to redirect to account page on init with 3 steps.

  1. You pass uuid in url
  2. You query and find account id on init
  3. Navigate to account

Link format will be like: https://yourdomain.lightning.force.com/lightning/cmp/c__GetAccountFromUUID?uuid=UUID_HERE

Component:

<aura:component implements="flexipage:availableForAllPageTypes,lightning:isUrlAddressable" controller="GetAccountFromUUIDController">
   <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
        {!v.pageReference.state.uuid}
</aura:component>

Controller:

({
    doInit: function(component, event, helper) {
        var uuid = component.get("v.pageReference").state.uuid;
        console.log("action");
        var action = component.get("c.getAccountId");
        console.log(action);
        action.setParams({ 
            "uuid": uuid
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var accId = response.getReturnValue();
                console.log("success");
                var urlEvent = $A.get("e.force:navigateToURL");
                urlEvent.setParams({
                    "url": "/lightning/r/Account/"+accId+"/view"
                });
                urlEvent.fire();
            }
            else if (state = "ERROR")
            {
                console.log("Failed");
                alert("no account found");
            }
        });
        $A.enqueueAction(action);
    }
})

Apex Controller:

public class GetAccountFromUUIDController {
    @AuraEnabled
    public static String getAccountId(String uuid){
        return String.valueOf([select id from account where uuid__c=:uuid].Id);
    }
}

You can find "lightning:isUrlAddressable" doc here: https://developer.salesforce.com/docs/component-library/bundle/lightning:isUrlAddressable

3
0

Did you try considering formula field solution. This way you can reduce lot of effort.

1
  • A formula field would work fine if I was linking from Salesforce TO the external system, but in this instance it's the other way around. A formula field will not cut it for this requirement. Oct 8, 2018 at 9:15

You must log in to answer this question.

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