You need to sign in to do that
Don't have an account?
Jayesh Deo 2
error encountered on after update trigger.
I tried many times but I am getting below error after updating the recruiter record.Please help.
**recruiter record and Hiring Manager records are having exact same fields**
Error:
SyncRecruiterRecords: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] Class.RecruiterRecordsSyncHandler.AfterUpdate: line 36, column 1 Trigger.SyncRecruiterRecords: line 6, column 1
---------------------------------------------------------------------------------------------
Trigger=Recruiter Object
trigger SyncRecruiterRecords on Recruiter__c (After update)
{
if(trigger.isAfter && trigger.IsUpdate)
{
RecruiterRecordsSyncHandler.Afterupdate(trigger.New);
}
}
---------------------------------------------------------------------------------------------
Trigger Handler Class:
public class RecruiterRecordsSyncHandler
{
Public static void AfterUpdate(List< Recruiter__C> lstrecs)
{
If (!lstrecs.isEmpty())
{
List <ID>HrIds= new List<ID>();
for(recruiter__c rec: lstrecs)
{
HrIds.add(rec.Hiring_manager__c);
}
Map<id, Hiring_Manager__C> mapHrs = new Map<ID,Hiring_MAnager__C>([select id, name,
location__C, email__c,Phone__C from Hiring_Manager__C
where id in : hrIds]);
if(!MapHrs.isEmpty())
{
List<Hiring_manager__C> lstHRS= new list <Hiring_manager__C>();
for(recruiter__c rec:lstrecs)
{
Hiring_Manager__c hr=new Hiring_Manager__c();
hr.Name=rec.name;
hr.Phone__c=rec.phone__C;
hr.Email__c=rec.Email__c;
hr.location__c=rec.location__c;
lstHRS.add(hr);
}
if(!lsthrs.isEmpty())
{
update lsthrs;
}
}
}
}
}
**recruiter record and Hiring Manager records are having exact same fields**
Error:
SyncRecruiterRecords: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] Class.RecruiterRecordsSyncHandler.AfterUpdate: line 36, column 1 Trigger.SyncRecruiterRecords: line 6, column 1
---------------------------------------------------------------------------------------------
- Hiring_Manager__c =Parent Object
- Recruiter__c= Child Object (Lookup relation)
Trigger=Recruiter Object
trigger SyncRecruiterRecords on Recruiter__c (After update)
{
if(trigger.isAfter && trigger.IsUpdate)
{
RecruiterRecordsSyncHandler.Afterupdate(trigger.New);
}
}
---------------------------------------------------------------------------------------------
Trigger Handler Class:
public class RecruiterRecordsSyncHandler
{
Public static void AfterUpdate(List< Recruiter__C> lstrecs)
{
If (!lstrecs.isEmpty())
{
List <ID>HrIds= new List<ID>();
for(recruiter__c rec: lstrecs)
{
HrIds.add(rec.Hiring_manager__c);
}
Map<id, Hiring_Manager__C> mapHrs = new Map<ID,Hiring_MAnager__C>([select id, name,
location__C, email__c,Phone__C from Hiring_Manager__C
where id in : hrIds]);
if(!MapHrs.isEmpty())
{
List<Hiring_manager__C> lstHRS= new list <Hiring_manager__C>();
for(recruiter__c rec:lstrecs)
{
Hiring_Manager__c hr=new Hiring_Manager__c();
hr.Name=rec.name;
hr.Phone__c=rec.phone__C;
hr.Email__c=rec.Email__c;
hr.location__c=rec.location__c;
lstHRS.add(hr);
}
if(!lsthrs.isEmpty())
{
update lsthrs;
}
}
}
}
}
The error you have encountered is because you are attempting to update list of Hiring_Manager__c records without specifying their IDs.
In your RecruiterRecordsSyncHandler class, you are creating new Hiring_Manager__c objects and adding them to a list lstHRS, but you have missed to set their IDs before updating them.
To fix this issue, you need to ensure that you set the IDs of the Hiring_Manager__c records to match the IDs of the corresponding Recruiter__c records.
You can refer below logic:
If this information helps, please mark the answer as best. Thank you
All Answers
The error you have encountered is because you are attempting to update list of Hiring_Manager__c records without specifying their IDs.
In your RecruiterRecordsSyncHandler class, you are creating new Hiring_Manager__c objects and adding them to a list lstHRS, but you have missed to set their IDs before updating them.
To fix this issue, you need to ensure that you set the IDs of the Hiring_Manager__c records to match the IDs of the corresponding Recruiter__c records.
You can refer below logic:
If this information helps, please mark the answer as best. Thank you
Thank you for the Answer.
I got that I was missing to collect only hiring manager record IDs which have associated recruiter records.
I did not implement if() statement suggested because mapHrs collection has already all the associated ID's of recruiter object.(child)
if(!MapHrs.isEmpty())
{
List<Hiring_manager__C> lstHRS= new list <Hiring_manager__C>();
for(recruiter__c rec:lstrecs)
{
Hiring_Manager__c hr=mapHrs.get(rec.Hiring_manager__C);
hr.Name=rec.name;
hr.Phone__c=rec.phone__C;
hr.Email__c=rec.Email__c;
hr.location__c=rec.location__c;
lstHRS.add(hr);