I have a o problem with invoke controller class, after click button on related list. I tried do this with JS - var result = sforce.apex.execute("MyClass", "myMethod",{customObjectId: customObjectId}) - but then js error ocured. I tried to simply implement visualforce page: apex:page standardController="CustomObject" extensions="MyClass" - then I have:

common.apex.runtime.bytecode.BytecodeApexObjectType cannot be cast to common.apex.runtime.impl.ApexType



if({!Member__c.Id}!=Null)  { 
alert("This is {!Member__c.Id}");  }


global class CheckSomething {
    public Member__c member;
    public ApexPages.StandardSetController  stdController { get; set; }

    public CheckSomething(ApexPages.StandardSetController  ctrl){
       stdController = ctrl;
       member = (Member__c) stdController.getRecord();

    webservice void String myMethod(String accId) 
        System.debug('### service works: ' + accId);


<apex:page standardController="Member__c" extensions="CheckSomething">

Any ideas, how can I do this?

  • are you using this on standard user object? Jul 21 '16 at 9:58
  • No, I am using only customs.
    – Ralph For
    Jul 21 '16 at 10:05
  • Could you please post the complete code? Also the object name on which you or building the button? Jul 21 '16 at 10:06
  • >global class CheckSomething { > public Member__c Member; >public ApexPages.StandardSetController stdController { get; set; } >public CheckSoemthing(ApexPages.StandardSetController ctrl){ >stdController = ctrl; > Member = (Member__c) stdController.getRecord(); > } > > webservice void String myMethod(String objectId) { > System.debug('### service works: ' + objectId); > } >} <apex:page standardController="Member__c" extensions="CheckSomething" > </apex:page>
    – Ralph For
    Jul 21 '16 at 10:12
  • 1
    Please edit the post and add code.. Code in COmments is impossible to read Jul 21 '16 at 10:21

Just in case you do want to get this going, I can point out a few errors that would have prevented this working for you. Since you are actually running javascript, you should declare all your bindings as javascript vars as evaluate them as strings:

Change your code to:

var memberId = '{!Member__c.Id}';
//I'm not sure exactly what member id will resolve to if null 
//but this truthy test should work.
    alert("This is member Id: " + memberId);

Note the difference in the function call also - you need to pass it valid JSON to call the method, in the form of {parameterName:parameter}

Also, your webservice method definition seems wrong too - you have defined the return type as webservice void String myMethod(String accId) but I think you wanted webservice String myMethod(String accId) or webservice void myMethod(String accId)

  • Thanks a lot. As I said - I've done it in different way, but for the future I will keep your solution, thanks!
    – Ralph For
    Jul 22 '16 at 9:08

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.