+ Start a Discussion
Mike @ BlackTabMike @ BlackTab 

Ajax Toolkit: sObject type 'sObject' is not supported

Hello,

 

In the following javascript, i'm trying to 1.) Query a case 2.) Update a field based on a page parameter. When I try to update the case, salesforce is kicking back an error:

 

failed to update case {errors:{message:'sObject type 'sObject' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.', statusCode:'INVALID_TYPE', }, id:null, success:'false', }

 

Here is the code:

 

  	function chooseRep(id){
            var fieldName = '{!$CurrentPage.parameters.field}';
            
            sforce.connection.sessionId = '{!$Api.Session_ID}';
            var result = sforce.connection.query("SELECT id, Sales_Rep__c, NDS_Assigned__c FROM Case WHERE ID = \'{!$CurrentPage.parameters.id}\'");
            
            
            
            if(fieldName == 'SalesRep'){
                result.records.Sales_Rep__c = id;
            }else{
            	result.recoreds.NDS_Assigned__c = id;       
            }
            
            var result2 = sforce.connection.update([result.records.Id]);
            if (result2[0].getBoolean("success")) {
    			alert("case with id " + result2[0].id + " updated");
  			} else {
    			alert("failed to update case " + result2[0]);
  			}
            
            var previousCase = "{!$CurrentPage.parameters.id}";
            window.location.href = "/" + previousCase;
        }

I'm thinking I need to cast the "result" variable to a case, but i'm not exactly sure how to do that via the Ajax Toolkit.

 

Thanks! 

 

Best Answer chosen by Admin (Salesforce Developers) 
vbsvbs

Mike - Lets see if this works:

 

function chooseRep(id){
            var fieldName = '{!$CurrentPage.parameters.field}';
            
            sforce.connection.sessionId = '{!$Api.Session_ID}';
            var result = sforce.connection.query("SELECT id, Sales_Rep__c, NDS_Assigned__c FROM Case WHERE ID = \'{!$CurrentPage.parameters.id}\'");
            
            var records = result.getArray("records");
            var caseObj = new sforce.SObject("Case");
            caseObj.Id =  records[0].Id;

            if(fieldName == 'SalesRep'){
                caseObj.Sales_Rep__c = id;
            }else{
            	caseObj.NDS_Assigned__c = id;       
            }

            var result2 = sforce.connection.update(caseObj);
            if (result2[0].getBoolean("success")) {
    			alert("case with id " + result2[0].id + " updated");
  			} else {
    			alert("failed to update case " + result2[0]);
  			}
            
            var previousCase = "{!$CurrentPage.parameters.id}";
            window.location.href = "/" + previousCase;
        }

 

All Answers

vbsvbs

Mike - Lets see if this works:

 

function chooseRep(id){
            var fieldName = '{!$CurrentPage.parameters.field}';
            
            sforce.connection.sessionId = '{!$Api.Session_ID}';
            var result = sforce.connection.query("SELECT id, Sales_Rep__c, NDS_Assigned__c FROM Case WHERE ID = \'{!$CurrentPage.parameters.id}\'");
            
            var records = result.getArray("records");
            var caseObj = new sforce.SObject("Case");
            caseObj.Id =  records[0].Id;

            if(fieldName == 'SalesRep'){
                caseObj.Sales_Rep__c = id;
            }else{
            	caseObj.NDS_Assigned__c = id;       
            }

            var result2 = sforce.connection.update(caseObj);
            if (result2[0].getBoolean("success")) {
    			alert("case with id " + result2[0].id + " updated");
  			} else {
    			alert("failed to update case " + result2[0]);
  			}
            
            var previousCase = "{!$CurrentPage.parameters.id}";
            window.location.href = "/" + previousCase;
        }

 

This was selected as the best answer
Mike @ BlackTabMike @ BlackTab

Now i'm getting a different error via the web browsers console:

 

uncaught exception: arg 0 'sObjects' is an array. But passed in value is not an array

 

When I tested it, I confirmed I was getting a record returned from that specific query. 

vbsvbs
Can you confirm what line this refers to?
Mike @ BlackTabMike @ BlackTab

It's the var result2 = sforce.connection.update(caseObj); line.

 

I also tried: var result2 = sforce.connection.update(caseObj.Id);

 

But that rendered the same result. 

Mike @ BlackTabMike @ BlackTab

Got it working: It needed to change the sforce.connection.update([caseObj]);