+ Start a Discussion
Steve KucklincaSteve Kucklinca 

Apex code naming convention on new record creation

I have the below trigger executing beautifully with 100% code coverage. Unfortunately when it creates a new record in the sandbox the Name of the record is the SFDC ID string referenced in the URL of the record. Is there any way to edit the code so readable text populates there instead of the ID string? For example using the name of one of the Parent objects (or combination of both) to easily identify the record

MerchOpps Name
a0aK0000004iSeQ
salesforce.com/a0aK0000004iSeQ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
trigger MerchOppsRecords on Merchant_Application__c (after update){

    Set<Id> accountIds = new Set<Id>();
    Map<Id,Opportunity> accountOpportunityMap = new Map<Id,Opportunity>();
    for(Merchant_Application__c ma : Trigger.new){
        accountIds.add(ma.Account_Name__c); 
    }
    
  
    for(Opportunity opp : [Select Id, Name, AccountId from Opportunity where AccountId = :accountIds]){
        accountOpportunityMap.put(opp.AccountId,opp);
    }
    
    List<MerchOpps__c> mOps = new List<MerchOpps__c>();
     
    for(Merchant_Application__c ma : Trigger.new){
        
        if(accountOpportunityMap.containsKey(ma.Account_Name__c)){
            MerchOpps__c mo = new MerchOpps__c(ChildofOpp__c = accountOpportunityMap.get(ma.Account_Name__c).Id, ChildofMA__c = ma.ID);
            mOps.add(mo); 
        }
    }
   
    insert mOps;  
    
}
Best Answer chosen by Steve Kucklinca
David "w00t!" LiuDavid "w00t!" Liu
All you need to do is modify the "Name" field of the record.

So before line 20 you can add this line:
mo.Name = ma.Account_Name__c;

All Answers

David "w00t!" LiuDavid "w00t!" Liu
All you need to do is modify the "Name" field of the record.

So before line 20 you can add this line:
mo.Name = ma.Account_Name__c;

This was selected as the best answer
Steve KucklincaSteve Kucklinca
thanks! that worked!