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

obj.getSObject('CreatedBy') returning null after Insert

riggeri am testing a trigger.i am calling this method

  GMirrorUtil.createTimeLine(, contentMap);

My create timeline function is 

public static void createTimeLine(List<sObject> objList,Map<String,String> contentMap){ 
      Map<Id,User> userMap = new Map<Id,User>([Select id,Name From User where Authorize__c = true]);
      Map<Id,GlassUserApiSettings__c> userSettingsMap = new Map<Id,GlassUserApiSettings__c>();

       for(Id user_id : userMap.keySet()){
         GlassUserApiSettings__c userSettings = GlassUserApiSettings__c.getValues(user_id);
        if(userSettings == null)
         { User u =userMap.get(user_id);
            u.Authorize__c = false;
           update u;  
          else userSettingsMap.put(user_id,userSettings); 

       for(sObject obj : objList)
         for(Id userId: userSettingsMap.keySet() ){
           String type = '';
             type= 'Comment';
           GlassUserApiSettings__c userSettings = userSettingsMap.get(userId);
             Datetime tokenExpiredTime = userSettings.LastModifiedDate;
             String body='{"html":"<article><section><div class="text-auto-size">'+type+':'+
                         '<p class="yellow">"'+obj.getSObject('CreatedBy')+'&nbsp;'+obj.getSObject('CreatedBy')+'</p><p>'+obj.get(contentMap.get('Content'))+'</p>'+
                         '</div></section> </article>"}';
                         System.debug('Body is '+body);
             if(tokenExpiredTime >={
               GMirror.TokenResponse res  =  GMirrorUtil.refreshToken(userSettings.RefreshToken__c);                 
               userSettings.RefreshToken__c = res.refresh_token;
               userSettings.AccessToken__c  = res.access_token;    
               userSettings.ExpireDuration__c = Integer.valueOf(res.expires_in) ;
               update userSettings;
             String timelineRes = doApiCall(body,'POST','',userSettings.AccessToken__c);
             GMirror.TimelineResponse createdTimeCard  = (GMirror.TimelineResponse) JSON.deserialize(timelineRes,GMirror.TimelineResponse.class);   
             if( != null)
               System.debug('created timeline card :'+createdTimeCard);
             else { try{
                        throw new GMirror.TimelineException(null,timelineRes);
                    catch(Gmirror.TimelineException e){

but when i initialize prepare String body='{"html":"'+type+':'+ '"'+obj.getSObject('CreatedBy')+' '+obj.getSObject('CreatedBy')+'


'+ ' "}'; i check it in debug logs its giving me null for getSObject('CreatedBy'); i inserted it in my test class thats why trigger invoked and i am using afterinsert event in trigger . can any one please tell why its giving me null ??



Are other fields of the object too showing null?
If yes then the test class data might not be available for debugging as its created only on the fly and destroyed.

Hey Ispita,Please give reply to this query if possible.No not other fields are showing not sowing null.i solved this using a SOQL statement first get CreatedById then find User and Then User.Name .Simple