function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jkucerajkucera 

Link to detail page

At risk of showing how much I suck at UI, I can't get a link to work to point to a detail page.

 

This VF page only shows if there's an error, and I want to show a link to a Chatter Group for some of the errors (let's assume all the time for this thread).

 

How do I do that?

 

If I try to pass the ID from a method to a class var, I get an error "Variable doesn't exist: newGroup"

 

VF:

<apex:page standardController="Opportunity" extensions="createExternalGroupController" action="{!createExternalGroup}">
    <apex:pagemessages />

    <apex:form>

        <apex:pageBlock id="thePageBlock">

                <apex:commandLink id="groupExists" value="Go to Customer Group"  action="{!groupLink}"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 Apex:

public with sharing class createExternalGroupController{

    public final Opportunity o;
    public PageReference pageRedirect= new PageReference('');
    public Id newGroup;
    public createExternalGroupController(ApexPages.StandardController controller) {
        this.o=(Opportunity)controller.getRecord();
        pageRedirect=ApexPages.CurrentPage();
    }
    
    public pageReference groupLink(){
        PageReference pageRef=new PageReference('/'+newGroup);
        return pageRef;
    }//opptyLink

    public pageReference methodThatDoesStuff(){
       CollaborationGroup g=new CollaborationGroup();
                g.CollaborationType='Private';
                g.CanHaveGuests=TRUE;
                g.name=groupName;
       insert g;

       newGroup=g.Id;
       return pageRedirect;
    }

 

_Prasu__Prasu_

Did you tried following?

return new PageReference('/' +newGroup); 

 

Or you can write a getter setter and access the newGroup on visualforce page.

public Id newGroup {get; set;}


_Prasu__Prasu_
Ispita_NavatarIspita_Navatar

Hi,

Please try this code and its working fine for me :-

<apex:page standardController="Opportunity" extensions="createExternalGroupController"  action="!methodThatDoesStuff}" >   

<apex:pagemessages />
    <apex:form >
        <apex:pageBlock id="thePageBlock">
                <apex:commandLink id="groupExists" value="Go to Customer Group"  action="{!groupLink}"/>              </apex:pageBlock> 

  </apex:form>

</apex:page>  

 

public with sharing class createExternalGroupController

{
    public final Opportunity o;   

    public PageReference pageRedirect= new PageReference('');   

    public Id newGroup;   

    public createExternalGroupController(ApexPages.StandardController controller)

{       

     this.o=(Opportunity)controller.getRecord();       

     pageRedirect=ApexPages.CurrentPage();   

 

   public pageReference groupLink()

{   

   system.debug('##########' +newGroup);       

   PageReference pageRef=new PageReference('/'+newGroup);       

    return pageRef;   

 }//opptyLink
    public pageReference methodThatDoesStuff()   

{     

 CollaborationGroup g=[select id from CollaborationGroup limit 1];        

    //   new CollaborationGroup();             

    //   g.CollaborationType='Private';         

   //    g.CanHaveGuests=TRUE;           

  //     g.name='gName';       

 //      insert g;       

   system.debug('@@@@@@@' + g.id);
       newGroup=g.Id;       

       return null;   

}

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

jkucerajkucera

Thanks for the help - it looks like the groupLink method isn't firing for me, as the log doesn't show a system.debug() comment at all, and the link always points to the oppty:

https://c.na12.visual.force.com/apex/OpportunityCustomerGroupButton?id=006U00000036NDX&core.apexpages.devmode.url=1#

 

I'm gonna give up here as the link isn't that important and I don't want to spend another hour figuring out soemthing that should be really easy to do, and the link isn't that important for the app. 

 

Perhaps there's some issue with the order of operations given the group is created during the auto-run action on the VF page, so perhaps the group doesn't exist yet when the link method tries to grab the ID.  

 

I appreciate both of your help and I like the URL methods link as I didn't realize those methods existed.