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
Peter van HeckPeter van Heck 

Master-Detail field default value

I have 2 custom objects, Locations and Systems, which both have a
Master-Detail relation with Account: Systems also has a Locations
lookup field.
After I created a New Location (record) I would like to create New
Systems (records) from Locations.
How do I set the default value for the (Master-Detail) field Account.Name,
which has already been entered in Locations?
I have tried it with a formula field called Account_ID and a trigger
but I do not get it work:
trigger CopyAccountID on System__c (before update, before insert) {
For (System__c
       accid.Account__c = accid.Account_ID__c;
//    }



Message Edited by Peter van Heck on 09-22-2008 05:29 AM
I think you should have a query for example...


trigger CopyAccountID on System__c (before update, before insert) {
For (System__c
       Location__c query = [Select Account__c from Location__c where Id = :accid.System__c limit 1] 
       accid.Account__c = query.Account__c;

obviously you should have the System Id on Location

hope I can help you


well i dont know much about this but hope this will help you


try using the realtionship name like


System.Account = Locations__r.Account_Name;


perhaps you can find a way with this.