0

I trying to post something to a Facebook page using my own API.The Visualforce Page gets the Facebook Page info and displays a checkbox. The user then selects the Pages and clicks Submit.

Here is my Controller code.

public String[] FacebookOptions = new String[]{};

if (postFacebook)
          {

              FACEOFFERS_Settings__c settings = [select Id, MerchantId__c from FACEOFFERS_Settings__c];
              string merchantId = settings.MerchantId__c;

              FaceOffersAppClaim AppClaim = FaceOffersController.GetToken();   

              FaceoffersSocialAccount facebook = GetFaceBookAccount();

              List<FacebookAccountModel> facebookPages = FaceOffersController.GetFacebookPages(merchantId, facebook.AccessToken, AppClaim.Token);

              for (String[] i : facebookOptions)
              {

                  //Get short URL 
                  string shortURL = FaceOffersController.GetShortURLSocialMedia(selectedOfferId); 

                  if(i.getValue() != null)
                  {

                      for (FacebookAccountModel a : facebookPages)
                      {
                          if (i.getValue() == a.id)
                          {
                              FacebookPost post = new FacebookPost(merchantId, a.id, a.access_token, 'A deal on us!', shortURL );

                              FaceOffersController.PostToFacebook(post, AppClaim.Token);
                          }
                      }

                  }
              }

          } 

public String[] getFacebookOptions() {

        return FacebookOptions;

    }

    public void setFacebookOptions(String[] FacebookOptions) {

        this.FacebookOptions = FacebookOptions;
}

I can see the Facebook Page Id in FacebookOptions when I debug, but I can't get to it. If I can get to the Id, I can then try to match the Ids in this statement if (i.getValue() == a.id).

Any help is much appreciated. Thanks!

  • 1
    List doesn't have a method getValue()? – sfdcfox Oct 16 '18 at 21:14
  • @sfdcfox Thanks for the reply! I'm stuck. Any idea what I can do to get the Page Id? What about the for loops? Is there a better way to filter lists in Apex? – Dumber_Texan2 Oct 16 '18 at 22:21
0

I found a solution here.

https://stackoverflow.com/a/39241324/5360237

for (String pageId : FacebookOptions)

The pageId then contains the string values from FacebookOptions.

The first if statement is now this.

if(pageId != null)

The final if statement looks like this.

if (pageId == a.id)

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.