You need to sign in to do that
Don't have an account?
Apex/OnClick JavaScript Button Error
We have the below custom button on opportunities:
{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/19.0/apex.js")}
var eQuoteEndpoint = sforce.apex.execute("UAUpdate","GenerateEQ",
{user_id:"{!Opportunity.OwnerId}",opp_id:"{!Opportunity.Id}"});
//var eQuoteEndpoint = //'URL REDACTED' + "token=//{!User.Quote_Token__c}" + "&opportunityId={!Opportunity.Id}";
console.log(String(eQuoteEndpoint));
window.open(String(eQuoteEndpoint));
Every so often it gives the below error:
A problem with the OnClick JavaScript for this button or link was encountered:
{faultcode:'soapenv:Client',
faultstring:'System.QueryException: LIst has no rows for assignment to SObject
Class.UAUpdate.GenerateEQ: line 9, column 1', }
As far as I can tell, it is referencing the below Apex class (only pasted until line 9 out of 184).
global class UAUpdate{
public static boolean isApexTest = false;
WebService static String GenerateEQ(String user_id, String opp_id){
// Perform SOQLs to obtain relevant information.
User user = [SELECT Id, Quote_Token__c FROM User WHERE Id = :user_id LIMIT 1];
Opportunity opp = [SELECT Id, AccountId FROM Opportunity WHERE Id = :opp_id LIMIT 1];
Account account = [SELECT Id, Name FROM Account WHERE Id = :opp.AccountId LIMIT 1];
Contact contact = [SELECT Id, Email, FirstName, LastName, MailingCity, MailingPostalCode, MailingState, MailingStreet, Phone FROM Contact WHERE AccountId = :opp.AccountId LIMIT 1];
Is the class trying to reference a missing record/object? I can't tell what exactly it would be and how to fix it. Would appreciate any help.
global class UAUpdate{
public static boolean isApexTest = false;
WebService static String GenerateEQ(String user_id, String opp_id){
System.debug('---------user_id------->'+user_id);
System.debug('-----------opp_id----->'+opp_id);
// Perform SOQLs to obtain relevant information.
User user = [SELECT Id, Quote_Token__c FROM User WHERE Id = :user_id LIMIT 1];
Opportunity opp = [SELECT Id, AccountId FROM Opportunity WHERE Id = :opp_id LIMIT 1];
System.debug('-----------opp ----->'+opp );
Account account = [SELECT Id, Name FROM Account WHERE Id = :opp.AccountId LIMIT 1];
System.debug('-----------account ----->'+account );
Contact contact = [SELECT Id, Email, FirstName, LastName, MailingCity, MailingPostalCode, MailingState, MailingStreet, Phone FROM Contact WHERE AccountId = :opp.AccountId LIMIT 1];
System.debug('-----------contact ----->'+contact );
And share your log