You need to sign in to do that
Don't have an account?
ckellie
Custom Button Error:
I am recieving the following error when I click a custom button that customizes the new button.
Error
A problem with the OnClick JavaScript for this button or link was encountered: sforce is not defined
Custom Button - List Button - Execute JavaScript - OnClick JavaScript
var MPS__c = sforce.sObject("MPS"); var id = sforce.apex.execute("NewMPSGlobal","makeMPS", {MPS_Scheduled_Ship_Date__c: Opportunity.Projected_Ship_Date__c, o:opportunity});
Apex Class:
global class NewMPSGlobal { webService static Id makeMPS( Opportunity o) { MPS__c mps = new MPS__c(MPS_Scheduled_Ship_Date__c= o.Projected_Ship_Date__c, Opportunity__c = o.Id); return mps.id; } }
How do I solve the error?
Thank you
<script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script>
<script src="/soap/ajax/15.0/apex.js" type="text/javascript"></script>
Doc link http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_and_ajax.htm
I was missing that and included them in the button. But I now am seeing the following error:
I am adapting the code from the apex user guide. Here is what I have for the button.
What am I missing?
Thank you
Hi,
1) Why you are initializing two parameters for the method makeMPS().
sforce.apex.execute("NewMPSGlobal","makeMPS",
{MPS_Scheduled_Ship_Date__c: Opportunity.Projected_Ship_Date__c,
o:opportunity});
2) why you need to pass opportunity. just pass the id of the opportunity.
class
global class NewMPSGlobal {
webService static Id makeMPS( id oppid) {
MPS__c mps = new MPS__c(MPS_Scheduled_Ship_Date__c= o.Projected_Ship_Date__c, Opportunity__c = oppid);
return mps.id;
}
}
Button
var sOppid = "{!Opportunityid}";
sforce.apex.execute("NewMPSGlobal","makeMPS",{oppid:sOppid});
Thank you for the help. I am running into syntax problems:
1.
for the recommended code:
I then changed o.Projected_Ship_Date__c to opportunity.Projected_Ship_Date__c
And I recieve the following error:
Both fields are date formatted fields. What is the error and how do I solve it?
Thank you,
Ckellie
You need to include the JS references while calling salesforce API. Tryout the syntax given below :
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}
Thank you, the updated version solved that problem, but I am now experiencing this error:
As I am not familiar with this JavaScript error, I don't know what to do to fix this. Is this concerning the Javascript button or the apex class?
Here is the apex class:
Thank you,
ckellie