0

I've tried various iterations but this is what I have right now. This is the main code from VF Page:

                    <div>
                <h3>Search Groups</h3>
                 <apex:form >
                  <apex:inputText id="groupName" list="{!listOfStrings}" value="{!groupname}"/>
                  <apex:commandButton value="Submit" reRender="wrapper" action="{!retrieveGroupMembers}"/>

                 </apex:form>
            </div>
        <apex:pageblock >

            <apex:outputPanel id="wrapper">
                         <apex:repeat value="{!PGM}" var="u">
                        <div class="view view-seventh">
                            <!--<img src="{!u.FullPhotoUrl}" />-->
                            <div class="mask">
                                <h2>{!u.users.CompanyName}</h2>

                                <a href="#" class="info">Read More</a>
                            </div>
                        </div>
                          </apex:repeat>                    

                </apex:outputPanel>

The Apex:

    public string groupName{get;set;}
public User[] users{get;set;}
public List<PublicGroupsMembers> PGM {get; set;}

public void retrieveGroupMembers(){
    // Get the users.
    PublicGroupsMembers pgm = new PublicGroupsMembers();
    List<PublicGroupsMembers> lPGM = new List<PublicGroupsMembers>();
    users = [Select AboutMe,FirstName,LastName,AccountId,IsActive,CompanyName,ContactId,Department,Email,ManagerId,Phone,ProfileId,UserRoleId,Title,SmallPhotoUrl,FullPhotoUrl,Id,UserType,Username FROM User WHERE Id IN (SELECT UserOrGroupId FROM GroupMember WHERE Group.Name IN (:groupName))];
    for(user u:users){
        pgm.users = u;
        pgm.SmallPhotoUrl = u.SmallPhotoUrl;
        pgm.FullPhotoUrl = u.FullPhotoUrl;
        PGM = pgm;
     }

}

public class PublicGroupsMembers{
    public User users;
    public string SmallPhotoUrl;
    public string FullPhotoUrl;
}

if I use "{!users}" instead of "{!PGM}" it will work. Any guidance is appreciated.

3

Apex is a case-insensitive language. The identifiers pgm and PGM are the same as far as the compiler is concerned. In addition, there is a key logical error in the code populating this variable. Let's look at what's happening here:

PublicGroupsMembers pgm = new PublicGroupsMembers();

This local variable shadows the instance variable PGM. You now cannot access the instance variable while this local is in scope without an explicit this reference.

List<PublicGroupsMembers> lPGM = new List<PublicGroupsMembers>();

You don't use this at all, and you actually don't need it.

for(user u:users){
    pgm.users = u;
    pgm.SmallPhotoUrl = u.SmallPhotoUrl;
    pgm.FullPhotoUrl = u.FullPhotoUrl;
    PGM = pgm;

This line assigns pgm to itself. Note that pgm is a single PublicGroupsMembers instance, not a List<PublicGroupsMembers>. It looks like what you meant to do was

lPGM.add(pgm);

However, all you need to do is initialize PGM - the instance variable, the list - with an empty list when you start, call your single PublicGroupsMembers something else like currentPublicGroupMember, and then do

PGM.add(currentPublicGroupMember);
2
  • Thanks for the help. I made the changes that you have suggested. In debug PGM has the data in it. The VF page is still not displaying my data and it still looks the same as above but I uncommented out FullPhotoUrl. – ChristianA Jul 8 '19 at 12:20
  • I figured it out. I had to change PublicGroupsMembers to be this: public User lusers{get; set;} public string SmallPhotoUrl{get; set;} public string FullPhotoUrl{get; set;} – ChristianA Jul 8 '19 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.