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
Austin Davis 8Austin Davis 8 

How do I get the record Id of a record from an embedded visualforce page?

I have a VisualForce page that I have embedded into the account object, and I am trying to get the account's record id into the controller. I need the account id to make a new record.

Here's what I have so far:
private Account acct;
    public ChatterBoxNote__c newNote = new ChatterBoxNote__c();
    public ChatterBoxNote__c getNewNote(){
    
    return newNote;
}
public String Record_ID { get; set; }
public Id posID { get; set; }

public genericController(ApexPages.StandardController controller) {
    acct= (Account)controller.getRecord();
    posID = acct.Id;
}

public PageReference createNewNote(){
        System.Debug('PosID: ' + posID);
        newNote.Record_ID__c = (String)posID;

        //insert newNote;
        return null;
}

 
Austin Davis 8Austin Davis 8
Alright, so after much fiddling around with different ways of doing this, I finally figured out a simple and effective solution:
 
acct= [ SELECT Id, Name, Site FROM Account WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    posID = acct.get(0).Id;

I hope this will help anyone else that had this problem. Note that this can be used for any object standard or custom.