+ Start a Discussion
Malli GMalli G 

how to display a string value in place of lookupfield in detailpage?

i have an account and contact object, if i didn't select "Account lookup" in "contact", after saving the record i want to display a string value in place of "account name"  in detail page using triggers.
the "Account Name" is a lookup field, which means you cannot input a place holder string into it. It always need to be a reference to an account record. One thing you could do, is to create an account for this purpose say "General Account" and then using a before insert trigger fill in the Account field ; something like this:
trigger contact_actions on Contact (before insert){
      //query the general Account id
      Id generalAccountId = [Select Id from Account where name = 'General Account'].id;

      //loop through contacts being inserted
      for(Contact thisContact: Trigger.new){
             //verify if the account lookup was left empty
             if(thisContact.AccountId == null)
                   thisContact.AccountId = generalAccountID;

Arun KumarArun Kumar
Hi Malli,

You can create anew custom field of text type then assign your string to it. And change the PageLayoyt accordingly.