+ Start a Discussion
stephen_m_woodstephen_m_wood 

Record insert doesn't take properly

Hi guys,

I have a custom object which I use to store link information to our other systems.  I can insert records (pretty much using an exact copy of the example code provided) and it works fine.  However:

The record doesn't show in any other linked lists until I manually go to the record and click on the 'Edit' button.

I don't need to edit, or even click cancel, I just need to open the record in the edit view.  If I do this, the record takes and is viewable in all of the linked lists.

Has anyone seen this before.  It's almost like the record has not been commited to the system - trouble is - I can't see how you commit using the API (or the examples).

Any help is much appreciated.

Steve
DevAngelDevAngel
Well, we don't have the concept of commit in the API.  Why don't you post the code that sets the values on your object just prior to including in the create call.
stephen_m_woodstephen_m_wood
Hi DevAngel,

The code is:

    public void updateSpark(String salesforceSparkID, Design design)
    {
        int size = designs.size();
       
        SObject[] sparks = new SObject[size];
       
        for (Iterator i = designs.iterator(); i.hasNext();)
        {
            ComboItem comboItem = (ComboItem)i.next();
           
            String salesforceSparkID = comboItem.getIndex();
            Design design = (Design)comboItem.getObject();
           
            sparks[count] = new SObject();
            sparks[count].setType(SPARK_OBJECT);
            sparks[count].set_any(createSparkMessage(design));
           
            if (salesforceSparkID != null && salesforceSparkID.trim().length() > 0)
            {
                sparks[count].setId(salesforceSparkID);
            }
           
            count++;
        }
       
        SaveResult[] saveResult = null;

        try
        {
            // If the spark doesn't exist, then create it
            saveResult = binding.create(sparks);
        }
        catch (Exception ex)
        {
            System.out.println("An unexpected error has occurred." + ex.getMessage());
            return;
        }
       
        for (int j = 0; j < saveResult.length; j++)
        {
            if (saveResult[j].isSuccess() == false)
            {
                // there were errors during the create call, go through the errors
                // array and write them to the screen
                for (int i = 0; i < saveResult[j].getErrors().length; i++)
                {
                    // get the next error
                    com.sforce.soap.partner.Error err = saveResult[j].getErrors()[i];
                   
                    System.out.println("Errors were found on item " + new Integer(j).toString());
                    System.out.println("Error code: " + err.getStatusCode().toString());
                    System.out.println("Error message: " + err.getMessage());
                }
            }
        }
    }

Nothing too fancy, so hopefully it makes sense.  At the moment, the spark will never exist, so it's always an insert (or create).  So by that, the sparks[count].setId(salesforceSparkID); code is never called.

Any help is very much appreciated.

Cheers,

Steve

Message Edited by stephen_m_wood on 05-02-2006 12:16 PM

DevAngelDevAngel
Well, that didn't shed much light.  A bit confused as to why you pass a Design object to the function, but that won't affect the issue.

I wonder if there is something about your Design object from the designs collection that might be unusual.  Could you post a screen shot of the custom object from sforce explorer (or the eclipse explorer) so that I can attempt to reproduce this behavior?
stephen_m_woodstephen_m_wood
Thanks DevAngel,

Screen-shot here:
http://www.informavores.com/salesforce/sparkobject.gif

The design object is passed in simply because we're still developing the function - it will be used eventually!

Thanks a lot for your help.

Cheers,

Steve
stephen_m_woodstephen_m_wood
I'm assuming by the lack of response on this one that it's a bug in the salesforce.com API?

I'm not sure what to do - we can't launch our app with this error!

Any help is much apprciated.

Cheers,

Steve
SuperfellSuperfell
I didn't follow the earlier steps to re-produce this, can you describe the problem in a little more detail? You're saying that you need to edit the object before it'll appear on a related list ?
stephen_m_woodstephen_m_wood
Hi Simon,

I'll try to explain the process is a bit more detail.  Once we execute the code, everything works fine (in terms of the code that is - no errors, messages, etc).  The code should have inserted an new Spark record in to our salesforce.com developer account.  However, when we log in to the salesforce account (as an end user), we noticed the following:

1.  We click on our 'Interviews' tab
2.  We click on 'New' to open the edit form
3.  On the form there's a field called 'Spark' which has a 'Lookup'
4.  We click on the little magnifying glass to open the lookup
5.  The record doesn't show in the list, can't be searched - it's just not there

However, if we do the following:

1.  Click on the 'Sparks' tab
2.  At this stage, the newly inserted spark does not show in the list below
3.  If we click on 'Go', it then shows in the list of results
4.  We can then see the inserted record, so we then click on the 'Edit' link
5.  We do nothing else, but click back on the 'Interviews' tab again - nothing, no 'Save', no 'Save & New', no 'Cancel' - we just click straight through to the 'Interviews' tab
6. We create a 'New' interview as before
7. We click on the little magnifying glass for 'Spark' to open the Lookup dialog
8. Hey presto, it's there!

That's it.  So it's a bit of a problem obviously as it's not going to be a very effective way of updating our database!

Help with this is much appreciated as we're really anxious to get this completed.

Cheers,

Steve

SuperfellSuperfell
The records are there, however many of the UI feature you mention are defaulted from the MRU (Most Recently Used) list. For example, i setup a spark cusom object the same as yours, and set the name autonumber field format to be SN-{000}. I created a new record from the API. When i click on the lookup for spark from the other custom object, the lookup list is empty, however if i enter SN* as the search criteria, my new record will appear. The recent list on the sparks tab page is similarly driven by the MRU.
Now the good news, you can control whether your API insert affects the MRU or not, there's a soap header called MruHeader, it has an updateMru property, set this to true, and the insert via the API will now also update the MRU, which means it'll appear straight away on the lookup windows, and in the recent tab on the custom tab. (along with the an entry in the MRU list on the left hand side of the window).

In java its something like this (do this once after login, or something similar)
MruHeader mru = new MruHeader();
mru.setUpdateMru(true);
stub.setHeader("urn:enterprise.soap.sforce.com", "MruHeader", mru);
....
stub.create ...