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
BMC GroupBMC Group 

Why Values are not populating into fields ?

Hi all,
Basically I want to insert values some field values into the respected fields into child object Trademark_Details_ESR__c from the custom Object Trademark_Details__c dynamically for that i have created custom settings TrademarkESRDetails__c.Ihave got all the required values into the esrList but those are not populated after its insertion.
Here is my code.

public with sharing class CreateTrademarkDetailsESRGateway{
    
    public list<Trademark_Details_ESR__c> TMESR=new list<Trademark_Details_ESR__c>();
    public list<Trademark_Details_ESR__c> newESR=new list<Trademark_Details_ESR__c>();
    public String input;
    public Integer index=0;
    public map<Integer,list<TrademarkESRDetails__c>> esrmap=new map<Integer,list<TrademarkESRDetails__c>>();
    
  
    public list<Trademark_Details_ESR__c> esrList = new list<Trademark_Details_ESR__c>();
   
    public void DetailsUpdate(list<Trademark_Details_ESR__c> triggernew){ 
        
        for(Trademark_Details_ESR__c tempTM: triggernew){
            system.Debug('---tempTM--'+tempTM); 
            system.Debug('---tempTM.BMCID__c--'+tempTM.BMCID__c);
            input=tempTM.BMCID__c; 
            system.Debug('---input--'+input);
        } 
       
                
        if(input!= null){
            system.Debug('---input--'+input);
            list<Trademark_Details__c>  tmrRecords = [Select id,Application_Date__c,Application_No__c,Application_Status__c,
                                                       Brand_Name__c,   Class_No__c,Contact_Email__c,Contact_Name__c,
                                                       Contact_Phone__c,Operation_Name__c,oid__c,User_Date__c,name
                                                       From 
                                                       Trademark_Details__c
                                                       Where
                                                       oid__c =: input AND Application_Status__c='Objected'];   
        
            system.debug('-tmrRecords-' + tmrRecords);
            getESRDetails(tmrRecords);
         }
      
            
   }
  
  
   public void getESRDetails(list<Trademark_Details__c> tmrRecords1){
    
   try{
        system.debug('---TMRRecords1'+TMRRecords1);
        system.debug('---TMRRecords1.size()---'+TMRRecords1.size());
        system.debug('--- TrademarkESRDetails__c.getAll()-'+ TrademarkESRDetails__c.getAll());
        system.debug('--- TrademarkESRDetails__c.getAll().Values()---'+ TrademarkESRDetails__c.getAll().Values());
        
        list<TrademarkESRDetails__c> lst = [Select ESR_Field_API_Name__c,TM_Field_API_Name__c,List_Size__c from TrademarkESRDetails__c];
        system.debug('---lst'+lst);
        
        for(TrademarkESRDetails__c  temp : TrademarkESRDetails__c.getAll().Values()) {
            system.debug('---temp---'+temp);
            system.debug('---temp.List_Size__c---'+integer.valueof(temp.List_Size__c));
                if(esrMap.containsKey(integer.valueof(temp.List_Size__c))){
                    esrMap.get(integer.valueof(temp.List_Size__c)).add(temp);
                    system.Debug('in IF-esrMap.get(integer.valueof(temp.List_Size__c))-' + esrMap.get(integer.valueof(temp.List_Size__c))); 
                }else{
                     esrMap.put(integer.valueof(temp.List_Size__c), new List<TrademarkESRDetails__c> {temp});
                     system.Debug('in else -esrMap.get(integer.valueof(temp.List_Size__c))-' + esrMap.get(integer.valueof(temp.List_Size__c)));
                }   
        }
        system.debug('-esrMap.size-' + esrMap.size()+'---esrMap---'+esrMap);
        system.debug('---esrmap.get(index)---'+esrMap.get(index));
       
         //sObject s;
         //Trademark_Details_ESR__c esr = (Trademark_Details_ESR__c)s;
        
        
          Trademark_Details_ESR__c esr=new Trademark_Details_ESR__c();
        for(Trademark_Details__c tempTM: tmrRecords1){
            system.debug('---TMRRecords11---'+tempTM );
            //TrademarkESRDetails__c is a custom settings
            
            
            for(TrademarkESRDetails__c customSettings : esrmap.get(index)){
               system.debug('---customSettings--'+customSettings + '-esrmap.get(index)-'+esrmap.get(index));
               esr.put(customSettings.ESR_Field_API_Name__c, tempTM.get(customSettings.TM_Field_API_Name__c));
               system.debug('---esr1--'+esr);
               esrList.add(esr);
            }
           
            index++; 
        }
      
        system.debug('-esrList.size-' + esrList.size()+ '-esrList-' + esrList);
      
       if(esrList.size()>0){
            system.debug('--inside if'+esrList);
            insert esrList;
       }
           
    }catch(Exception e){
        system.debug('---Exception'+e.getmessage());
    }
  }
}
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello,

What are the fields that you are trying to get populated? Is that class called in a trigger (after/before/update/insert) ?
BMC GroupBMC Group
Hi Zuinglio Lopes Ribeiro Júnior,

Thanks for you reply,i am trying to populate fields namely Application_No1__c,Class_No1__c and Brand_name1__c likewise 2,3,4, in the Trademark_Details_ESR__c Custom Object from  Trademark_Details__c  object for n no. of records from the respective fields  Application_No__c,Class_No__c,Brand_name__c as youcan see in the query. To achieve this i have created custom settings TrademarkESRDetails__c as can be understood in the code itself.

Yes this class is being called from tigger on condition before insert ,before Update.