1

As the user goes into an account, there is a custom button that they can click that will redirect them to my Visualforce page. How can I capture that account id in my controller?

Thanks

public myControllerCBR(){
    breachRecord = new List<wrapperClass>();

    AccountTeamMember uId = [SELECT UserId FROM AccountTeamMember WHERE AccountId =:ApexPages.CurrentPage().GetParameters().Get('id') and TeamMemberRole = 'Sales Engineer' limit 1];

    List<User> uName = [SELECT Name, Manager__c, MANAGERID, Email, MOBILEPHONE FROM User WHERE Id =:uId.UserId limit 1];


    for(User rept : uName){
        breachRecord.add(new wrapperClass(rept));
    }

}

See button setup: http://www.evernote.com/shard/s197/sh/b7efd476-905f-4660-b281-2b71e6755318/1f05fbd47a9d9ebf227649e2e70c4c10

1

When you create the button you could the following in the formula editor:

/apex/YourVisualForcePage?acctId={!RelantionshipName__c}

Depending on if you use a standard controller, extension or custom controller you will then have different options

If you are using a custom controller you need to perform a SOQL query on the id in the controller's constructor.

Getting the id is easy, you match the key of the parameter in the query string like so:

ApexPages.CurrentPage().GetParameters().Get('acctId')
  • Hi Mihai, I've a custom controller. I've added "ApexPages.CurrentPage().GetParameters().Get('id')" to my query but keep getting error "System.QueryException: List has no rows for assignment to SObject " – user7123 Jul 31 '15 at 10:33
  • When adding "/apex/YourVisualForcePage?id={!Account.Id}" to my button and clicking on it will give me an error "unexpected token Illegal". – user7123 Jul 31 '15 at 10:37
  • ok, so what you need to set in the url of the custom url is the specific name of the relationship you have between your object and the account object. I will also update the query string. – Mihai Neagoe Jul 31 '15 at 12:36
2

You need to add account Id in the url of your custom buttom.. for example:

?accid={!AccountId}&retURL=..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.