+ Start a Discussion
StaceyWStaceyW 

Please Help! Error: Compile Error: Expression cannot be assigned at line -1 column -1

I am creating a trigger which creates a Target_Sale__c which links to a Target__c. Each User has a Target per month and the Sales represents the Won Opportunity which rolls up to the target. The problem is that I need to take OpportunitySplits into account and create  Target Sale for each Opportunity Split.

I wrote the below trigger and am not getting any errors in the Developer Console but it is not saving in the browser - Here is my trigger:

trigger LinkOpportunitytoUserTarget on Opportunity (before insert, after update, after delete) {
   
    SET<String> oppyear = new SET<String>();
    SET<String> oppmonth = new SET<String>();
   
    SET<ID> oids = new SET<ID>();
    SET<ID> osids = new SET<ID>();
    SET<ID> userids = new SET<ID>();
   
    LIST<Target_Sale__c> targetsalelistdelete = new LIST<Target_Sale__c>();
    LIST<Target_Sale__c> targetsalelistinsert = new LIST<Target_Sale__c>();
    MAP<String,Target__c> targetmap = new MAP<String,Target__c>();
       
    String omaplookup;
    String osmaplookup;
   
    if(Trigger.IsInsert || Trigger.IsUpdate){
        for(Opportunity o : Trigger.new){
            if(o.Probability==100){
                oppyear.add(string.Valueof(o.CloseDate.Year()));
                oids.add(o.Id);
                oppmonth.add(string.ValueOf(o.CloseDate.Month()));
            }
        }
       
        system.debug('oppyear: '+oppyear);
        system.debug('oids: '+oids);
        system.debug('oppmonth: '+oppmonth);
    
     //Query Opportunity Splits linked to Opportunity and assign user ids to set
    for(OpportunitySplit getos : [SELECT Id, OpportunityId, SplitAmount, SplitOwnerId
                                FROM OpportunitySplit
                                WHERE OpportunityId IN :oids]){
                                    if(Opportunity.Probability=100){
                                        osids.add(getos.Id);
                                        userids.add(getos.SplitOwnerId);
                                  }
                                }
       
      system.debug('userids: '+userids);
      system.debug('osids: '+osids);
     
    //Query Target Sales already linked to Opportunity for delete
    for(Target_Sale__c getts : [SELECT Id, Name, Amount__c, Opportunity_Reference__c, Opportunity_Split_Reference__c, Opportunity_Name__c FROM Target_Sale__c WHERE Opportunity_Split_Reference__c IN :osids]){
        targetsalelistdelete.add(getts);   
    }
       
        system.debug('targetsalelistdelete: '+targetsalelistdelete);
   
        if(!targetsalelistdelete.isEmpty()){
            delete targetsalelistdelete;
        }
     
    //Query Target records for users for Month and Date of Opportunity
    for(Target__c gett : [SELECT Id, Name, Target_Amount__c, Actual_Sales__c, OwnerId, Sales_Rep__r.Id, Year__c, Month__c
                        FROM Target__c
                        WHERE Sales_Rep__r.Id IN :userids
                        AND Year__c IN :oppyear
                        AND Month__c IN :oppmonth]){
                        //add Targets to Target Map
                        targetmap.put(gett.Sales_Rep__r.Id + '_' + gett.Year__c + '_' + gett.Month__c,gett);                     
                        }
       
    system.debug('targetmap: '+targetmap);

    for(OpportunitySplit oppsplits : [SELECT Id, OpportunityId, SplitAmount, SplitOwnerId
                                FROM OpportunitySplit
                                WHERE Id IN :osids]){
            osmaplookup = oppsplits.SplitOwnerId + '_' + string.Valueof(oppsplits.Opportunity.CloseDate.Year()) + '_' + string.Valueof(oppsplits.Opportunity.CloseDate.Month()); 
            system.debug('osmaplookup: '+osmaplookup);
                            if(targetmap.get(osmaplookup) != null){
                                            targetsalelistinsert.add(new Target_Sale__c(Target__c = targetmap.get(osmaplookup).Id,
                                                                    Opportunity_Reference__c = oppsplits.OpportunityId,
                                                                    Opportunity_Split_Reference__c = oppsplits.Id,
                                                                    Amount__c = oppsplits.SplitAmount,
                                                                    Opportunity_Name__c = oppsplits.OpportunityId.Name)); 
                                            }
        }
            
        system.debug('targetsalelistinsert: '+targetsalelistinsert);
        if(!targetsalelistinsert.isEmpty()){
            insert targetsalelistinsert;
        }
    }
   
    if(Trigger.IsDelete){
        for(Opportunity o : Trigger.old){
            if(o.Probability=100){
                oids.add(o.Id);
            }
        }
       
        system.debug('oids: '+oids);
       
        for(Target_Sale__c getts : [SELECT Id, Name, Amount__c, Opportunity_Reference__c, Opportunity_Split_Reference__c, Opportunity_Name__c FROM Target_Sale__c WHERE Opportunity_Reference__c IN :oids]){
            targetsalelistdelete.add(getts);   
        }
       
        system.debug('targetsalelistdelete: '+targetsalelistdelete);
        if(!targetsalelistdelete.isEmpty()){
            delete targetsalelistdelete;
        }
    }
}

