?
Solved

how to extract an objectID from a PageReference?

Posted on 2013-06-01
5
Medium Priority
?
275 Views
Last Modified: 2016-02-17
I'm using a standard Controller's save action (called by sc.save()) to save a new record.  It returns a PageReference called OrderPage.  When I look at the returned PageReference in the debugger, it is the ID of the saved record preceded by a '/'.  I need to assign the id (without the '/' ) to a variable for further processing.  The page hasn't loaded, and in any event OrderPage.getParameters().get('id) doesn't work nor does (getting desperate here) OrderPage.valueOf() or various attempts at using string functions to extract it.
 
Can anyone tell me how to do this?  It seems like it would be a common use case, but a lot of searching both here and on the Internet has been unsuccessful.
 
I appreciate any help anyone can offer.
0
Comment
Question by:kathytb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:ChloesDad
ID: 39213462
Here are examples of how to split a string. You should be able to remove the '/' and then use the rest.

http://boards.developerforce.com/t5/Apex-Code-Development/String-split-method-works-only-some-of-the-time/td-p/185684
0
 

Author Comment

by:kathytb
ID: 39213561
Thanks for your suggestion -- that was one of the things I had tried.  The problem is that save() returns a PageReference object (array, I think) and I haven't found a way to extract the ID so I can work with it as a string.  I really appreciate your willingness to help.
0
 
LVL 15

Expert Comment

by:ChloesDad
ID: 39213582
To refer to an item in an array you use [ ] notation, so if you array is called myArray then myArray[0] will be the first element (if its zero based)
0
 

Accepted Solution

by:
kathytb earned 0 total points
ID: 39214415
I was barking up the wrong tree entirely, I'm afraid.  It turns out I needed to call getId() on the controller, not anything on the PageReference.  I really appreciate your suggestions -- thank you for helping me out.
0
 

Author Closing Comment

by:kathytb
ID: 39228393
I was approaching the problem from the wrong angle.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Salesforce.com is a cloud-based customer relationship management (CRM) system. In this article, you will learn how to add and map custom lead and contact fields to your Salesforce instance.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question