You need to sign in to do that
Don't have an account?
chinna r 5
triggers errors
Hi,
Can anyone help me plz?I am trying to insert account record so that related created will b created.Below is the code:
Trigger triggername on Account(after insert){
List<Contact> cclist = new list<Contact>();
for(Account acc:trigger.new){
Contact c = new Contact();
c.LastName__c = acc.LastName__c;
c.accountid = acc.id;
cclist.add(c);
}
insert cclist;
}
I am not able to save the Account record and below is the error.No other Triggers are activated too.
Can anyone help me plz?I am trying to insert account record so that related created will b created.Below is the code:
Trigger triggername on Account(after insert){
List<Contact> cclist = new list<Contact>();
for(Account acc:trigger.new){
Contact c = new Contact();
c.LastName__c = acc.LastName__c;
c.accountid = acc.id;
cclist.add(c);
}
insert cclist;
}
I am not able to save the Account record and below is the error.No other Triggers are activated too.
So as the error says the issue is with duplicate rules there might be already records with the details so it is not possible to reinsert record.
You need to make sure the records entered are not duplicates i.e., they should not be already present in the org, so to make it unique you can make use of a counter or concatinate a unique detail so as to make sure the contact record is unique.
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
Normally, this error relates to the Salesforce's Standard Duplicate rule.
If you have this rule enabled, it'll be showing an alert every time you are trying to create a duplicate record.
And you also haven't filled the required field of contact i.e last name of contact.
This code is working fine in my org.
if(trigger.isafter && trigger.isinsert){
List<Contact> cclist = new list<Contact>();
for(Account acc:trigger.new){
Contact c = new Contact();
c.lastname__c = acc.last_name__c;
c.lastname ='sas';
c.accountid = acc.id;
cclist.add(c);
}
insert cclist;
}