+ Start a Discussion
fredkafredka 

Assign Account ID using URL

I have a custom object that is using record types.  I am also using the Account Tabbed view.

 

In order to show one record type per tab on my account, I created a custom controller and used that to create my lists.  I am trying to add a new button to each tab so users can create new records.

 

I am having a problem getting the account ID into the custom object.  When I use the following, it assigns the accounts ID to the name field on the custom object.  Trying to figure out how I correctly assign the account to the custom object.

 

Any help would be greatly appreciated!!! Thanks!!!!

 

 

 public PageReference NewEnrollHealth() {
    Id Aid = ApexPages.currentPage().getParameters().get('id');
    PageReference pageRef = new PageReference('https://cs3.salesforce.com/a01/e?CF00N700000021Lm4='+Aid+'&CF00N700000021Lm4_lkid=001Q000000EAALT');
   
            return PageRef;
      }

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Jeremy_nJeremy_n

If you're specifying a lookup field value in the URL, you have to specify two things: the Name of the looked up object, and the Id. But you're just specifying the Id (lkid = lookup Id, which you have hardcoded right now, and I don't think that's what you meant.

 

You're also filling in the Aid, which is the actual ID, into the name part of the field, and this is your problem. You need to get the actual Name of the Account if you're going to specify it in advance.

 

 

public PageReference NewEnrollHealth() {
    Id Aid = ApexPages.currentPage().getParameters().get('id');
    String AName = [select Name from Account where id = :Aid].Name; PageReference pageRef = new PageReference('https://cs3.salesforce.com/a01/e?CF00N700000021Lm4='+AName+'&CF00N700000021Lm4_lkid=' + Aid); return PageRef; }

 See how that works for you.

Good luck!

 

 

Jeremy

 

 

All Answers

Jeremy_nJeremy_n

If you're specifying a lookup field value in the URL, you have to specify two things: the Name of the looked up object, and the Id. But you're just specifying the Id (lkid = lookup Id, which you have hardcoded right now, and I don't think that's what you meant.

 

You're also filling in the Aid, which is the actual ID, into the name part of the field, and this is your problem. You need to get the actual Name of the Account if you're going to specify it in advance.

 

 

public PageReference NewEnrollHealth() {
    Id Aid = ApexPages.currentPage().getParameters().get('id');
    String AName = [select Name from Account where id = :Aid].Name; PageReference pageRef = new PageReference('https://cs3.salesforce.com/a01/e?CF00N700000021Lm4='+AName+'&CF00N700000021Lm4_lkid=' + Aid); return PageRef; }

 See how that works for you.

Good luck!

 

 

Jeremy

 

 

This was selected as the best answer
fredkafredka

Jeremy, that is exactly what I needed!!! Thank you for taking the time to help me, I appreciate it!!!!!!

 

Fred