1

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

JS:

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}

if({!Member__c.Id}!=Null)  { 
sforce.apex.execute("CheckSomething","myMethod",{!Member__c.Id}"});
alert("This is {!Member__c.Id}");  }

Controller:

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);
    }  
}

Page:

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

Any ideas, how can I do this?

9
  • are you using this on standard user object? Jul 21, 2016 at 9:58
  • No, I am using only customs.
    – Ralph For
    Jul 21, 2016 at 10:05
  • Could you please post the complete code? Also the object name on which you or building the button? Jul 21, 2016 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, 2016 at 10:12
  • 1
    Please edit the post and add code.. Code in COmments is impossible to read Jul 21, 2016 at 10:21

1 Answer 1

0

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.
if(memberId){ 
    sforce.apex.execute("CheckSomething","myMethod",{"accId":memberId});
    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)

1
  • 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, 2016 at 9:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .