My visual force page requests 5 inputs. WeatherController then posts those inputs to Chatter and also creates a record from the information. What I'm not understanding is how to "grab" the URL of the newly created record so that I can publish it as a link in Chatter along with the other 5 inputs. How do I automatically grab the url of a newly created record in Apex?

VisualForce APEX

1 Answer 1


You have two insert statement into your code

 insert WT;
 insert fItem;

You can get both record id by

     WT.id and fItem.id

and you can build url for both item in following way before return null statement

    String WTUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/'+WT.Id;
    String fItem = URL.getSalesforceBaseUrl().toExternalForm()+'/'+fItem.Id;
  • It Worked! You da best! Thank you! Your answer also helped me realize that I needed to rearrange some of the statements.
    – Rocket_Izz
    Commented Nov 3, 2015 at 21:15
  • please upvote and mark this as answer :)
    – Himanshu
    Commented Nov 3, 2015 at 21:16
  • Done and done..
    – Rocket_Izz
    Commented Nov 3, 2015 at 21:21

You must log in to answer this question.

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