You need to sign in to do that
Don't have an account?
PRASHANT BHARTI
Illegal assignment from Integer to Id
trigger Count_Of_JobApp on job_application__c (after insert,after delete)
{
if((Trigger.isInsert && Trigger.isAfter) || (Trigger.isDelete && Trigger.isAfter))
{
Set<Id> parentIdsSet = new Set<Id>();
List<Position__c> positionList = new List<Position__c>();
if(Trigger.isInsert){
for(job_application__c jobObj : Trigger.new){
parentIdsSet.add(jobObj.Total_Job_Application__c);
}
}else if(Trigger.isDelete) {
for(job_application__c jobObj : Trigger.old){
parentIdsSet.add(jobObj.Total_Job_Application__c);
}
}
System.debug('parentIdsSet-->'+parentIdsSet);
if(parentIdsSet.size() > 0){
positionList = [SELECT Id,
Name,
Count_Of_Job_App__c,
(SELECT Name
FROM job_applications__r)
FROM Position__c
WHERE Id IN : parentIdsSet];
}
System.debug('positionList-->'+positionList);
if(positionList.size() > 0){
for(Position__c postionObj : positionList){
postionObj.Count_Of_Job_App__c = postionObj.job_applications__r.size();//Error on this line.
}
update positionList;
}
}
}
{
if((Trigger.isInsert && Trigger.isAfter) || (Trigger.isDelete && Trigger.isAfter))
{
Set<Id> parentIdsSet = new Set<Id>();
List<Position__c> positionList = new List<Position__c>();
if(Trigger.isInsert){
for(job_application__c jobObj : Trigger.new){
parentIdsSet.add(jobObj.Total_Job_Application__c);
}
}else if(Trigger.isDelete) {
for(job_application__c jobObj : Trigger.old){
parentIdsSet.add(jobObj.Total_Job_Application__c);
}
}
System.debug('parentIdsSet-->'+parentIdsSet);
if(parentIdsSet.size() > 0){
positionList = [SELECT Id,
Name,
Count_Of_Job_App__c,
(SELECT Name
FROM job_applications__r)
FROM Position__c
WHERE Id IN : parentIdsSet];
}
System.debug('positionList-->'+positionList);
if(positionList.size() > 0){
for(Position__c postionObj : positionList){
postionObj.Count_Of_Job_App__c = postionObj.job_applications__r.size();//Error on this line.
}
update positionList;
}
}
}
As i was able to understand your issue, you were having problem in the 9th and 13th line from the top. You have used Set of ID type and assigning a field which most probably is a Numeric field of type Integer. Hence i will suggest you to look below and find the correct solution.
To Summerize i have simple changed the following line to the following line Or you can simply change the assignment to following: Please mark the answer as Best Answer if it helped you :)
Issue is on 30th line of the code.
Still the solution provided by you is not working.
Regards,
Prashant
Kindly do the following changes, it will start working Also if it doesn't work, then please let me know the type of Count_Of_Job_App__c
Mark the Solution as best answer if it helped you in any case :)
Greetings to you!
- I have also added the code to check if postionObj.job_applications__r.size()=0.Now it is dynamic.Please use the below code : -
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
I am getting an erro while inserting a record.
"Apex trigger Count_Of_JobApp caused an unexpected exception, contact your administrator: Count_Of_JobApp: execution of AfterInsert caused by: System.StringException: Invalid id: 1: Trigger.Count_Of_JobApp: line 30, column 1"
Thanks & Regards,
Prashant
From the Exception i assume that Count_Of_JobApp is a relationship field !! Can you confirm the same?
yes Count_Of_JobApp is a relationship field.
Hi Prashant,
I afaik that you have used wrong field type. Here you must use Integer type of field. Kindly change the same, and you will be good to go.
But why will you need to have a Count_Of_JobApp as a relationship field. By the name i can assume that with this you need to have a count. Hence change the Field Type. You can also use RollUp Field where you can count the number of JobApplications easily via a simple Count feature. Kindly have a look at the screenshot in case you need help on the same.
Regards,
Somya Tiwari