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
NinesNines 

Create a trigger that replaces Id with Name

I am very new to Salesforce so I would really appreciate some help in this.

I am creating multiple multiple job application records from selecting candidates on a data table. The position field is a lookup field connected to Job Application so whenever a job application is created the name of the Job application is set into an ID.The left side is the Id of the Job Application and I would like to replace that Id with the Position Title
I would like help to create a trigger that when I create a job application the ID name is replaced with the position title name. 
manu manu 23manu manu 23
Is the position parent object? i assume it is so and  job applications are child to the postion right? 
manu manu 23manu manu 23
i would prefer process builders for this 
NinesNines
Hi Manu yes. The Position is the parent object. I'm not using process builder because the create job application is done in bulk.
ravi soniravi soni
hi Nines,
Plese correct me if i wrong. I think you want that in place of Id, Position Title shuld be display on UI and when user click on title, I should navigate on its detail page or just display title instead of Id.

If this is your requirment then I would say you don't need trigger but it will be managed by JavaScript. you need to share your entire Code with apex.
Thank you
Suraj Tripathi 47Suraj Tripathi 47

Hi,

You can take references from the below code. You can write a trigger for this

trigger ContactAccountTrigger on Contact (before insert, before update, after insert, after update) {  
    List<Contact> conList =new List<Contact>();
    Set<Id> setid = new  Set<Id>();
    
    if(trigger.isBefore){
        system.debug('trigger before event');
        conList = trigger.new;
        
    }else if(trigger.isAfter){
         conList=trigger.new;
        for(Contact con:conList){
           setid.add(con.AccountId); 
        }
        system.debug('setid ' + setid);
        
        List<Account> accList = [Select Id, Name, updateContact__c From Account  Where Id=:setid];       
       
        if(trigger.isInsert){                     
            
             for(Contact c1:trigger.new){
                 for(Account a1:accList){
                     a1.updateContact__c= c1.FirstName + ' ' + c1.LastName;
                     update a1;
                 }   
              }
            
            
        }else if(trigger.isUpdate){
            for(Contact c2:trigger.new){
                for(Account a2:accList){
                    a2.updateContact__c= c2.FirstName + ' ' + c2.LastName;
                    update a2;
                }   
            }             
        }        
         
    }
}
Thank You