- Home
- Technical Library
- Partners
- Blog
- Ideas
- Code Share
-
Discussion Boards
- Announcements
- General Development
- New to Cloud
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules Discussion
- Security
- Force.com Sites
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby Development
- Adobe Flash Builder for Force.com
- Desktop Integration
- Apple, Mac and OS X
- VB and Office Development
- Excel Connector
- AJAX Toolkit & S-controls
- Force.com Builder & Native Apps
- AppExchange Directory & Packaging
- Force.com Labs Projects
- Open Source
- Jobs Board - Developer
- Job Board - Administrators
- More
Discussions
- Announcements
- General Development
- New to Cloud Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules Discussion
- Security
- Force.com Sites
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby Development
- Adobe Flash Builder for Force.com
- Desktop Integration
- Apple, Mac and OS X
- VB and Office Development
- Excel Connector
- AJAX Toolkit & S-controls
- Force.com Builder & Native Apps
- AppExchange Directory & Packaging
- Force.com Labs Projects
- Open Source
- Jobs Board - Developers
- Jobs Board - Administrators
- Force.com Discussion Boards
- :
- Developer Boards
- :
- Apex Code Development
- :
- Call an Apex class from a button
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Call an Apex class from a button
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-01-2007 06:31 AM
global class MyHelloWorld {
WebService static void doKPI() {
INTEGER NUM = 10;
KPI__c[] tblkpi;
tblkpi = new KPI__c[NUM];
for (integer i = 0; i < NUM; i++) {
tblkpi[i] = new KPI__c(UserName__c='user '+i, Signed_Contracts__c = i);
}
insert tblkpi;
}
}Solved! Go to Solution.
Re: Call an Apex class from a button
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-01-2007 11:14 AM
I think you might need to include the connection.js and apex.js files at the top of your button JavaScript:
Code:
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
If that doesn't fix your issue, you take a look at the Force.com Cookbook -- there's a recipe called "Creating a Button with Apex" on page 141 that shows a working example of a JavaScript button executing an Apex Web Service method -- perhaps there's something else in that example that will help you.
ADN members can download the book for free at http://wiki.apexdevnet.com/index.php/Members:Cookb
Hope that helps!
Caroline Roth
Co-Author, "Force.com Cookbook"
Re: Call an Apex class from a button
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-02-2007 03:00 AM
Thanks very much Caroline - that worked!
I was working from the salesforce_apex_language_reference.pdf document yesterday and nowhere in that does it tell me the answer you just gave me. I recommend that the document be updated to include that example so other beginners don't get stuck on such a trivial problem.
Thanks again!
Re: Call an Apex class from a button
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-02-2007 09:15 AM
Cheers,
Caroline
Re: Call an Apex class from a button
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
03-24-2009 01:24 AM
Really Share n Dicuss among community members is Bottom Line of learning :)
Re: Call an Apex class from a button
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-21-2009 03:16 PM
Does anyone know if this method should work in the Customer Portal? I've had success with using this method on a normal SF user account, but keep getting the following error when executed from the CP:
A problem with the OnClick JavaScript for this button or link was encountered:
{faultcode:'sf:INSUFFICIENT_ACCESS', faultstring:'NOCPortalSubmitForReview: no access allowed to this class.', }
Re: Call an Apex class from a button
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-25-2010 11:48 PM
Have you enabled the apex class for the customer portal profile in question?

