4

I have some code that triggers a Chatter Mention to a specific user. I want the user to be able to click this link on their phone and be taken to a visualforce page. This works exactly as intended when on a desktop but when using the Salesforce1 app, it only takes me to the contact record and not the VF page. Any ideas as to why this would be happening? My VF page is "Available for Salesforce Mobile Apps", so I can't figure out why this would be happening!

Chatter Utils Method:

public static void mentionLinkPost(Id userId, Id userToMentionId, String url, String urlName) { 

    ConnectApi.FeedItemInput feedInput = new ConnectApi.FeedItemInput();
    feedInput.body = new ConnectApi.MessageBodyInput();

    // add some text before the mention
    ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
    feedInput.body.messageSegments = new List<ConnectApi.MessageSegmentInput>();  
    textSegment.text = '';
    feedInput.body.messageSegments.add(textSegment);

    // add the mention
    ConnectApi.MentionSegmentInput mentionSegment = new ConnectApi.MentionSegmentInput();
    mentionSegment.id = userToMentionId;
    feedInput.body.messageSegments.add(mentionSegment);

    /*// add the text that was passed
    textSegment = new ConnectApi.TextSegmentInput();
    textSegment.text = postText;
    messageInput.messageSegments.add(textSegment);*/

    ConnectApi.LinkAttachmentInput linkIn = new ConnectApi.LinkAttachmentInput();
    linkIn.urlName = urlName;
    linkIn.url = url;
    feedInput.attachment = linkIn;

    /*ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
    input.body = feedInput;*/

    // post it
    ConnectApi.ChatterFeeds.postFeedItem(null, ConnectApi.FeedType.UserProfile, userId, feedinput, null);

  }

Part of the class that calls the Method:

ChatterUtils.mentionLinkPost(UserInfo.getUserId(),userList[0].id,'/apex/directConfirm?id='+contItem.id,'Accept Lead for '+contItem.Name);

Visualforce Page:

<apex:page controller="ConfirmationController" tabstyle="Contact" showHeader="false" sidebar="false" action="{!accept}">
</apex:page>

In this case, the userList[0].id is the user I'm mentioning, which works just fine. The "contItem.id" is the Contact Id that I am passing to my VF page, which once again, works perfectly well on a desktop but not at all on the SF1 app. Instead of taking me to the VF page in the app, I'm taken directly to the contact record instead. The VF page is calling an action which basically changes the ownerId of the contact to that of the running user.

Any ideas or insight would be greatly appreciated!

4 Answers 4

3

I needed to add an action to my record layout with the following code to allow my VF page to be opened within SF1.

<apex:page standardController="Contact" sidebar="false" showHeader="false">

    <script  language="javascript" type="text/javascript">

    var myUrl = "/apex/Confirmation?Id={!Contact.id}";
    if( (typeof sforce != 'undefined') && (sforce != null) ) {
      // Salesforce1 navigation
      sforce.one.navigateToURL(myUrl);
    } else {
      // Set the window's URL using a Visualforce expression
     window.location.href =   myUrl;
    }

</script>
</apex:page>
2
  • does it worked. how it is getting linked, when we are clicking on url in feed. and how added action .
    – Ankuli
    Commented Jul 10, 2015 at 5:37
  • Yeah, it works. This is the page for an action that I put on the Contact record. Clicking it in SF1 will open my page that has the rest of my code. Commented Jul 10, 2015 at 22:28
2

enter image description here

Make sure to check the Available for Salesforce mobile apps checked on VF .

Workaround

One other can be to use Publisher actions and call this visualforce controller code to execute the logic

4
  • Thanks Mohith, but like I mentioned, I've already done that. Commented Jul 9, 2015 at 4:26
  • Oopps..Missed it .Alright so workaround to spin a new action and see if it works . Commented Jul 9, 2015 at 5:03
  • 1
    It is happening bcz in SF1 to go to visualforce page we need to call method like this which is not similar as desktop sforce.one.navigateToURL('/apex/PageName'); so when u created a chatter feed that link it is working fine in desktop but when u run the same in SF1 it couldn't change the url and unexpected behaviour happens .As url is fixed when u created the chatter feed. so it remain same for desktop and SF1
    – Ankuli
    Commented Jul 9, 2015 at 6:37
  • @Ankuli any idea how I could use the sforce.one.navigateToURL('/apex/PageName') method in my Chatter Post? Commented Jul 9, 2015 at 13:45
0

Please find the give code in the image format......enter image description here

1
  • 2
    Nikitha it is better to post code in text format; on this site you can paste the text into the answer window, select it all and then click the {} button to get the code formatted and escaped so it displays well. The problem with an image is that it can't be search indexed so will not appear in search results on the site or via Google. And anyone wanting to use the code will have to type it in again which often leads to errors.
    – Keith C
    Commented Jul 10, 2015 at 8:36
0

<script  language="javascript" type="text/javascript">

var myUrl = "/apex/Confirmation?Id={!Contact.id}";
if( (typeof sforce != 'undefined') && (sforce != null) ) {
  // Salesforce1 navigation
  sforce.one.navigateToURL(myUrl);
} else {
  // Set the window's URL using a Visualforce expression
 window.location.href =   myUrl;
}

You must log in to answer this question.

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