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

How to make a custom filed as a primary key filed using Apex trigger

Hello Friends. I have created a  custom field and i need to make it as a primary  key field using Trigger.


Please help[ me in solving this problem.





Simply creaed a custom fields
set it as        


RequiredAlways require a value in this field in order to save a record
UniqueDo not allow duplicate values
  • Treat "ABC" and "abc" as duplicate values (case insensitive)
  • Treat "ABC" and "abc" as different values (case sensitive)
External IDSet this field as the unique record identifier from an external system



or u can write a after triige so u can copy the ID of the record in to u r custom fields






thanks , i need a smple code for this can u help .






Sample code for after trigger ??


trigger testtrg on testobj (After Insert)


 for(integer i = 0 ;i <; i++)[i].primarykeycustomfield__c =[i].Id;