Any help would be greatly appreciated as I just can't figure out what the error is refering to!
Best Answer chosen by StaceyW
StaceyWStaceyW
Thanks so mmuch for the input. I ended up saving it section by section and eventually go it to work with a few tweaks here and there:

Here is the final code for anyone who comes across this.

trigger LinkOpportunitytoUserTarget on Opportunity (after insert, after update, after delete) {
   
    SET<String> oppyear = new SET<String>();
    SET<String> oppmonth = new SET<String>();
   
    SET<ID> oids = new SET<ID>();
    SET<ID> osids = new SET<ID>();
    SET<ID> userids = new SET<ID>();
   
    LIST<Target_Sale__c> targetsalelistdelete = new LIST<Target_Sale__c>();
    LIST<Target_Sale__c> targetsalelistinsert = new LIST<Target_Sale__c>();
    MAP<String,Target__c> targetmap = new MAP<String,Target__c>();
       
    String omaplookup;
    String osmaplookup;
   
    if(Trigger.IsInsert || Trigger.IsUpdate){
        for(Opportunity o : Trigger.new){
            if(o.Probability==100){
                oppyear.add(string.Valueof(o.CloseDate.Year()));
                oids.add(o.Id);
                oppmonth.add(string.ValueOf(o.CloseDate.Month()));
            }
        }
       
        system.debug('oppyear: '+oppyear);
        system.debug('oids: '+oids);
        system.debug('oppmonth: '+oppmonth);
    
     //Query Opportunity Splits linked to Opportunity and assign user ids to set
    for(OpportunitySplit getos : [SELECT Id, OpportunityId, SplitAmount, SplitOwnerId
                                FROM OpportunitySplit
                                WHERE OpportunityId IN :oids]){
                                        osids.add(getos.Id);
                                        userids.add(getos.SplitOwnerId);
                                }
       
      system.debug('userids: '+userids);
      system.debug('osids: '+osids);
     
        //Query Target Sales already linked to Opportunity for delete
    for(Target_Sale__c getts : [SELECT Id, Name, Amount__c, Opportunity_Reference__c, Opportunity_Split_Reference__c, Opportunity_Name__c FROM Target_Sale__c WHERE Opportunity_Split_Reference__c IN :osids]){
        targetsalelistdelete.add(getts);   
    }
       
        system.debug('targetsalelistdelete: '+targetsalelistdelete);
   
        if(!targetsalelistdelete.isEmpty()){
            delete targetsalelistdelete;
        }
    //Query Target records for users for Month and Date of Opportunity
    for(Target__c gett : [SELECT Id, Name, Target_Amount__c, Actual_Sales__c, OwnerId, Sales_Rep__r.Id, Year__c, Month__c, Month_Value__c
                        FROM Target__c
                        WHERE Sales_Rep__r.Id IN :userids
                        AND Year__c IN :oppyear
                        AND Month_Value__c IN :oppmonth]){
                        //add Targets to Target Map
                        targetmap.put(gett.Sales_Rep__r.Id + '_' + gett.Year__c + '_' + gett.Month_Value__c,gett);                     
                        }
       
    system.debug('targetmap: '+targetmap);
    
    for(OpportunitySplit oppsplits : [SELECT Id, OpportunityId, SplitAmount, SplitOwnerId, Opportunity.CloseDate, Opportunity.Name, Opportunity.Probability
                                FROM OpportunitySplit
                                WHERE Id IN :osids]){
            osmaplookup = oppsplits.SplitOwnerId + '_' + string.Valueof(oppsplits.Opportunity.CloseDate.Year()) + '_' + string.Valueof(oppsplits.Opportunity.CloseDate.Month()); 
            system.debug('osmaplookup: '+osmaplookup);
                            if(targetmap.get(osmaplookup) != null){
                                            targetsalelistinsert.add(new Target_Sale__c(Target__c = targetmap.get(osmaplookup).Id,
                                                                    Opportunity_Reference__c = oppsplits.OpportunityId,
                                                                    Opportunity_Split_Reference__c = oppsplits.Id,
                                                                    Amount__c = oppsplits.SplitAmount,
                                                                    Opportunity_Name__c = oppsplits.Opportunity.Name)); 
                                            }
            }
         system.debug('targetsalelistinsert: '+targetsalelistinsert);
        if(!targetsalelistinsert.isEmpty()){
            insert targetsalelistinsert;
        }
     }
   
    if(Trigger.IsDelete){
        for(Opportunity o : Trigger.old){
            if(o.Probability==100){
                oids.add(o.Id);
            }
        }
       
        system.debug('oids: '+oids);
       
        for(Target_Sale__c getts : [SELECT Id, Name, Amount__c, Opportunity_Reference__c, Opportunity_Split_Reference__c, Opportunity_Name__c FROM Target_Sale__c WHERE Opportunity_Reference__c IN :oids]){
            targetsalelistdelete.add(getts);   
        }
       
        system.debug('targetsalelistdelete: '+targetsalelistdelete);
        if(!targetsalelistdelete.isEmpty()){
            delete targetsalelistdelete;
        }
    }
}

