You need to sign in to do that
Don't have an account?
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!
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)
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"
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,