+ Reply to Thread
Results 1 to 8 of 8

Thread: Issues with history tracking / xsd:date

  1. #1
    zerodiv is offline Junior Member
    Join Date
    Aug 2007
    Posts
    4

    Issues with history tracking / xsd:date

    So I am a bit stuck on updating a custom object who has history turned on.

    I have tried:
    - clearing out the fields $sobj->fields->fieldname = null;
    - setting fields to null:


    $setting->fieldsToNull = array( 'CreatedDate', 'CreatedById',
    'LastModifiedDate', 'LastModifiedById', 'SystemModstamp' );


    Both techniques end up with the same salesforce result message:
    stdClass Object
    (
    [errors] => stdClass Object
    (
    [fields] => Array
    (
    [0] => CreatedDate
    [1] => CreatedById
    [2] => LastModifiedDate
    [3] => LastModifiedById
    [4] => SystemModstamp
    )

    [message] => Unable to create/update fields: CreatedDate, CreatedById, LastModifiedDate,
    LastModifiedById, SystemModstamp. Please check the security settings of this field and verify
    that it is read/write for your profile.
    [statusCode] => INVALID_FIELD_FOR_INSERT_UPDATE
    )

    [id] =>
    [success] =>
    )
    Any ideas / suggestions?

  2. #2
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    If you are performing an update then you need to have the Id field from
    the custom object in order to make the other fields null.

    I have never set any of those fields to null due to those fields being set by Salesforce
    whenever you make a change to the record in question so I am not sure that salesforce
    will allow those fields to be Nulled, but you could try it once you get the Id.

    Hope that helps and thanks for joining the site

  3. #3
    zerodiv is offline Junior Member
    Join Date
    Aug 2007
    Posts
    4
    From the function in question.. I do lookup the sobject first:
    PHP Code:
     $sql 'SELECT ' join', '$fields ) . ' FROM Customer_Variable__c WHERE ';
            
    $sql .= ' Account__c = ?';
            
    $sql .= ' AND settingid__c = ?';
            
            try {
                list( 
    $setting ) = $this->__fetchall_sforce_results
    $sql, array( $sf_account->Id$setting_id ) );
            } catch ( 
    Exception $e ) {
                throw 
    $e;
                return 
    null;
            } 
    So... the object does exist.. but has issues with the update once called.



    I'll share the utility functions also:
    PHP Code:
        function __sforce_escape$value ) {
            
    $value str_replace"'"'\\\''$value );
            
            if ( ! 
    is_numeric$value ) ) {
                return 
    "'" $value "'";
            }
            
            return 
    $value;
        }
        
        function 
    __fetchall_sforce_results$raw_query$params = array(), $limit 500 ) {
            
            
    $query $raw_query;
            foreach ( 
    $params as $param ) {
                
    // echo "param : " . $param . "\n";
                // echo "eparam: " . $this->__sforce_escape($param) . "\n";
                
    $query preg_replace'/\?/'$this->__sforce_escape$param ), $query);
                
    // $query = str_replace( '?', $this->__sforce_escape($param), $query );
            
    }
            
            
    // echo "raw_query: $raw_query\n";
            // print_r( $params );
            // echo "query    : $query\n";
            
             // set the limit to 500 per batch
            
    $queryOptions = new QueryOptions($limit);
            
            try {
                
    $response $this->sf_client->query(($query), $queryOptions);
            } catch ( 
    Exception $e ) {
                throw 
    $e;
                return 
    null;
            }
            
            
    $tmp null;
            
            
    // check count to see if we are done
            
    if ($response->size 0) {
                
                
    $tmp = array();
                foreach ( 
    $response->records as $r_obj ) {
                    
    $tmp[] = new SObject($r_obj);
                }
                
                
    // Cycles through additional responses if the number of records
                // exceeds the batch size
                
    while (! $response->done ) {
                    
    // set_time_limit(100);
                    
                    
    try {                  
                        
    $response $this->sf_client->queryMore($response->queryLocator);
                    } catch ( 
    Exception $e ) {
                        throw 
    $e;
                        return 
    null;
                    }
                    
                    foreach ( 
    $response->records as $r_obj ) {
                        
    $tmp[] = new SObject$r_obj );
                    }
                    
                }
                
                return 
    $tmp;
                
            }

            return 
    null;
        
        } 

  4. #4
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15

    Post Cannot update or change those fields

    Okay I did some checking and the reason why you are getting the errors when trying to NULL those fields is that
    those fields cannot be updated or changed via the API. I tried it via the data loader and read the API documentation.
    I thought that this was the case but I wanted to make sure that I was right.


    Unless you read somewhere it states that those fields can be changed!

  5. #5
    zerodiv is offline Junior Member
    Join Date
    Aug 2007
    Posts
    4
    Unfortunatly.. no I am not changing any of those fields. All I do is pull back the sobject and update some of the custom fields I added. So in theory, the individual date fields should be the same as they were dumped in.

  6. #6
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    But according to the error message, you are trying to update or change those records.

    I guess I am just confused on what exactly you are trying to accomplish here, sorry!

  7. #7
    zerodiv is offline Junior Member
    Join Date
    Aug 2007
    Posts
    4
    So, here's the summary of the issue / how to recreate:

    - create custom sobject
    - insert data into said sobject
    - turn history tracking on
    - select sobject out (who will have null tracking info)
    - update sobject

    How I worked around it:
    - select sobject out
    - create new sobject
    - copy all fields across except the protected ones
    - update using that new target object

  8. #8
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    That works, I am glad that you were able to get that to work using another custom Object. Honestly I have never worked with Turning History on so your problem was new to me.

    Thanks for sharing the work around

    ~Mike

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO 3.5.1