+ Start a Discussion
TechMightyTechMighty 

How to capture record id for the record on any custom button click?

Hi, I am using standard detail page for detailed view of Order and its line items are listed in related list. In the related list of Line items, i can see standard Edit and Del Links against each record. I want to override Edit link to navigate to a new custom made detail page which will detail about the Line Item record for which the link was clicked. How can I retrieve the record Id of line item whos Edit link was clicked. Thanks, TechMighty
Best Answer chosen by Admin (Salesforce Developers) 
wt35wt35

Have you checked if the id was passed as an URL parameter when clicking on Edit?
Also is your page a Visualforce page?

 

 

If both answers are yes, then you could easily retrieve it with
ApexPages.currentPage().getParameters()

 

The following example shows how to use a PageReference object to retrieve a query string parameter in the current page URL. In this example, thegetAccountmethod references theidquery string parameter:

 
public class MyController {
   public Account getAccount() {
        return [SELECT Id, Name FROM Account
                WHERE Id = :ApexPages.currentPage().getParameters().get('Id')];
    }
}

The following page markup calls thegetAccountmethod from the controller above:

 
<apex:page controller="MyController">
    <apex:pageBlock title="Retrieving Query String Parameters">
        You are viewing the {!account.name} account.
    </apex:pageBlock>
</apex:page>

 

All Answers

wt35wt35

Have you checked if the id was passed as an URL parameter when clicking on Edit?
Also is your page a Visualforce page?

 

 

If both answers are yes, then you could easily retrieve it with
ApexPages.currentPage().getParameters()

 

The following example shows how to use a PageReference object to retrieve a query string parameter in the current page URL. In this example, thegetAccountmethod references theidquery string parameter:

 
public class MyController {
   public Account getAccount() {
        return [SELECT Id, Name FROM Account
                WHERE Id = :ApexPages.currentPage().getParameters().get('Id')];
    }
}

The following page markup calls thegetAccountmethod from the controller above:

 
<apex:page controller="MyController">
    <apex:pageBlock title="Retrieving Query String Parameters">
        You are viewing the {!account.name} account.
    </apex:pageBlock>
</apex:page>

 

This was selected as the best answer
TechMightyTechMighty

Thanks very much...this solved my problem. :)