You need to sign in to do that
Don't have an account?
Rahul
hello friends, Iam getting this error while saving the record.System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Please find the full error below. Need your help
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, bucket1associatetobucket2: execution of AfterInsert caused by: System.TypeException: Invalid id value for this SObject type: a14p000000275tEAAQ Trigger.bucket1associatetobucket2: line 35, column 1: []
Bucket1__c is parent and Bucket_2__c is child.Iam trying to create buckel1 record and when borower_name__c is null , then create bucket_2__C record and associate it with parent which is bucket1__c.
Please help to solve this error.
Please find my code below :-
trigger bucket1associatetobucket2 on Bucket1__c (after insert) {
map<string,id> conEmailVsId = new map<string,id>();
List<Bucket_2__c> newbuck2 = new list<Bucket_2__c>();
if(Trigger.isAfter && Trigger.isInsert) {
for(Bucket1__c a1:trigger.new){
if(a1.Borrower_Name__c == null){
Bucket_2__c bb = new Bucket_2__c();
bb.id=a1.id;
bb.Addhar_Number__c = a1.Aadhar_Number__c;
bb.Name=a1.Name;
newbuck2.add(bb);
system.debug('values in newbuck2'+newbuck2);
}
}
if(newbuck2.size()>0){
insert newbuck2;
}
}
}
Bucket1__c is parent and Bucket_2__c is child.Iam trying to create buckel1 record and when borower_name__c is null , then create bucket_2__C record and associate it with parent which is bucket1__c.
Please help to solve this error.
Please find my code below :-
trigger bucket1associatetobucket2 on Bucket1__c (after insert) {
map<string,id> conEmailVsId = new map<string,id>();
List<Bucket_2__c> newbuck2 = new list<Bucket_2__c>();
if(Trigger.isAfter && Trigger.isInsert) {
for(Bucket1__c a1:trigger.new){
if(a1.Borrower_Name__c == null){
Bucket_2__c bb = new Bucket_2__c();
bb.id=a1.id;
bb.Addhar_Number__c = a1.Aadhar_Number__c;
bb.Name=a1.Name;
newbuck2.add(bb);
system.debug('values in newbuck2'+newbuck2);
}
}
if(newbuck2.size()>0){
insert newbuck2;
}
}
}
In that case you will be having lookup of bucket 1 on bucket 2 right.
so while inserting the record you write the below line
bb.LOOKUPFIELD_APINAME=a1.id;
LOOKUPFIELD_APINAME is the api name of the lookup field on bucket 2 referencing bucket 1.
All Answers
Here you are trying to insert Bucket_2__c bb on insert of Bucket1__c. Please the comment the below line in your code.
bb.id=a1.id;
You cannot assign Id to a record which is being inserted from trigger
Mark the answer if it solves your query.
In that case you will be having lookup of bucket 1 on bucket 2 right.
so while inserting the record you write the below line
bb.LOOKUPFIELD_APINAME=a1.id;
LOOKUPFIELD_APINAME is the api name of the lookup field on bucket 2 referencing bucket 1.