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
MSVRadMSVRad 

Autopopulate a field when another is filled in and saved

I want to write a trigger that will auto populate a date field when another date field from another object is filled in.  One field is from a custom object the other from a standard Contract object. The account name that is attached to both objects has to match so that the correct date is passed into the field that I have created.
 
So, I want to take a date from the contract object and put it in a field in the custom object, where their accounts match. There is a little hiccup in this that I do not know how to handle. in the standard Contract object the Account field is a standard lookup field. But in the custom object the the Account Name field is a custom field that has a master detail relationship to Account. - how do I deal with that? I just want to make sure that the accounts being referenced in the two different objects are the same Account.
 
Does anyone have an idea of how to start this trigger? or even pseudo code would be helpful because I cannot wrap my head around this right now.
JonPJonP
You'll need to provide more context about the relationship between the custom object record and the Contract record.  Both objects have a 1 to Many relationship with Account, so if you have multiple custom object records and multiple Contract records, when you edit a Contract how do you know what custom object records to update?

Depending on your requirements, you may be able to do this with one or more formula fields rather than a trigger, which will be much simpler.
MSVRadMSVRad
The custom object(Go Live Process) allows the user to pick the record type (from a picklist) for the record they want to create. I am only concerned with one of the record types (Client Agreement) this record type corresponds to the Contract type, "Client Agreement Contract".  The Contract object only has this one type of contract.
This is really the only way these two objects are related other than they are both related to an Account object.
 
So the Account has a Go Live process in this case its a Client Agreement. The Client Agreement(Go Live Process) has a Client Agreement Contract.
NonickNonick
Sounds like a trigger which will run on update of your object.
select from your custom object when the name matches and save that field to match.
You can probably get it to only update the field if it changed due to the update.
You'll also probably need to get it to itterate through the individual custom objects which you can do by selecting to an array. That should deal with you probably having a many to one relationship.

That is if I'm reading the situation correction. I'm guessing you want for the date to update when the account name selected corresponds with the account name in the project yeh? Something to consider will be, what if you have several contracts related to the same account object.

You have any experience in testing triggers?
I'm stuck on mine



Message Edited by Nonick on 11-20-2008 04:43 PM
Shadow8002Shadow8002
These kind of triggers is something that me and my team develop all the time. You can email me with the specifics and we can get something like this done in a couple of hours. Email me at arun.david@listertechnologies.com

Thanks.