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
WrogWrogWrogWrog 

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

 
(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
briano.ax404briano.ax404

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

BritishBoyinDCBritishBoyinDC

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

 

It's probably quicker to just pass the object id field already available as a merge field to the class, and do a SOQL query in the class for the Opportunity, and then use that to create the Shipment...