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
MAvdiMAvdi 

Upsert multiple values from Flex

Hi

 

I need to upsert an array of objects to salesforce database from flex. here is the code im trying to do it with

Code:
var newItems:Array= new Array();
for(var i:int=0;i<PDetails.authorFeeder.items.length;i++){
//newItem=null;
newItem=new SObject("R_Author__c");
newItem.PID__c=PID.PIDText;
newItem.Author__c=PDetails.authorFeeder.items[i];
newItems.push(newItem);
}
apex.upsert("Name",[newItems], new AsyncResponder( function ():void{
Alert.show("ok seems like authors are saved");
}));

and here is the Debug Message I get

Code:
[DEBUG] com.salesforce.Util Saleforce Soap Fault: sf:INVALID_TYPE
INVALID_TYPE: 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.
5/15/2008 17:18:03.569 [ERROR] com.salesforce.AsyncResponder (com.salesforce.results::Fault)#0
  context = (null)
  detail = (Object)#1
    InvalidSObjectFault = (Object)#2
      column = -1
      exceptionCode = "INVALID_TYPE"
      exceptionMessage = "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."
      row = -1
      xsi:type = "sf:InvalidSObjectFault"
  faultcode = "sf:INVALID_TYPE"
  faultstring = "INVALID_TYPE: 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."

 It seems that the API diesnt accept my array as a SOject or maybe has a problem with array of SObjects
Has anyone esle faced this problem before?
When i replay newItems with newItem in upsert it works fine...

Best Answer chosen by Admin (Salesforce Developers) 
Ron HessRon Hess
try this
Code:
  apex.upsert("Name",newItems, new AsyncResponder( function ():void{
     Alert.show("ok seems like authors are saved");

 
where new items is already an array, i think you had an array of array

All Answers

Ron HessRon Hess
try this
Code:
  apex.upsert("Name",newItems, new AsyncResponder( function ():void{
     Alert.show("ok seems like authors are saved");

 
where new items is already an array, i think you had an array of array
This was selected as the best answer
MAvdiMAvdi
You are absolutly right, didnt think of it :) Thank you!