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
Pavel_KhrapkinPavel_Khrapkin 

hot to check if new entered text field is matching the existing one in another record?

I have common problem which could be clear for more experienced developers: At the Save moment I'd like to check is the field in new record (for example the good serial number - SN) is already exist in another object list. If Yes, I should pickup the existing record Id. Else (if not exist) -- to create a new record. 

Sean TanSean Tan

Based off you're workflow it sounds like you'll want to mark your custom field as an "External Id" field, and then just use an upsert call against that field.

 

Upsert will handle doing an update to the record if the external id is already used, otherwise it will insert a new one.

Pavel_KhrapkinPavel_Khrapkin
Thanks for the advice! If I not mistaken, you tell it on the Informatika Data Loader language :) I also use it over few years. However, now I'm trying to relocate my Excel based application into Visualforce environment. Excel + Data Loader is indeed very good for the PC based data handling and upload to the Cloud on the final stage. However, for more interactive work I'd prefer APEX. Am I right?




Отправлено с устройства Samsung
Sean TanSean Tan

Data Loader is not a language. It's a tool that was written to talk to the Force.com API. Apex is a language that was written by Salesforce that also uses calls to the Force.com API.

 

That being said, that also means in Apex you can use the upsert command on external Id fields. So rather then reinvting the wheel, you probably just want to leverage functionality that already exists. If you really want to do it yourself you can, but I don't see a reason too...

 

Here is an example on how to upsert on an external Id field from Apex.

 

Contact c = new Contact(LastName='Testing');

//Assume the external Id field is External_Id__c
upsert c External_Id__c;

 

RocketRocket

Hi Sean,

 

 

Just assume there is a bidirectional flow of data between two systems.For example,salesforce is integrated with sap or peoplesoft.

 

Scenario 1:-

 

Somebody saves record in salesforce and that information is forwarded to sap .Now, we need to use external's ids in sap to see if record already exists in sap  if it does then record is updated else it is inserted.Now some record is created or updated in sap then same procedure should be repeated  in salesforce and record should be upserted based on external id's in salesforce.

 

Theoretical ,I can think of this .However,In external id field in salesfoirce,Am i suppose to store unique value of sap in it?.Is that correct? and in sap unique id's of salesforce .

 

If u know ,can u please explain with an example,Just about external id's .

 

 

 

 

 

 

Pavel_KhrapkinPavel_Khrapkin
Thank you for clarification indeed!
Yes, I supposed you used the words "external Id" and "upsert" from
Informatika DL, however these terms are in Force platform! Excellent!!
I'm reading Visualforce Workbook now; it is rather about markup and MVC.
Possibly I should jump to another Guide where APEX record manipulation
covered? Your advice is appreciated.