Prepopulate Account Name in Custom New Contact Page

Ok so, when you’re on an account page and you click “Add Contact,” on the new Contact form it should auto populate the the Account field with the name of the account. This normally goes through URL parameter, I think, but if your New Contact page is a Skuid page, the override takes over the url parameter… so how do you do the “New Contact” redirect so that the new contact will be automatically associated with the Account?

1. Add a “New Contact” Global Action to the Contacts table on your Account’s detail page. This should be a “Redirect” action whose URL takes you to the New Contact page, and passes in the Id of the current Account. Usually you can get this Id from your page’s URL parameters, but you could also get it from a model merge: URL (easiest way — use URL Parameter to get Account Id):

/{{Model.KeyPrefix}}/e?retURL=%2F{{$Param.id}}&accid={{$Param.id}}

URL (more complex — use global model merge to get Account Id):

/{{Model.KeyPrefix}}/e?retURL=%2F{{#$Model.AccountData.data}}{{Id}}{{/$Model.AccountData.data}}&accid={{#$Model.AccountData.data}}{{Id}}{{/$Model.AccountData.data}}

2. Create a custom Skuid page to use as the “NewContact” page This page should expect to be handed an “accid” URL parameter, and it should use this in an “Account” model. You should then have a “Contact” model which has a Model Merge condition to autopopulate the “AccountId” field using the Account model: (2a) Create an Account Model. -Fields: Id, Name -Conditions: Id = (param) accid (2b) Create a Contact Model -Fields: all the fields you want the user to edit when creating a new Contact -Conditions: AccountId = (Account)(Id) 3. Tada! The AccountId field will be prepopulated on your NewContact page, and it will display as the Account’s Name:

Thanks so much! I think the Id=accId thing was where I was tripping up.

I think that the trickiest part of all of this is having to create the Account Model in order to get the related Account’s Name — otherwise the “Account” field will show up as the Account’s Id, e.g. “00100000004499AAA”. The other way to do it would be to pass an additional URL parameter, accName={{Name}} — this isn’t as reliable or powerful, though, so I wouldn’t recommend it. Going the separate-model route allows you to do some crazy stuff, such as using a custom display template, so when you create your new Contact record, the “Account” field could be populated with additional fields, e.g. instead of just seeing an account called “School of Finance”, you could see its Parent Account as well, e.g. “School of Finance (Parent: University of Arizona)”.

Hi. I’m new to Skuid and REALLY appreciate this post by Zach. I tried it in two places and it worked. Now, a new question. If I have an Opportunity Detail page that includes a Quote table and the action to create a new quote, how do I pass along both the Opportunity Name/ID AND the Account ID so that the new Quote has both? The Opportunity detail page has both so I’d like both to be passed on to ensure the creator of the record won’t leave it out or put in the wrong account. Any help you can provide here would be really appreciated! Thanks, Matt Boyer

The quick answer here is that you can pass as many URL parameters from the Opportunity detail page to the new Quote page as you want. 

A little more detail: 
Make sure the ID fields you are interested in seeing are identified as URL parameter conditions on the first model (Account in the example above).  This is the “get info” model.
 
Then make sure the fields are also populated  in the second model (Contact in the example above).  This is the “put info” model.  

What happens is when you put the Account Name in the field editor associated with the put info model - the skuid page knows it has an Account ID and that it matches the Account ID for the “get info” model.  It goes out and asks “Is that name field available anywhere?”   It finds the relationship in the get info model and populates things correctly. 

Warning - this will not work on polymorphic fileds (WhatId,  WhoId).  And in those cases you will have to do a little different process.

Hope this gets you started.  

Rob, Thanks for the response. I’ll review and see what I can do with it. Much appreciated. Matt

Hello All, Great thread . . .I’m trying to get the New Contact to work the way it currently does in Salesforce from the Account record, so we don’t lose functionality. 1. How can we auto-populate the Contact address with the address from the Account record? I presume there needs to be a “get” command that puts it into the URL . . . 2. How can we auto populate/auto-select State and Country picklist values. The picklists are a new enhancement from Salesforce . . . 3. How can we get the New Contact button redirect to work . . . the one that points to the Visualforce Page, which in turn points to the Skuid page for creating news contacts, which I’ve called “ContactNew”. In other words, how do we code the URL get and put parameter on the visual force page? Thanks! Krista

Krista,  here is an incomplete answer…  (but its late on a Saturday night, and I’m just back from our city’s best day-long street-party - so I’m not 100%). 
1. You can pass more parameters in the redirect url that is behind the “New contact” button on the account.  As many as you want.  These then get populated in your new page using the mechanism that Anna described above. 

2. You’ll have to wait till Monday on that… 

3. If you are building a custom button (either on a Skuid page or on a standard salesforce page)  you can call the Skuidified “contactNew” page directly.  ON the other hand, if you want to use the VF redirect route on the Contact - use the same methodology as overriding any standard Salesforce tab,  except make sure you are connecitn the “New” action for the “contact” object with the Skuidified “contactNew” page. 

Again - I’m probably pretty incoherent - but hopefully that will keep you going through the weekend. 

Krista - Question #2 seemed significant enough that it merited its own topic.  Here it is: http://community.skuid.com/t/skuid_with_auto_select_state_and_country_picklist_values

Hope that helps.