You need to sign in to do that
Don't have an account?
Timothy Wade 26
How to enforce that users can only create one record on a custom object?
I created a custom object. How do I enforce that users cannot create more than 1 record on this custom object? Validation rule, flow, trigger???
Check suggestion on this link for refernce:
https://developer.salesforce.com/forums/?id=906F0000000D82jIAC
https://salesforce.stackexchange.com/questions/56187/want-to-restrict-a-user-from-creating-more-than-10-records-w-o-rsf
https://trailhead.salesforce.com/trailblazer-community/feed/0D54S00000A86aESAR
Thanks!
Class__c is a Custom Object
trigger insertTriggerClass on Class__c (before insert) {
insertClass.restrictInsertion(trigger.new);
}
public class insertClass {
public static void restrictInsertion(List<Class__c> classList)
{
try{
Set<Id>classID = new Set<Id>();
for(Class__c c : classList)
{
classID.add(c.Id);
}
List<Class__c> cla = [Select Id from Class__c];
List<Class__c> clas = new List<Class__c>();
for(Class__c con : cla)
{
if(cla.Size() > 0)
{
con.addError('You can not insert the record more than 1');
}
else
{
con.Name='abc';
clas.add(con);
}
}
insert clas;
}catch(Exception e)
{
system.debug('Exception '+e);
}
}
}
Thanks!