Solved

how to extract an objectID from a PageReference?

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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 …
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

706 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

18 Experts available now in Live!

Get 1:1 Help Now