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
Jan MattesonJan Matteson 

Javascript Button doesn't work from Partner Communities

I will be implementing Partner Communities. I am testing in a dev org to confirm functionality. I have a Button on the Contact that executes javascript. It works fine from the internal org but gives this error from the community:

A problem with the OnClick JavaScript for this button or link was encountered:

{faultcode:'UNKNOWN_EXCEPTION', faultstring:'UNKNOWN_EXCEPTION: Site under construction', }

The button code is
var dob = '{!Contact.Birthdate}';
var sal = '{!Contact.Annual_Income__c}';
var plandate = '{!Contact.Date_Entered_Plan__c}';
var inflation = '{!Contact.Expected_Raise_Per_Year__c}';

if( dob == '' || sal == '' ||inflation == '' || plandate == '')
alert('Please Validate Birthdate/Annual Income/Date Entered Plan/Expected Raise Per Year/ Spouse DOB');

sforce.apex.execute("GeneratePensionReport","attachReport", {id:"{!Contact.Id}"});
window.alert("Pension Report has been Generated and Attached." );

I think this issue has to do with the context - since it is running from the community it thinks it has a different domain.  Not sure how to address this.
Any help would be appreciiated.

Have create GeneratePensionReport global  and global,static method attachReport and give access to communit this class. May be this info helps you.
Jan MattesonJan Matteson
Hi Ashiekh

Thanks for respoding 

The class is global.  I don;t even think it gets that far. I believe it stops at the REQUIRESJAVASCRIPT because it can't resolve the url.  I have tried putting in the site reference but I haven't found the right answer.  

Here is the class.

global class GeneratePensionReport {
    WebService static void attachReport(id ContId) {
        PageReference pdf = Page.PensionReportPDF;
        Blob b;
            b = pdf.getContent();
            b=blob.valueOf('Text for Testing');
        Attachment attachment = new Attachment();
        attachment.Body = b;
        attachment.Name = String.valueOf('PensionReport.pdf');
        attachment.ParentId = ContId;
        insert attachment;

Jerry ClifftJerry Clifft
Did you get a resolution to this? If not, I think the answer is because Community pages with can not access "soap/ajax/10.0/connection.js" the ajax stuff. You need to make button using apex trigger/class.
Jan MattesonJan Matteson
Yes, I had a developer rewrite it.  Thx
Maureen CassidyMaureen Cassidy
Hi Jan, 
I'm having the exact same problem. Could you please tell me what the problem was with the original button? Thank you!
Jan MattesonJan Matteson
We ended up writing a VF page that was accessed from community
Jerry ClifftJerry Clifft
I had the same issue, I also ended up making a VF. After a bit of research I located the issue:


Those AJAX / . js is not available for a community partner to use. It will work fine with a standard license or an old PRM / Gold partner license, but community licenses do not have access to use them.
We had the same issue and I tried changing the API version to 30.0 and gave the portal users access to the class. This made the Java script button using Ajax worked for us.
SF AdminSF Admin

Same problem. resolved by updating the correct link of the the partner community.
Incorrect -- 

Correct -

Raj kumar RRaj kumar R
Thanks SF Admin. Your pointer resolved the issue..

What I did:
Check JS in the custom button: find navigareToUrl function in your code...then added partnerportal below..

navigateToUrl("/partnerportal/setup/ui/recordtypeselect.jsp?ent=01Ib00000002MnA&retURL=%2F"+varRetId+ ...
Jerry ClifftJerry Clifft
I beleive you can use javascript with your non-community buttons, but javascript will not work with buttons for community sites/users.