-1

Hi I am getting unexpected identifier error for below code. this a javascript added to a custom button on opportunity. Please help on the same

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js" )}     
var opptyId = "{!Opportunity.Id}";    
var connection = sforce.connection;    
integer soCount = [Select count() from csmso__Sales_Order__c WHERE csmso__Opportunity__c = opptyId && csmso__Status__c = 'Externally Approved' || 'Manual Approval'];     
if(soCount >1){ 
alert('Records limit exceeded'); 
}     
else{ 
var result = sforce.apex.execute("Order_PaymentSchedulerController ","createOrder",{oppId:"{!Opportunity.Id}"}); 
alert(result); 
window.location.reload(); 
}

class:

global class Order_PaymentSchedulerController 
{
    webService static String createOrder(Id oppId) {
        Order__c orderRec = new Order__c();
        List<csmso__Sales_Order__c> salesOrders = [Select id,Name,csmso__Status__c from csmso__Sales_Order__c WHERE id =:oppId];
        orderRec.Name = salesOrders[0].Name;
        orderRec.Sales_Order__c = salesOrders[0].Id;
        insert orderRec;  
        return ('Successful : Order Created!');
    }     
}

enter image description here

  • integer soCount... this should be var type and your soql should be in sforce.connection.query – Ratan Paul Aug 10 '16 at 7:25
  • Changed. but still the same error – wizard Aug 10 '16 at 7:27
  • I do not believe that is how you declare and execute a query in button code – Eric Aug 10 '16 at 7:30
1

So this is modified code for you..

try this

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js" )}     
sforce.connection.sessionId = "{!$Api.Session_ID}";
var  soCount = result = sforce.connection.query("Select count() from csmso__Sales_Order__c WHERE csmso__Opportunity__c = '{!Opportunity.Id}' AND csmso__Status__c IN ('Externally Approved' , 'Manual Approval')");  
if(soCount >1){ 
alert('Records limit exceeded'); 
}     
else{ 
var result = sforce.apex.execute("Order_PaymentScheduler","createOrder",{oppId:"{!Opportunity.Id}"}); 
alert(result); 
window.location.reload(); 
}
  • ratan i added your code bu i got error which I have attached – wizard Aug 10 '16 at 7:36
  • now it points out the same Malformed_Query error on 'Externally Approved' OR 'Manual Approval' – wizard Aug 10 '16 at 7:43
  • I have added the latest code with the linked controller class but its giving me an error which I have attaced – wizard Aug 10 '16 at 7:55
  • Let us continue this discussion in chat. – Ratan Paul Aug 10 '16 at 7:58
  • Hi @ratan the sforce.connection.query is not working – wizard Aug 16 '16 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.