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
HeeseHeese 

Best Practice for Inserting and Updating New Custom Object Records?



Hi all,

I am trying to update two objects by inserting new records and updating existing records but am having trouble.  

Account is the Master Object of the Custom Object named Invoices.  
So on the Invoices Object there is a lookup (Master-Detail)Account.  

Here is the scenario, each week I receive a spreadsheet containing all accounts (person Accounts) along with invoices.  So i need to create a new account if it doesn't exist and then create a new invoice if it doesn't exist. If it does exist then i simply need to update the account and invoice.  

The fields on the Invoices object are pubId(an external ID), Price, Total

I am having a very difficult time updating these records.  I am able to update/create new records for the Accounts (Import Person accounts through the UI) but I am having a hard time importing the Invoices.  No matter what I've tried it doesn't seem to create new Invoices.  Is it because I am working with Person Accounts??

Is there a better way to do this?  I have access to DemandTools and the DataLoader.  Thanks in advance.

Ankit AroraAnkit Arora

Correct me if am wrong. You want to update the invoice when account is updated, so when account is updated fetch all invoice related to it and fortunately you have ExternalId. If  that id matches with the value from your XLS then you can just update it else insert it.

 

Do not use upsert.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

HeeseHeese

Hi Ankit,

 

Thanks for the response. I'm afraid there is a little more to it.  

 

I want to be able to insert/update new Account Records And then and subsequently insert/update new invoices.  So when i Receive the spreadsheet to update it only has a unique key on the invoices, unfortunately there isn't one for the account.  

Ankit AroraAnkit Arora

But you said you are able to add/update the account properly, if not then please let me know the exact problem.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

HeeseHeese

Hi Ankit,

 

I am able to update the account (update fields and create new records, etc).  

 

However, when trying to insert and update records for the Custom Object it is only updating the Existing Custom Object records.  It is failing to create new records linked to the Account.  I hope this is more clear. Thanks for the help

HeeseHeese

Sorry I should have included this.  This is the email i receive from support@salesforce.com. Am i receiving this error because I am using Person Accounts?

 



 

 

Result:

Number of Invoices created: 0

Number of Invoices updated: 3,682

Number of locked Jobamatic IDs: 0

Number of Invoices skipped because they had an incorrect Master/Detail relation: 721

 


Ankit AroraAnkit Arora

Make sure when you are inserting the custom object record it is having correct value of account (Id), as I can see account and your custom object have master detail relationship.

 

It is mandatory to fill account id in custom object account reference field.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page