You need to sign in to do that
Don't have an account?
WrogWrog
(the smiley that appears in the code is actually a colon. Why would I ever want to include a **** smiley in any message?)
Message Edited by WrogWrog on 12-12-2008 07:18 AM
Going quietly mad over javascript / apex
I am slavishly trying to follow the many code snippets in cookbooks etc, to try an achieve something simple. I wish to generate a record in my custom object "Shipment" which is linked to a standard object Opportunity. Most examples in the documentation are far more complex than this, but I can't get it to work at all.
The button is on the Opportunity detail form (is that the wrong place?) and should pass the opportunity record into my apex class to insert the record in Shipment__c.
All I get is an error message :
A problem with the OnClick JavaScript for this button or link was encountered:Object doesn't support this property or method
I've had various other error messages whilst creeping forward with versions of this one, some of them seem to "get stuck" with the a given error message appearing, even after I have modified the code to not actually do anything. Is this a bug?
Can anyone help me? You might guess I'm new to this, but I'm not stupid, and I've mimicked code supplied in the Apex code guide (haven't I?). I'd be very grateful.
Roger
Code for button:
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var opportunity= sforce.sObject("Opportunity");
var id sforce.apex.execute("Opportunity_Generate_Shipment","makeShip",{opp:opportunity});
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var opportunity= sforce.sObject("Opportunity");
var id sforce.apex.execute("Opportunity_Generate_Shipment","makeShip",{opp:opportunity});
code for class:
global class Opportunity_Generate_Shipment {
WebService static Id makeShip(Opportunity opp) {
try {
Shipment__c ship = new Shipment__c ();
ship.name = 'name';//opp.name,
ship.Opportunity__c = opp.id;
insert ship;
return ship.id;
}
finally{
}
}
}
WebService static Id makeShip(Opportunity opp) {
try {
Shipment__c ship = new Shipment__c ();
ship.name = 'name';//opp.name,
ship.Opportunity__c = opp.id;
insert ship;
return ship.id;
}
finally{
}
}
}
(the smiley that appears in the code is actually a colon. Why would I ever want to include a **** smiley in any message?)
Message Edited by WrogWrog on 12-12-2008 07:18 AM
Hi Roger,
I have the same problem and am trawling though lots of forums for an answer!!
I have a button on a page layout and I want to pass the record to an APEX class.
Did you get this working?
thanks,
Brian
For this to work, you would need to assign the values you want to use in the apex class to the new sobject Opportunity you create.
So you would need to first say:
opportunity.id = "{!Opportunity.Id}"; opportunity.name = "{!Opportunity.Name}";