You need to sign in to do that
Don't have an account?
Sudipto Ghosh 12
Code Issue while running of a Trigger
I have 2 Custom Objects 'Job_Posting__c' and 'Employment_Website__c'.
'Employment_Website__c' is the master object and 'Job_Posting__c' is the child object of the Master Detail Relationship.
I want to write a Trigger so that whenever there is a change in a Field 'Price_Per_Post__c' of the 'Employment_Website__c' Object, the 'City__c' Field of all the related (Child) records gets changed to 'Atlanta'.
This is the code I wrote:
trigger ChangingChildValue on Employment_Website__c (after insert, after update) {
Job_Posting__c JP = new Job_Posting__c();
for (Employment_Website__c EMP : Trigger.old)
{
System.debug('Price Per Post' + EMP.Price_Per_Post__c);
if(EMP.Price_Per_Post__c > 50){
JP.City__c = 'Pune';
}
}
update JP;
}
I am getting the below error when I change the Price Value and Save the parent record:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger ChangingChildValue caused an unexpected exception, contact your administrator: ChangingChildValue: 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: []: Trigger.ChangingChildValue: line 11, column 1
I am new Development, any help would be really great. Thanks.
'Employment_Website__c' is the master object and 'Job_Posting__c' is the child object of the Master Detail Relationship.
I want to write a Trigger so that whenever there is a change in a Field 'Price_Per_Post__c' of the 'Employment_Website__c' Object, the 'City__c' Field of all the related (Child) records gets changed to 'Atlanta'.
This is the code I wrote:
trigger ChangingChildValue on Employment_Website__c (after insert, after update) {
Job_Posting__c JP = new Job_Posting__c();
for (Employment_Website__c EMP : Trigger.old)
{
System.debug('Price Per Post' + EMP.Price_Per_Post__c);
if(EMP.Price_Per_Post__c > 50){
JP.City__c = 'Pune';
}
}
update JP;
}
I am getting the below error when I change the Price Value and Save the parent record:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger ChangingChildValue caused an unexpected exception, contact your administrator: ChangingChildValue: 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: []: Trigger.ChangingChildValue: line 11, column 1
I am new Development, any help would be really great. Thanks.
Please see below code.
Hope this helps you!
Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
Thanks and Regards
Sandhya
It is not working it showing an 'Unexpexted Token: List' error on the below line:
'List<Employment_Website__c> updatedew = [SELECT Id, EMP.Price_Per_Post__c,(Select Id,JP.City__c,from Job_Posting__c) FROM Employment_Website__c WHERE Id in :ids];
please replace that line with below.
Thanks and Regards
Sandhya
Thanks and Regards
Sandhya
I modified my original code, now I am not gettiny any error in the below code but the city value is also not getting updated:
trigger ChildValueChange on Employment_Website__c (after insert, after update, before insert, before update) {
List<Job_Posting__c> LJP = new List<Job_Posting__c> ();
Set<ID> EmpID = new Set<ID> ();
for(Employment_Website__c EW : Trigger.new){
EmpID.add(EW.Id);
}
LJP = [SELECT Price_Per_Post__c, City__c FROM Job_Posting__c WHERE Id in :EmpID];
List<Job_Posting__c> JPUpdate = new List<Job_Posting__c> ();
for(Job_Posting__c ejc : LJP){
if ( ejc.Employment_Website__r.Price_Per_Post__c > 50){
ejc.City__c = 'Pune';
JPUpdate.add(ejc);
}
}
update JPUpdate;
}