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
chessbasechessbase 

Custom object reference field

Hi All,
 
How can I make the custom object reference field REQUIRED just like I can do it for others field? I looked in to all possible areas but couldn't find anything to make the field required. Is it possible BTW?
RickyGRickyG
You could certainly write an Apex trigger to check for values and disallow the insert/update if there was no reference designated.

Hope this helps.

- Rick Greenwald
Developer Evangelist
chessbasechessbase

I tried following and it didn't work. Can u point out what is wrong with following code? how do i cancel the insert if account id is null?

Code:

trigger checkAccount on Project__tenrox__c bulk (before insert)
{
  for (Project__tenrox__c opp : Trigger.new)
  {
    Id OppId;     
    OppId = opp.Id;
    Project__tenrox__c[] ThisOppPartner = [select Account__c From Project__tenrox__c WHERE Id=:OppId];
  
    for(Project__tenrox__c o: ThisoppPartner)
    {
       if (o.Project__Account__c=='')
           return;
    }
  }
}