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
paololimpaololim 

Perl Upsert Problems

Hi There,

 

First time on this board so sorry if this problem has been posed before.  There are a few threads detailing upsert, but no sample code for working stuff in Perl's WWW::Salesforce library.  Here is what I have so far:

 

 

my %account; $account{"type"} = "Account"; $account{"FirstName"} = "NewFirstname"; $account{"LastName"} = "NewLastname"; $account{"RecordTypeId"} = $rti; $account{"My_ID__c"} = $my_id; $result = $sforce->upsert((type => "Account"), "My_ID__c","", (%account)); if ($result->result->{"success"} eq "false") { print $result->result->{errors}->{message} . "\n"; }

 

The reason I have the following as my upsert function: 

$sforce->upsert((type => "Account"), "My_ID__c","", (%account))

 

Is becase it's the only one that does not complain of missing types, keys, etc.  So anyway, when I run my Perl script, I get the following:

 

       Account: bad field names on insert/update call: type

 

What am I doing wrong with my code?  Can someone give me a simple example of how upsert should be used in Perl?

 

Thanks!

BoltonBolton

Check the CPAN docs for WWW::Salesforce.

 

http://search.cpan.org/dist/WWW-Salesforce/lib/WWW/Salesforce.pm


You need to do something like this:

 

 

$sf->upsert(type => 'Account', key => $key, \%account)

 

 

jimmy chenjimmy chen

here is  my working code

 

%upsert = {};

$upsert->{'Account__c'} = 'qwewq';
$upsert->{'Tenant_ID__c'}='qewq';

 

my $res = $sforce3->upsert (type => 'Connected_Cloud_Data__c',key=>'Tenant_ID__c',$upsert);
if ($res->result->{"success"} eq "false") {
print "\n From Update Errors=".$res->result->{errors}->{message} . "\n";
}

 

 

you need to rewrite  "My_ID__c"   as    key =>"My_ID__c"

 

 

ff_tnguyen1.3926886928436838E12ff_tnguyen1.3926886928436838E12
I just finally figured out how to do this in perl.

I have a sub_account object (API name sub_account__c) whose name field is related to a field called gpid (API gpid__c) in Account. gpid__c is of type lookup(Sub Account)

To upsert account that include gpid__c you will need:
external_id from Account, 
external_id from sub_account (that you want to link to account through gpid__c),
and the syntax:

$sforce->upsert(
    type => 'account',
    key => 'external_id__c',    #this is the external id for account, you might have to create it and update Constants.pm
    {
        external_id__c => 10,
        name => 'abcd1234',
        gpid__r =>  {
                                  type => 'sub_account__c',
                                  external_id__c => 6,                            #this is external_id for sub_account 
                              },
        #other data for account goes here
    }
);

Cheers,