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
sk_nsk_n 

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.

 

 

satya

SRKSRK

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

 

 

 

 

sk_nsk_n

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

 

 

satya

 

SRKSRK

Sample code for after trigger ??

SRKSRK

trigger testtrg on testobj (After Insert)

{

 for(integer i = 0 ;i <trigger.new.sixe(); i++)

      trigger.new[i].primarykeycustomfield__c =  trigger.new[i].Id;

}