0

I have a VF page that call a flow when a custom button is clicked (maybe not a best practice but I'm working on this project, and I not have time to rework all this process...). The problem is that when we are in a community, this button should be hide or disabled.

So for now in the VF page I just filter if we are in a community using Site.getSiteId() and I can detect if I am in a community or not, with something like this :

<apex:pageBlockSection rendered="{!isInCommunity != true}">
    <flow:interview name="AssignCases"
    finishLocation="{!IF($User.UITheme == 'Theme4d' || $User.UITheme == 'Theme4t','/one/one.app#/sObject/Case/home','/500')}">
    <apex:param name="socvCasecoll" value="{!Selected}"/>
    <apex:param name="vUid" value="{!$User.Id}"/>
    </flow:interview>

</apex:pageBlockSection>

<apex:pageBlockSection rendered="{!isInCommunity == true}">

</apex:pageBlockSection>

So I'm not sure if I need touse the second apex:pageBlockSection, but i try to put some javascript at the bottom of my page to retrieve the button (and try to hide it later):

var isInCommunity ={!isInCommunity};
    console.log('isInCommunity : ' + isInCommunity);
    if(isInCommunity == true){
        console.log('passe dans isInCommunity == true');
        var bouton = document.querySelector('.forceActionLink');
        console.log(bouton);
    }

but the problem is that I got null in the log, so I can't hide it...

**** EDIT ****

Here is the DOM with the button : enter image description here

I also try to get the element by using document.querySelector('a[title="M\'affecter cette demande"]') to isolate the a tag, but it also returns null.

  • Your included markup does not make any reference to forceActionLink, let alone in a class. What leads you to believe this selector is the right one? – Adrian Larson Apr 17 '18 at 9:11
  • Thats because the buton with this markup isn't in the VF, it is a custom button that is on the list of the case, and this custom button call the VF page. I got the markup when inspecting the page, since I can't add any class or id to the button... – dou Apr 17 '18 at 9:19
  • Are you sure it's in the same window? Not in an iframe or anything? – Adrian Larson Apr 17 '18 at 14:07
  • I don't see any ifram or anything... but as I said in the question, I don't know if it was very clear, the button isn't in the VF page where I call the javascript. – dou Apr 17 '18 at 14:12
0

You can not access Apex variable in JavaScript like this.

var isInCommunity ={!isInCommunity};

Correct way to access apex variable in Javascript :

var isInCommunity = '{!isInCommunity}';

  • even if the apex variable is a boolean ? Because if I use the simple quote, then I did not pass into the if, event if the var isInCommunity is true... – dou Apr 17 '18 at 9:15
  • ohh.. Mak sure you call query selector after DOM has loaded. – MIX DML Apr 17 '18 at 9:32
  • Well I try to call first window.onload but same problem... – dou Apr 17 '18 at 9:35
  • can you show me DOM code of forceActionLink ? – MIX DML Apr 17 '18 at 9:39
  • I editedt mu question with a copy of the dom for the button – dou Apr 17 '18 at 9:47

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.