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
MaxploreMaxplore 

Creating custom object records and setting custom fields from Flex

I am trying to create a record in Custom object "RMA_Shipment_Order" and trying to set a custom field "Case" which is a lookup field pointing to Case object.
 
If I dont set the custom field while calling the "create" method, then the record gets created in the custom object. But if I set the custom field, then I dont get any error but at the same time record also doesnt get created. Here is the code cnippet of what I am doiing.
 
// Appending "__c" since its a custom object
 var acc:SObject = new SObject('RMA_Shipment_Order__c');
  
// Appending "__c" since its a custom field. Please note that I am setting a valid Case number which exists
    acc.Case__c = "0010023";
    apex.create([acc], new AsyncResponder(
     function (result:Object):void {
      ta.text   += 'createResult\n' + ObjectUtil.toString(result);
    }, genericFault
   ) );
Can anyone please respond to this?  
SuperfellSuperfell
0010023 is a case number, not a case Id, Ids are 18 characters long.
MaxploreMaxplore
Thanks. That did the trick.
But my next question is how to get the 18 characters identifier for the case number.
I want to make the call from the API and wont have access to the URL where that 18 characters ID is displayed.
Ron HessRon Hess
the result object ( from the create() ) has the new ID in it

MaxploreMaxplore
No. I think you misunderstood my question.
What I want to ask is while creating a record in custom object, if I want to pass the 18 digit unique identifier of Case number, how will I get it programmatically using API?
SuperfellSuperfell
Assuming your case numbers are unique, you could query for it (select id from case where casenumber='xxx'). But where are you getting the case number from ? (and can't that give you the case Id instead?)
MaxploreMaxplore

Thanks for letting me know.

We will be putting a popup control from where user will be selecting the case number. I guess when we are populating the case number using the SOQL query, at that point of time, we will fetch the ID of the case numbers also and pass both the case number and ID to the main form and then can use the create method for creating the record in custom object.

Can you validate this approach or do you have some better idea?

 

Ron HessRon Hess
that will work just fine, and follows best practice, which is fetch all you need with your first query and pass it along to where it will be used.


MaxploreMaxplore
Thanks for confirming this.