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

Apex script to change the ID of employee ID


Iam looking for the apex script to change


Example:  Smith employee id=100;

                    Kevin Employee ID= 200 from employee custom table


Is there any apex script available to change Smith employee id=200 and Kevin Employee ID= 100





Rahul SharmaRahul Sharma
Do you want to swap both the field values?



I need to swap the values




Rahul SharmaRahul Sharma

I have written code for you which swaps the value of field1 and field2 of account object.

Change the object and field API names and run it in developer console.

// Load all the account records in the list
List<Account> lstAccount = [Select Id, Field1__c, field2__c from Account];

// Iterate the list(all records)
for(Account objAccount: lstAccount) {
	// Swap value of the fields
	String strTemp = objAccount.field2__c;
	objAccount.field2__c = objAccount.field1__c;
	objAccount.objAccount.field1__c = strTemp;

// Updating all the records
if(!lstAccount.isEmpty()) {
	update lstAccount;

 Enjoy, Let me know if you need any more help.