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
RyanJenkinsRyanJenkins 

Creating custom objects to autofill mailing addresses from a location

Hi, I'm working with a database full of inmates (and some non-inmates) and managing their records. I would like to devise a system where I can choose the prison in which inmates are located from a dropdown list, and then it would automatically fill their mailing address, since we occasionally correspond with them.

 

Conceptually, this is something that could be done by creating custom objects, right? If I had a class of object called prison, and then each prison had a mailing address, I think I should be able to autofill the mailing address of a prisoner if we relate them to a certain prison object. Is this correct, or no?

 

Or, is it something that can be done with a custom record type for a prison that would just have its name and address, and then declare some sort of relationship between a record type "prison" and a record type "inmate" so that it autofills their address if they are related to a prison?

 

I am worried about making their mailing address a lookup field, since that would disrupt the mailing address fields of the other non-inmate records that are stored in the same database. I don't really want to make another kind of address field, either, since that's getting redundant and ad-hoc. Any suggestions?

Richie DRichie D

If you fancy fiddling with triggers then you could use them to set the address details on saving the record (if a prison is chosen then load and set the address details). This would work server side so you wouldn't see the address fields until the record was actually saved. 

 

If you decide to do this then you might want to have a trigger on a prison record to update the prisoners details if the prison address changes!?!? 

 

Alternatively you could use visual force and apex controller to update an actionregion containing the address fields when a prison dropdown list is changed in a visualforce page. 

 

Either way I think you'll have to 'code something'. 

 

R. 

RyanJenkinsRyanJenkins

Thanks for the advice on triggers, I'm looking them up now, and it's a good solution without having to turn Address into a lookup field for all my records. Good deal.

 

Would the process be something like this?: 

 

1) Set up a custom object class for prisons and create one for each place, assigning the class an address field

2) Instantiating/creating all of the prison objects and filling in their address

3) Create a field for prison and add a dropdown for the prison location to the page layout for inmates

4) Writing a trigger that looks something like this, forgive the pseudocode:

 

when fieldIsModified(inmate.Prison)

{

if inmate.getPrison() != ""

{

inmate.setAddress(inmate.getPrison().getAddress());

}

 

Realize I took C++ and Java a while ago, so the syntax is way off, but you get the idea. 

Message Edited by RyanJenkins on 04-23-2009 09:49 AM
Richie DRichie D

Pretty much. Be careful with the triggers as you may need to 'bulkify' them - but thats all in the documentation.

Enjoy ;)

R. 

RyanJenkinsRyanJenkins
Thanks, I'll try to give all of that a try and see how it goes. I appreciate it. Ryan