function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lapaullapaul 

how to capture the selected record for editing

HI,

I'm writing a custom edit page to edit a current record. Basically I created a custom edit button to

replace the standard button. When a user click on the edit button of any record, how do you capture

the selected record? I don't know how to capture the current record for editing. I got a null result

from the following SOQL statement. Any help with sample codes would be appreciated. thanks

 

Paul

 

Time_Tracking__c ed = [SELECT OwnerId, Project__c, Status__c, Date__c, Department__c, Start_Time__c, Stop_Time__c, Time_Code__c from Time_Tracking__c WHERE id =: ApexPages.currentPage().getParameters().get('id')];

mike1983mike1983

First you want to make sure that while you are testing it you are actually doing so with an ID of the object you are querying.... Meaning if your Visual force page/controler is for a different object then the ID in the URL isnt the one you care about.  So your test page would be something like https://cs3.salesforce.com/apex/yyyy?id=xxx

Where yyy is your visual force page name and xxx is a valid ID of your time tracking custom object

 

Use this variable  above your select statement

private final string LiveID = ApexPages.currentPage().getParameters().get('id');

 Then replace

 ApexPages.currentPage().getParameters().get('id')

 

with LiveID

 

 

 

 

 

 

 

 

 

 

lapaullapaul

Thanks for the reply.

I did what you suggested but I got the following error message. Any idea?

 

System.QueryException: List has no rows for assignment to SObject

 

Class.timetracker.edit_action: line 162, column 28 External entry point

 

 

here's my code.

 

public PageReference edit_action()

{

String LiveID = ApexPages.currentPage().getParameters().get('id');

 

Time_Tracking__c ed = [SELECT OwnerId, Project__c, Status__c, Date__c, Department__c, Start_Time__c, Stop_Time__c, Time_Code__c from Time_Tracking__c WHERE id =: LiveID];

 

timetr.OwnerId = ed.OwnerId;

timetr.Project__c = ed.Project__c;

timetr.Status__c = ed.Status__c;

timetr.Date__c = ed.Date__c;

timetr.Department__c = ed.Department__c;

timetr.Start_Time__c = ed.Start_Time__c;

timetr.Stop_Time__c = ed.Stop_Time__c;

timetr.Time_Code__c = ed.Time_Code__c;

 

PageReference pg = Page.TimeTrackEditPage;

pg.setRedirect(true);

 

return pg;

 

}

 

 

ThomasTTThomasTT

Did you check what is set to LiveID? and the ID is what you expect?

 

That would tell us whether the query is wrong or the parameter is wrong, don't you think so?

 

ThomasTT

ThomasTTThomasTT

And, try to open one of your existing Account or Opportunity or whatever SFDC standards, and click Edit button. In the edit screen, look at the URL. It looks like

 

https://na6.salesforce.com/00Q8000000MResz/e?retURL=%2F00Q8000000MResz

 

There is no parameter "id". So you can't get the record id from URL parameter "id". But, don't try to get the parameter from "retURL". THere should be the right way to do it, because it is very basic function.

 

ThomasTT

ThomasTTThomasTT

 I found an example in Visualforce Developer's Guide (Salesforce Summer '09) at page 59.

public class myControllerExtension {
private final Account acct;
// The extension constructor initializes the private member
// variable acct by using the getRecord method from the standard
// controller.
public myControllerExtension(ApexPages.StandardController stdController) {
this.acct = (Account)stdController.getRecord();
}
public String getGreeting() {
return 'Hello ' + acct.name + ' (' + acct.id + ')';
}
}

You said you created a custom Edit page. If you were using Custom Controller, you would be getting the record id
already somehow so you wouldn't be supposed to post the question.

So it means it is Standard Controller Extension, so you are supposed to use StandardController.getRecord() or getSubject() to get the object, and get the id from the object.

 

ThomasTT