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:


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?


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')}" />
    New Account

then it does this on click

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

function gotoNewAccountPage(){

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

  • 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 Mar 28 '17 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/…). – Renato Oliveira Mar 28 '17 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 Mar 28 '17 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 Mar 28 '17 at 16:53
  • But what happens if you don't provide the record type id? – Renato Oliveira Mar 28 '17 at 22:23

Your Answer

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

Browse other questions tagged or ask your own question.