• Shubranashu Panda
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
So my goal is to be able to have a primary record for one for my related object.  I'm currently getting an error.

Space__c is my main object
Lease__c is my related object

current_lease__c is the check box.

Here's my error: 
Error: Compile Error: Cannot save a trigger during a parse and save class call at line -1 column -1
trigger CurrentLease on Lease__c (Before Insert, Before Update, 
                                   After Insert, After Update, After Delete, After UnDelete) {

    Set <Id> filesId = new Set <Id> ();
    set <Id> objectsID = new Set <Id> ();

   for (Lease__c files : Trigger.new) {
       //Check if trigger.new Primary_file__c is TRUE
       System.debug('files.Current_Lease__c: '+files.Current_Lease__c);
       if (files.Current_Lease__c){
           //Add the Id to a list of ids
           filesId.add(files.Id);
           objectsID.add(files.Space__c);
       }     
   }
    System.debug('Object: ' + objectsID);
    //Query the ids from object where Primary_file__c is TRUE and is not new
    List <Lease__c> filesList = new List <Lease__c> (
        [select id, Current_Lease__c from Lease__c where Current_Lease__c = true and id not in :filesID and Space__c in :objectsID] );
    //System.debug('filesList: '+ filesList);
    System.debug('filesList.size(): ' + filesList.size());

    for (Lease__c files : Trigger.new) {
        if (filesList.size() > 0){
            files.Id.AddError('You cannot have more than one Current Lease');
        } 
    }
}

Any idea?