You need to sign in to do that
Don't have an account?
Paras Jain
Test class fails...
trigger UpdateSelfLookUpField on npe4__Relationship__c(before insert,before update,after update) {
npe4__Relationship__c acc,acc1;
List<npe4__Relationship__c >acc2=new List<npe4__Relationship__c >();
Set<id> act=new set<id>();
if(trigger.isbefore){
for(npe4__Relationship__c ac: Trigger.new){
acc1=ac;
if( ac.npe4__SYSTEM_SystemCreated__c){
ac.city__c=ac.CityUpdate__c;
ac.Cohort__c=ac.CohertUpdate__c;
ac.Programme__c=ac.ProgrammeUpdate__c;
ac.Placement_Engagement__c=ac.Placement_engagemen_update__c;
ac.Mentor_engagement__c=ac.Mentor_engagement_Update__c;
ac.recordtypeid=ac.Record_Type_parent__c;
ac.Organisation__c=ac.Placement_organisation_Update__c;
ac.Placement_Opportunity__c=ac.Placement_Opportunity_Update__c;
system.debug('@@@@@@@@22222222222'+ac);
}
}
}
if(trigger.isafter){
for(npe4__Relationship__c ac1:Trigger.new){
system.debug('@@@@@@@@>>>>>>>>'+ac1.npe4__SYSTEM_SystemCreated__c);
if(!ac1.npe4__SYSTEM_SystemCreated__c)
system.debug('@@@@@@@@11111111'+ac1.npe4__ReciprocalRelationship__c);
act.add(ac1.npe4__ReciprocalRelationship__c);
} system.debug('@@@@@@@@33333333'+act.size());
system.debug('@@@@@@@@33333333'+act);
if(act.size()>0){
npe4__Relationship__c rl=[Select id,Organisation__c,npe4__Type__c,Type_Update__c from npe4__Relationship__c where id In :act limit 1];
if(rl!=null){
update rl;
}
}
}
}
>>>>>>>>>>>>>>>>>>>>>Test class
@isTest
public class UpdateSelfLookUpFieldTest {
static testmethod void UpdateSelfLookUpFieldTest (){
Account acc=new Account();
acc.name='test';
insert acc;
Contact con=new Contact();
con.lastname='test';
con.firstname='test';
con.accountid=acc.id;
insert con;
npe4__Relationship__c acr=new npe4__Relationship__c();
acr.npe4__Contact__c=con.id;
acr.npe4__Status__c='Current';
acr.city__c='Paris';
acr.Cohort__c='2011';
acr.Programme__c='abc';
acr.Placement_Engagement__c='123';
acr.Mentor_engagement__c='1';
acr.npe4__SYSTEM_SystemCreated__c= false;
insert acr;
npe4__Relationship__c ac=new npe4__Relationship__c();
ac.npe4__Contact__c=con.id;
ac.npe4__Status__c='Current';
ac.city__c='Paris';
ac.Cohort__c='2011';
ac.Programme__c='abc';
ac.Placement_Engagement__c='123';
ac.Mentor_engagement__c='1';
ac.npe4__SYSTEM_SystemCreated__c= false;
ac.npe4__ReciprocalRelationship__c= acr.id;
insert ac;
npe4__Relationship__c ac2=new npe4__Relationship__c();
ac2.npe4__Contact__c=con.id;
ac2.npe4__Status__c='Current';
ac2.city__c='Paris';
ac2.Cohort__c='2011';
ac2.Programme__c='abc';
ac2.Placement_Engagement__c='123';
ac2.Mentor_engagement__c='1';
ac2.npe4__SYSTEM_SystemCreated__c= true;
ac2.npe4__ReciprocalRelationship__c= ac.id;
insert ac2;
npe4__Relationship__c ac3=[Select id,npe4__Status__c,npe4__ReciprocalRelationship__c,npe4__ReciprocalRelationship__r.city__c from npe4__Relationship__c where id=:ac2.id ];
// ac3.npe4__SYSTEM_SystemCreated__c=false;
// ac3.npe4__ReciprocalRelationship__c=acr.id;
//update ac3;
}
}
>>>>>>>>>>>>>>>value not coming in debug.... system.debug('@@@@@@@@11111111'+ac1.npe4__ReciprocalRelationship__c);
npe4__Relationship__c acc,acc1;
List<npe4__Relationship__c >acc2=new List<npe4__Relationship__c >();
Set<id> act=new set<id>();
if(trigger.isbefore){
for(npe4__Relationship__c ac: Trigger.new){
acc1=ac;
if( ac.npe4__SYSTEM_SystemCreated__c){
ac.city__c=ac.CityUpdate__c;
ac.Cohort__c=ac.CohertUpdate__c;
ac.Programme__c=ac.ProgrammeUpdate__c;
ac.Placement_Engagement__c=ac.Placement_engagemen_update__c;
ac.Mentor_engagement__c=ac.Mentor_engagement_Update__c;
ac.recordtypeid=ac.Record_Type_parent__c;
ac.Organisation__c=ac.Placement_organisation_Update__c;
ac.Placement_Opportunity__c=ac.Placement_Opportunity_Update__c;
system.debug('@@@@@@@@22222222222'+ac);
}
}
}
if(trigger.isafter){
for(npe4__Relationship__c ac1:Trigger.new){
system.debug('@@@@@@@@>>>>>>>>'+ac1.npe4__SYSTEM_SystemCreated__c);
if(!ac1.npe4__SYSTEM_SystemCreated__c)
system.debug('@@@@@@@@11111111'+ac1.npe4__ReciprocalRelationship__c);
act.add(ac1.npe4__ReciprocalRelationship__c);
} system.debug('@@@@@@@@33333333'+act.size());
system.debug('@@@@@@@@33333333'+act);
if(act.size()>0){
npe4__Relationship__c rl=[Select id,Organisation__c,npe4__Type__c,Type_Update__c from npe4__Relationship__c where id In :act limit 1];
if(rl!=null){
update rl;
}
}
}
}
>>>>>>>>>>>>>>>>>>>>>Test class
@isTest
public class UpdateSelfLookUpFieldTest {
static testmethod void UpdateSelfLookUpFieldTest (){
Account acc=new Account();
acc.name='test';
insert acc;
Contact con=new Contact();
con.lastname='test';
con.firstname='test';
con.accountid=acc.id;
insert con;
npe4__Relationship__c acr=new npe4__Relationship__c();
acr.npe4__Contact__c=con.id;
acr.npe4__Status__c='Current';
acr.city__c='Paris';
acr.Cohort__c='2011';
acr.Programme__c='abc';
acr.Placement_Engagement__c='123';
acr.Mentor_engagement__c='1';
acr.npe4__SYSTEM_SystemCreated__c= false;
insert acr;
npe4__Relationship__c ac=new npe4__Relationship__c();
ac.npe4__Contact__c=con.id;
ac.npe4__Status__c='Current';
ac.city__c='Paris';
ac.Cohort__c='2011';
ac.Programme__c='abc';
ac.Placement_Engagement__c='123';
ac.Mentor_engagement__c='1';
ac.npe4__SYSTEM_SystemCreated__c= false;
ac.npe4__ReciprocalRelationship__c= acr.id;
insert ac;
npe4__Relationship__c ac2=new npe4__Relationship__c();
ac2.npe4__Contact__c=con.id;
ac2.npe4__Status__c='Current';
ac2.city__c='Paris';
ac2.Cohort__c='2011';
ac2.Programme__c='abc';
ac2.Placement_Engagement__c='123';
ac2.Mentor_engagement__c='1';
ac2.npe4__SYSTEM_SystemCreated__c= true;
ac2.npe4__ReciprocalRelationship__c= ac.id;
insert ac2;
npe4__Relationship__c ac3=[Select id,npe4__Status__c,npe4__ReciprocalRelationship__c,npe4__ReciprocalRelationship__r.city__c from npe4__Relationship__c where id=:ac2.id ];
// ac3.npe4__SYSTEM_SystemCreated__c=false;
// ac3.npe4__ReciprocalRelationship__c=acr.id;
//update ac3;
}
}
>>>>>>>>>>>>>>>value not coming in debug.... system.debug('@@@@@@@@11111111'+ac1.npe4__ReciprocalRelationship__c);
You need to add after insert event in your trigger like below, right now it only has after update, it should work as expected once you add tha.
trigger UpdateSelfLookUpField on npe4__Relationship__c(before insert,before update, after insert,after update) {
Thanks
Shashikant
Please mark it as answer if it helps you so others could be benifitted form it.
0 0 UpdateSelfLookUpFieldTest.UpdateSelfLookUpFieldTest(), Details: System.DmlException: Insert failed. First exception on row 0; first error: ENTITY_IS_DELETED, entity is deleted: [] Class.UpdateSelfLookUpFieldTest.UpdateSelfLookUpFieldTest: line 40, column 1Previous (1 - 1 of 1) NextApex Test Failures
Class Name
Method Name
Error Message
UpdateSelfLookUpFieldTest UpdateSelfLookUpFieldTest System.DmlException: Insert failed. First exception on row 0; first error: ENTITY_IS_DELETED, entity is deleted: []
Stack Trace: Class.UpdateSelfLookUpFieldTest.UpdateSelfLookUpFieldTest: line 40, column 1