Solved

how to extract an objectID from a PageReference?

Posted on 2013-06-01
5
257 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
countEvens challenge 2 78
java continue statement 10 118
mapAB Challlenge 35 128
Problem to start Neon 20 89
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This video teaches viewers about errors in exception handling.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

864 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now