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
Dorel4Dorel4 

Cross object formulas

I am created a formula field called "List Agent" (see below).  I wpuld like to take the Listing Agent ID LR Source field's information and look up in the Custom Object "Agent" to see if there is an Agent ID that matches,  If it does, I would like the Agent Name to be returned.  I can not get the formula to use the Listing Agent ID LR Source to search in the Agent Object.  Please help.  If this is not possible with a formula please advise my options.  Thank you 

IF( Listing_Agent_ID_LR_Source__c =  Agent__r.Agent_ID__c ,  Agent__r.Name , NULL)  
KaranrajKaranraj
You can't do it simply by formula field. You have to write trigger to achieve this.

1. Write before insert trigger on Listing Agent ID LR Source field object
2. Using soql query get the Agent information based on the Listing Agent ID LR Source field's information
3. Then assign the matching value to the custom field
 
trigger yourtriggername on Nameoftheobject (before insert) {
  List<string> listingAgentId = new List<String>();
Map<String,Nameoftheobject> mapValues = new Map<String,Nameoftheobject>()
         for(Nameoftheobject sobj : Trigger.new){
                listingAgentId.add(sobj.Fieldname); //Field name you want to compare 

        }
List<agent__c> agentValues = [select id,AgentName from Agent__c where AgentId IN: listingAgentId];

   for(Nameoftheobject sobjs : Trigger.new){
    for(agent__c agc: agentValues){
       if(agc.Agent_Id__C == sobjs.Fieldname){
           fieldNameofAgent = agc.Agent_Name__c
        }

    }
} 
}

The above is writen with the assumptions of the field and object name, you need to replace the objectname and field names as per your org else this trigger won't get saved in your org.

I suggest you to take a look into the salesforce Trailhead which helps you to get programticaly.https://developer.salesforce.com/trailhead