0

I embedded visualforce page contains javascript in standard layout.It is working fine when I testing.But when I login as User and test, it is not working at all,there also no error in javascript console.As soon as I logout as user and go to the page,it works.I already granted FLS to the user.Here is my code:

<apex:page standardController="Opportunity" >
  <!-- Remote Objects declaration --> 
    <apex:remoteObjects jsNamespace="RemoteObjectModel">
        <apex:remoteObjectModel name="Opportunity" fields="Id">
            <!-- custom field added to the Contact object -->
            <apex:remoteObjectField name="isFlag__c" jsShorthand="isFlag"/>
        </apex:remoteObjectModel>
    </apex:remoteObjects>
   <script type="text/javascript">
   var flag={!opportunity.isFlag__c};

   if(flag==true){
   var x =confirm("This opportunity has been moved more that three times");
   if(x==true){
      resetFlag();
   }
   }

   function resetFlag(){

     var record= new RemoteObjectModel.Opportunity({Id:'{!opportunity.Id}',isFlag:false});
     record.update(resetFlagCallback);

   }

   function resetFlagCallback(err,ids){

        if (err) { 
           displayError(err); 
        } else {
             var totalPageURL = window.location.toString();
             var protocalType= totalPageURL.split("//")[0];
             var tempbaseURL = totalPageURL.split("//")[1].split("/");
             var finalBaseURL = protocalType+'//'+tempbaseURL[0];

           window.top.location.href=finalBaseURL+"/Opportunty_to_Close?id="+{!opportunity.Id};
        }

   }

  </script>  
</apex:page>

What are possibles step/code that I missed?

4
  • Can you check, if login user profile has access of that embedded VF page?
    – Devendra
    Oct 7 '16 at 7:50
  • Yes, to be sure I enable all Profile for that embedded VF Page.But it's not working.
    – unidha
    Oct 7 '16 at 7:52
  • Okay, then What is the sharing setting for Opportunity object. Does Login User has access to this Opportunity record?
    – Devendra
    Oct 7 '16 at 7:59
  • Yes... The user can view and create Opportunity.I included visualforce inside Opportunity Standard Layout, the dialog box in the code does not popup at all while user view the Opportunity.It doesnot run the script at all, but when I log out as user it's working.
    – unidha
    Oct 7 '16 at 8:03
0

Yes stupid me.I am about to close the question but I am thinking that maybe another people repeat the same mistake.

The root cause is : Page Layout. I did not embed this Visualforce in the user page layout.

Apologize on inconvinience.

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.