Obama '08

               
   

Go Back   Mike Simonds > Salesforce > Salesforce Coding Discussions

This is a discussion on Issues with history tracking / xsd:date within the Salesforce Coding Discussions forums, part of the Salesforce category; So I am a bit stuck on updating a custom object who

Reply
 
LinkBack Thread Tools Rate Thread
  #1  
Old 08-24-2007, 12:15 PM
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:
Quote:
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2  
Old 08-24-2007, 03:45 PM
Administrator
 
Join Date: May 2007
Posts: 248
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 08-24-2007, 06:27 PM
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;
    
    } 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 08-24-2007, 10:45 PM
Administrator
 
Join Date: May 2007
Posts: 248
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5  
Old 08-26-2007, 07:12 PM
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6  
Old 08-27-2007, 02:05 PM
Administrator
 
Join Date: May 2007
Posts: 248
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike

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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7  
Old 08-27-2007, 04:31 PM
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8  
Old 08-27-2007, 04:44 PM
Administrator
 
Join Date: May 2007
Posts: 248
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump



Powered by vBulletin


SEO by vBSEO 3.2.0 RC8 ©2008, Crawlability, Inc.

1 2 3 4 5