All Answers

Daniel B ProbertDaniel B Probert
i think your problem lies within line 34 - 37

also i notice that on line 88 it should be ==100 to ensure it's a boolean response.

without having target and target_sale object in my org it's hard to 100% be sure but if you // that if statement out do you still get the error?
Daniel B ProbertDaniel B Probert
if(Opportunity.Probability=100){
               osids.add(getos.Id);
               userids.add(getos.SplitOwnerId);
         }
these lines - should have included in my answer..


StaceyWStaceyW
Thanks so mmuch for the input. I ended up saving it section by section and eventually go it to work with a few tweaks here and there:

Here is the final code for anyone who comes across this.

trigger LinkOpportunitytoUserTarget on Opportunity (after insert, after update, after delete) {
   
    SET<String> oppyear = new SET<String>();
    SET<String> oppmonth = new SET<String>();
   
    SET<ID> oids = new SET<ID>();
    SET<ID> osids = new SET<ID>();
    SET<ID> userids = new SET<ID>();
   
    LIST<Target_Sale__c> targetsalelistdelete = new LIST<Target_Sale__c>();
    LIST<Target_Sale__c> targetsalelistinsert = new LIST<Target_Sale__c>();
    MAP<String,Target__c> targetmap = new MAP<String,Target__c>();
       
    String omaplookup;
    String osmaplookup;
   
    if(Trigger.IsInsert || Trigger.IsUpdate){
        for(Opportunity o : Trigger.new){
            if(o.Probability==100){
                oppyear.add(string.Valueof(o.CloseDate.Year()));
                oids.add(o.Id);
                oppmonth.add(string.ValueOf(o.CloseDate.Month()));
            }
        }
       
        system.debug('oppyear: '+oppyear);
        system.debug('oids: '+oids);
        system.debug('oppmonth: '+oppmonth);
    
     //Query Opportunity Splits linked to Opportunity and assign user ids to set
    for(OpportunitySplit getos : [SELECT Id, OpportunityId, SplitAmount, SplitOwnerId
                                FROM OpportunitySplit
                                WHERE OpportunityId IN :oids]){
                                        osids.add(getos.Id);
                                        userids.add(getos.SplitOwnerId);
                                }
       
      system.debug('userids: '+userids);
      system.debug('osids: '+osids);
     
        //Query Target Sales already linked to Opportunity for delete
    for(Target_Sale__c getts : [SELECT Id, Name, Amount__c, Opportunity_Reference__c, Opportunity_Split_Reference__c, Opportunity_Name__c FROM Target_Sale__c WHERE Opportunity_Split_Reference__c IN :osids]){
        targetsalelistdelete.add(getts);   
    }
       
        system.debug('targetsalelistdelete: '+targetsalelistdelete);
   
        if(!targetsalelistdelete.isEmpty()){
            delete targetsalelistdelete;
        }
    //Query Target records for users for Month and Date of Opportunity
    for(Target__c gett : [SELECT Id, Name, Target_Amount__c, Actual_Sales__c, OwnerId, Sales_Rep__r.Id, Year__c, Month__c, Month_Value__c
                        FROM Target__c
                        WHERE Sales_Rep__r.Id IN :userids
                        AND Year__c IN :oppyear
                        AND Month_Value__c IN :oppmonth]){
                        //add Targets to Target Map
                        targetmap.put(gett.Sales_Rep__r.Id + '_' + gett.Year__c + '_' + gett.Month_Value__c,gett);                     
                        }
       
    system.debug('targetmap: '+targetmap);
    
    for(OpportunitySplit oppsplits : [SELECT Id, OpportunityId, SplitAmount, SplitOwnerId, Opportunity.CloseDate, Opportunity.Name, Opportunity.Probability
                                FROM OpportunitySplit
                                WHERE Id IN :osids]){
            osmaplookup = oppsplits.SplitOwnerId + '_' + string.Valueof(oppsplits.Opportunity.CloseDate.Year()) + '_' + string.Valueof(oppsplits.Opportunity.CloseDate.Month()); 
            system.debug('osmaplookup: '+osmaplookup);
                            if(targetmap.get(osmaplookup) != null){
                                            targetsalelistinsert.add(new Target_Sale__c(Target__c = targetmap.get(osmaplookup).Id,
                                                                    Opportunity_Reference__c = oppsplits.OpportunityId,
                                                                    Opportunity_Split_Reference__c = oppsplits.Id,
                                                                    Amount__c = oppsplits.SplitAmount,
                                                                    Opportunity_Name__c = oppsplits.Opportunity.Name)); 
                                            }
            }
         system.debug('targetsalelistinsert: '+targetsalelistinsert);
        if(!targetsalelistinsert.isEmpty()){
            insert targetsalelistinsert;
        }
     }
   
    if(Trigger.IsDelete){
        for(Opportunity o : Trigger.old){
            if(o.Probability==100){
                oids.add(o.Id);
            }
        }
       
        system.debug('oids: '+oids);
       
        for(Target_Sale__c getts : [SELECT Id, Name, Amount__c, Opportunity_Reference__c, Opportunity_Split_Reference__c, Opportunity_Name__c FROM Target_Sale__c WHERE Opportunity_Reference__c IN :oids]){
            targetsalelistdelete.add(getts);   
        }
       
        system.debug('targetsalelistdelete: '+targetsalelistdelete);
        if(!targetsalelistdelete.isEmpty()){
            delete targetsalelistdelete;
        }
    }
}
This was selected as the best answer
Daniel B ProbertDaniel B Probert
cool glad you worked it out..