You need to sign in to do that
Don't have an account?
Error: Compile Error: Unexpected Token
Hi,
I am trying to write a trigger on a custom object called Job Application. It has 2 fields that are lookup type called Candidate and Position. I am trying to write a trigger that would not let the a candidate apply for a position more than once.
Though at this point I am not expecting the code to do what is required, I am quite baffled with the compile error. And am not able to shake it.
The code is given below, getting Error: Compile Error: Unexpected Token: ja.Candidate__c at line 8 column 14
trigger jaduplicate on Job_Application__c (before insert, before update) {
Map <String, Job_Application__C> jamap = new Map <String, Job_Application__c>();
for (Job_Application__c ja : system.trigger.new){
if(ja.Candidate__c != null && ja.Candidate__c != system.trigger.oldMap.get.(ja.id).Candidate__c){
jamap.put(ja.Candidate__c, ja);
jamap.put(ja.Position__c, ja);
} else {
for (ja.Candidate__c == system.trigger.oldMap.get.(ja.id).Candidate__c){
if (ja.Position__c == system.trigger.oldMap.get.(ja.id).Position__c){
ja.Position__c.adderror('Job Application already exists for the candidate');
} else {
jamap.put(ja.Candidate__c, ja);
jamap.put(ja.Position__c, ja);
}
}
}
}
}
Any help or suggestion as to why I am getting the error. And what that error means.
Thanks
KD
Did you intend "for" on line 8, or "if"? -Steve.
Hi Steve, I intended it to be a for loop.
What is a Concrete sObject? The function that I am trying to pass, will it work on fields that are based on the lookup function and not keyed in new.
Thanks
KD
Hi
What i am trying to achieve from this code is that a Candidate can have multiple application but not for the same position again.
The Candidate field is a lookup from the Candiate customer object and the Position field is a look from the Position object. To create an Successfull application I require a Candidate needs to apply for a position only once.
I have used the for loop to check if the candidate value already exists or not, only if it exsits I prefer to check the position value.
I may be wrong with the syntax or the using the right function to call. These are all sandbox tests and I am new to programming and apex.
Thanks
KD
Not sure what you're trying to do, but this line doesn't make any sense
for (ja.Candidate__c == system.trigger.oldMap.get.(ja.id).Candidate__c){
With some suggestions and changes I have been able to compile the code. But I get a system.nullpointerexecution when executing it.
What does that error mean? It talks about de-refrencing an sObject. Please give me some information as to why this error could occur.
It occurs on line 4 column 58
Thanks
Krirshnadas M Rtrigger jaduplicate on Job_Application__c (before insert, before update) { Map <String, Job_Application__C> jamap = new Map <String, Job_Application__c>(); for (Job_Application__c ja : trigger.new){ if(ja.Candidate__c != null && ja.Candidate__c != system.trigger.oldMap.get(ja.id).Candidate__c){ jamap.put(ja.Candidate__c, ja); jamap.put(ja.Position__c, ja); } else { while(ja.Candidate__c == system.trigger.oldMap.get(ja.id).Candidate__c){ if (ja.Position__c == system.trigger.oldMap.get(ja.id).Position__c){ ja.Position__c.adderror('Job Application already exists for the candidate'); } else { jamap.put(ja.Candidate__c, ja); jamap.put(ja.Position__c, ja); } } } } }
I am trying to set a trigger to check that a given candidate does not apply for the same position more than once. What I am trying to do is
Check if the candidate already exists, if true then check for the position applied, if already applied it should give an error if not it should let me save the application.
...and, if you ever did manage to get into the While loop, how would you ever exit?
My suggestion would be to stop working on this for a day or two, and go read the documentation, and work your way through the tutorials, workbooks, etc. so that you can see how some of these are written that work properly, how to debug, etc.
Then dig in to your own. It's far more productive to learn then build as opposed to build, repair, repair, repair, etc.
Best, Steve.