function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KRamaKRama 

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

SteveBowerSteveBower

Did you intend "for" on line 8, or "if"?   -Steve.

KRamaKRama

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

SteveBowerSteveBower
Check your syntax/logic.   The '==' is an equivalence operator, not an assignment.  Line 8 makes no sense unless I'm missing something.  -S
KRamaKRama

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

SuperfellSuperfell

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){ 

KRamaKRama

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 R

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 : 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.

SuperfellSuperfell
I think for an insert, the trigger.oldMap.get(ja.id) part on line 4 is going to return null, so then accessing .Candidate__c is going to throw an NPE.
SteveBowerSteveBower

...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.