Solved

how to extract an objectID from a PageReference?

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Note: You must have administrative privileges in order to configure lead or case queues. Salesforce.com (http://www.Salesforce.com) is a cloud-based customer relationship management (CRM) system. It is widely used around the world by sales and ma…
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 tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

707 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