You need to sign in to do that
Don't have an account?

obj.getSObject('CreatedBy') returning null after Insert
riggeri am testing a trigger.i am calling this method
GMirrorUtil.createTimeLine(Trigger.new, 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 = ''; if(contentMap.get('Object').equals('FeedItem')) type='Post'; if(contentMap.get('Object').equals('FeedComment')) type= 'Comment'; GlassUserApiSettings__c userSettings = userSettingsMap.get(userId); if(((String)obj.get(contentMap.get('Content'))).contains('@'+userMap.get(userId).Name)){ Datetime tokenExpiredTime = userSettings.LastModifiedDate; tokenExpiredTime.addSeconds(Integer.valueOf(userSettings.ExpireDuration__c)); String body='{"html":"<article><section><div class="text-auto-size">'+type+':'+ '<p class="yellow">"'+obj.getSObject('CreatedBy')+' '+obj.getSObject('CreatedBy')+'</p><p>'+obj.get(contentMap.get('Content'))+'</p>'+ '</div></section> </article>"}'; System.debug('Body is '+body); if(tokenExpiredTime >= System.now()){ 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','https://www.googleapis.com/mirror/v1/timeline',userSettings.AccessToken__c); GMirror.TimelineResponse createdTimeCard = (GMirror.TimelineResponse) JSON.deserialize(timelineRes,GMirror.TimelineResponse.class); if(createdTimeCard.id != null) System.debug('created timeline card :'+createdTimeCard); else { try{ throw new GMirror.TimelineException(null,timelineRes); } catch(Gmirror.TimelineException e){ System.debug(e.getMessage()); } } } } }
but when i initialize prepare String body='{"html":"'+type+':'+ '"'+obj.getSObject('CreatedBy')+' '+obj.getSObject('CreatedBy')+'
'+obj.get(contentMap.get('Content'))+'
'+ ' "}'; 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 ??
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 http://boards.developerforce.com/t5/Apex-Code-Development/Error-When-only-send-a-HttpCallout-in-batch-request/m-p/683333 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