• Nilam Roy
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I have a chatter group where user can put a question and if any user answer the question , requestor can choose the answer as a "BestAnswer". Below class is reponsible for this functionality. Now the issue is bestanswer flag is not coming in the detail page. we have found out the resolution. could someone help me to get it as i am new into SFDC?

for(sobject s : scope){
              jj_sss_Question_And_Answer__c question = (jj_sss_Question_And_Answer__c)s;
           
            try {                               (4)
                ConnectApi.FeedItem fi = jj_sss_Chatter_Functions.GetFeedItem(question.jj_sss_Feed_Item_Id__c);          (1)
               
                ConnectApi.QuestionAttachment qa = (ConnectApi.QuestionAttachment)fi.attachment;         (2)
                if (qa.bestAnswer != null) {
                    List<jj_sss_Question_And_Answer__c> answersToQuestion =
                        [select id, jj_sss_Status__c, jj_sss_isMailSent__c,jj_sss_Is_Best_Answer__c, jj_sss_Answer_Posted_By__c,jj_sss_Answer_Posted_By__r.Id,jj_sss_Question_Posted_By__r.Id, jj_sss_Feed_Comment_Id__c
                         from jj_sss_Question_And_Answer__c
                         where jj_sss_Feed_Item_Id__c = :question.jj_sss_Feed_Item_Id__c
                         and jj_sss_Feed_Comment_Id__c != null];
                   
                    jj_sss_Question_And_Answer__c bestAnswer = null;
              …
            } catch(Exception ex) {
                // An Exception occured
                System.debug(logginglevel.ERROR, 'An Exception occured while running the Best Answer job');     (3)
            }
                   
(1)If the feed item is deleted, this will return ‘Null’ and cause an nullpointer exception in (2)
(2)Calling the property .attachment can also return ‘Null’ which is not checked
(3)When logging the error message, the original exception is not mentioned. As such debugging is hard.
(4)The try catch is only around questions, issues with answers will be caught, but stop the processing of other answsers.


seeing 1,2,3,4 can you write the code for me ?
I have a chatter group where user can put a question and if any user answer the question , requestor can choose the answer as a "BestAnswer". Below class is reponsible for this functionality. Now the issue is bestanswer flag is not coming in the detail page. we have found out the resolution. could someone help me to get it as i am new into SFDC?

for(sobject s : scope){
              jj_sss_Question_And_Answer__c question = (jj_sss_Question_And_Answer__c)s;
           
            try {                               (4)
                ConnectApi.FeedItem fi = jj_sss_Chatter_Functions.GetFeedItem(question.jj_sss_Feed_Item_Id__c);          (1)
               
                ConnectApi.QuestionAttachment qa = (ConnectApi.QuestionAttachment)fi.attachment;         (2)
                if (qa.bestAnswer != null) {
                    List<jj_sss_Question_And_Answer__c> answersToQuestion =
                        [select id, jj_sss_Status__c, jj_sss_isMailSent__c,jj_sss_Is_Best_Answer__c, jj_sss_Answer_Posted_By__c,jj_sss_Answer_Posted_By__r.Id,jj_sss_Question_Posted_By__r.Id, jj_sss_Feed_Comment_Id__c
                         from jj_sss_Question_And_Answer__c
                         where jj_sss_Feed_Item_Id__c = :question.jj_sss_Feed_Item_Id__c
                         and jj_sss_Feed_Comment_Id__c != null];
                   
                    jj_sss_Question_And_Answer__c bestAnswer = null;
              …
            } catch(Exception ex) {
                // An Exception occured
                System.debug(logginglevel.ERROR, 'An Exception occured while running the Best Answer job');     (3)
            }
                   
(1)If the feed item is deleted, this will return ‘Null’ and cause an nullpointer exception in (2)
(2)Calling the property .attachment can also return ‘Null’ which is not checked
(3)When logging the error message, the original exception is not mentioned. As such debugging is hard.
(4)The try catch is only around questions, issues with answers will be caught, but stop the processing of other answsers.


seeing 1,2,3,4 can you write the code for me ?