Creating a new SugarBean with a pre-created UUID

I have a custom API endpoint that we use to send a large number of records at a time. The endpoint works for updating records and inserting new records without a pre-created UUID, but when we send records with a pre-created UUID, we get the UUID back as a response, but the record is not written into the database.

To answer the questions this is going to cause, we do not use the bulk API endpoint due to a performance issue, since it is a http request to make multiple http requests. Also, we are a SugarCloud client so there is a 20 requests a minute limit, which is easy to violate. 

Does anyone have any insight as to why SugarBean might have an issue with new records with pre-created UUIDs?

Here is the code for the custom endpoint.

    public function setEntriesMethod($api, $args)
    {
        if (empty($args)) {
            return false;
        }
        $results = array();
        foreach ($args as $module => $records) {
            if (is_array($records)) {
                foreach ($records as $fieldsArray) {
                    $sugarBean = $this->_processEntry($module, $fieldsArray);
                    $results[$module][] = $sugarBean->id;
                }
            }
        }
        return $results;
    }

    private function _processEntry($module, $fieldsArray)
    {
        $Logger = Factory::getLogger('default');
        if (array_key_exists('id', $fieldsArray)) {
            $sugarBean = BeanFactory::retrieveBean($module, $fieldsArray['id']);
            if (is_null($sugarBean)) {
                $Logger->debug('Record ' . $fieldsArray['id'] . ' does not exist');
                $sugarBean = BeanFactory::newBean($module);
            }else{
                $Logger->debug('Record ' . $fieldsArray['id'] . ' does exist');
            }
        } else {
            $sugarBean = BeanFactory::newBean($module);
        }
        if (is_null($sugarBean)) {
            return null;
        }
        foreach ($fieldsArray as $field => $data) {
            $sugarBean->$field = $data;
        }
        $sugarBean->save();
        return $sugarBean;
    }

Parents Reply Children