0

Have repeater in repeater. Object Schema is as below.

Object :- MBT_SFFB__Conversation__c
Field1 :- MBT_SFFB__Total_Comments__c datatype :- Number
Field2 :- MBT_SFFB__parent__c datatype :- Lookup(MBT_SFFB__Conversation__c)
Field3 :- MBT_SFFB__Is_Comment__c datatype :- Checkbox if(checkbox is true then its comment otherwise post)

Structure :-

Post1:- XXXXXXXXXXXXX

Comment1 :- rrrrrrrrr

Post2 :- zzzzzzzzzz

Post3 :- pppppppppppp

Comment1 :- yyyyyyyyyy

Comment2 :- gggggggggg.

public Map<String,MBT_SFFB__Conversation__c> objmappost {get;set;} // For Post- Post ID  and post 
public Map<String,list<MBT_SFFB__Conversation__c>> objmapcomment {get;set;} // For post wise comments :- post ID and list of comments.

Issue Arise is if post have No comments as i have post2 then it will throw error that map don't have Values.

i wanna Use Condition that If Post have comments then and then only comment repeater should be shown. Please help me in writing Condition.

 <apex:repeat value="{!objmappost}" var="post">
   <div>
    Post 
   </div>
   <apex:repeat id="comment" value="{!objmapcomment[post]}" var="comment">
   <div>
    comments
   </div> 
  </apex:repeat>
</apex:repeat>

I wanna this type of IF() in visualforce :-

value="{!IF(((objmapcomment[post].MBT_SFFB__Total_Comments__c)==0), 'dont bind comment repeater', objmapcomment[post])}"
ERROR :- Incorrect parameter type for subscript. Expected Number, received Text

1 Answer 1

4

If iterating over the objmappost for one time is not a problem for you then you can try like,

for(String key: objmappost.keySet()){
    if(null == objmapcomment.get(key))
      objmapcomment.put(key,new list());
}

Note: I assume objmappost and objmapcomment has same keys based on your question.

Though rendering based on null or not at vf page would have been great but I could not find the way to implement that.

And if you implement this, you won't be using the if statement.

Edit:

If you have a field MBT_SFFB__Total_Comments__c on MBT_SFFB__Conversation__c which stores the count of comment on the post then you should try;

<apex:repeat id="comment" rendered="{!objmappost[post].MBT_SFFB__Total_Comments__c > 0}" value="{!objmapcomment[post]}" var="comment" >
        <div>
            comments
        </div> 
    </apex:repeat>
3
  • <apex:repeat id="comment" value="{!IF(((objmapcomment[post].MBT_SFFB__Total_Comments__c)==0), 'dont bind comment repeater', objmapcomment[post])}" var="comment"> wanna this type of Condition. can you please Help me for this ? Commented Jan 6, 2017 at 6:50
  • do you have a field MBT_SFFB__Total_Comments__c on MBT_SFFB__Conversation__c? Does conversation-Comments share a master-detail relation? Commented Jan 6, 2017 at 6:55
  • I have lookup from conversation to conversation (Self lookup) and have totalcomments field please check the question i had already mentioned structure as well as database. Commented Jan 6, 2017 at 7:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .