3

I have a VF page that I use for both classic and lightning. In this page, there is a button to create a new account. For classic, it just redirects the page to this url:

/001/e?setup/ui/recordtypeselect.jsp?ent=Account

For lightning, this takes the user to the account create page, but it skips the record type selection. So it tries to create an account with no record type, and it errors out.

Any thoughts on how I can create a link to the new account page with a record type picker (if needed) that would work for both classic and lightning?

Thanks

update: if it helps, here's a quick snippet of code. the button itself is just a SLDS styled button

<button class="slds-button slds-button--neutral" onclick="gotoNewAccountPage()">
    <svg class="slds-button__icon slds-button__icon--left" aria-hidden="true">
        <use xlink:href="{!URLFOR($Asset.SLDS, '/assets/icons/utility-sprite/svg/symbols.svg#new')}" />
    </svg>
    New Account
</button>

then it does this on click

function navigateToUrl(url){
    if(isLightningDesktop()){                   
        sforce.one.navigateToURL(url, true);
        // sforce.one.createRecord("Account", "012***************")
    }else{
        window.location.href = url;
    }
}

function gotoNewAccountPage(){
    navigateToUrl("/001/e?setup/ui/recordtypeselect.jsp?ent=Account");
}

as you guys can see commented out on the navigateToUrl method, the createRecord would work well if I had a record type id. but in this case, I do not since the user has to pick something first

6
  • For Lightning in VF pages, this is a good link to start: developer.salesforce.com/docs/atlas.en-us.lightning.meta/… If you have existing code, it would be nice to see it.
    – akcorp2003
    Commented Mar 28, 2017 at 16:03
  • 1
    Have you tried using JavaScript for this? On Lightning you have access to the sforce.one object, which gives you some methods to navigate within the platform. One of them is createRecord that can receive the developer name of the object to create and its record type. The record type is optional, so I believe the platform should prompt you with the record type selection page. Take a look at the docs (developer.salesforce.com/docs/atlas.en-us.salesforce1.meta/…). Commented Mar 28, 2017 at 16:03
  • @akcorp2003 - I was reading about using $A.createRecord in a lightning component, but I will still need to supply the recordtype id manually. my problem so far is I do not have the recordtype id to send, since the user will need to pick one
    – John
    Commented Mar 28, 2017 at 16:50
  • 1
    @RenatoOliveira - yes I was looking into that as well, problem is I do not have the recordtype to pass, since this one profile I'm using has access to 3 record types for the account. what I'm thinking I will do is just load the list of record types via Apex, then create a custom picker so I can grab a value to pass to createRecord
    – John
    Commented Mar 28, 2017 at 16:53
  • But what happens if you don't provide the record type id? Commented Mar 28, 2017 at 22:23

0

You must log in to answer this question.

Browse other questions tagged .