+ Start a Discussion
b.gonzalezb.gonzalez 

Compile Error: Variable does not exist

I am modifying an existing triggger and I am new to development. Need your help with the following error: Error: Compile Error: Variable does not exist: opp.Distributor_Performing_Integration__c at line 6 column 66
 
trigger CMR_OpportunityLineItemUpdated on OpportunityLineItem (after insert, after update, after delete, after undelete,before update, before insert) { 
    //Added before insert and before update events for Case 00076809
    //Added if condition for Case 00076809
    Opportunity I = trigger.new [0]; 
    if(I.RecordType.Name =='NewBDChannelOppRecordType'){
    if(I.RecordType.Name =='DesignChannelOpportunityRecordType'&&opp.Distributor_Performing_Integration__c==false&&opp.Distributor_Performing_Integration__c==true){
    if(trigger.IsAfter){
        string OpportunityId = '';
        if(trigger.isDelete) {
            OpportunityId = trigger.old[0].OpportunityId;
        } else {
            OpportunityId = trigger.new[0].OpportunityId;
        }
        Opportunity opp = new Opportunity(Id=OpportunityId);
        opp.CSG__c = false;
        opp.LMG__c = false;
        opp.NXN__c = false;
        opp.SPG__c = false;
        opp.SSG__c = false;
        opp.STI__c = false;
        opp.SIG__c = false;
        opp.EPG__c = false;
        List<OpportunityLineItem> prods = [Select PricebookEntry.Product2.Oracle_LOB__c From OpportunityLineItem Where PricebookEntry.IsActive = True And PricebookEntry.IsDeleted = False And PricebookEntry.Product2.IsActive = True And PricebookEntry.Product2.IsDeleted = False And OpportunityId = :OpportunityId];
        
        for(OpportunityLineItem oli:prods) {
            Product2 p2 = oli.PricebookEntry.Product2;

            if(p2.Oracle_LOB__c == 'CSG') {
                opp.CSG__c = true;
            } else if(p2.Oracle_LOB__c == 'LMG') {
                opp.LMG__c = true;
            } else if(p2.Oracle_LOB__c == 'NXN') {
                opp.NXN__c = true;
            } else if(p2.Oracle_LOB__c == 'SPG') {
                opp.SPG__c = true;
            } else if(p2.Oracle_LOB__c == 'SSG') {
                opp.SSG__c = true;
            } else if(p2.Oracle_LOB__c == 'STI') {
                opp.STI__c = true;
            } else if(p2.Oracle_LOB__c == 'SIG') {
                opp.SIG__c = true;
            } else if(p2.Oracle_LOB__c == 'EPG') {
                opp.EPG__c = true;
            }
           
        }
        update opp;
    }
    
    // Added for Case 00076809
    if(trigger.IsBefore){
        Set<String> products = new Set<String>{'SPG_SWITCH_TEST', 'SSG_ROUTER_TEST','PRF1-105XXC','PRF3-105XXC'};
        
        Map<Id,OpportunityLineItem> oliMap = new Map<Id,OpportunityLineItem>([Select Id, PricebookEntry.Product2.Name,PricebookEntry.Product2Id, Discount__c from OpportunityLineItem where Id in:trigger.New and (PricebookEntry.Product2.name in: products or PricebookEntry.Product2.Name like '%-MO-%')]);
        system.debug('**oliMap**'+oliMap );
        for(OpportunityLineItem oli: trigger.new){
            system.debug('**inside for**' );
            if(oliMap!= null && oliMap.get(oli.Id)!=null){
            system.debug('**inside if**' );
            oli.Discount__c = 0;
            }
        }   
    }
  }
 }
}

Thanks!

Beth
Best Answer chosen by b.gonzalez
BalajiRanganathanBalajiRanganathan
onLine 6, you have to use variable I, instead of opp

All Answers

BalajiRanganathanBalajiRanganathan
onLine 6, you have to use variable I, instead of opp
This was selected as the best answer
b.gonzalezb.gonzalez
Thanks. I am now recieving the following error: Compile Error: Illegal assignment from SOBJECT:OpportunityLineItem to SOBJECT:Opportunity at line 4 column 5
trigger CMR_OpportunityLineItemUpdated on OpportunityLineItem (after insert, after update, after delete, after undelete,before update, before insert) { 
    //Added before insert and before update events for Case 00076809
    //Added if condition for Case 00076809
    Opportunity I = trigger.new[0]; 
    if(I.RecordType.Name =='NewBDChannelOppRecordType'){
    if(I.RecordType.Name =='DesignChannelOpportunityRecordType'&&I.Distributor_Performing_Integration__c==false&&I.Distributor_Performing_Integration__c==true){
    if(trigger.IsAfter){
        string OpportunityId = '';
        if(trigger.isDelete) {
            OpportunityId = trigger.old[0].OpportunityId;
        } else {
            OpportunityId = trigger.new[0].OpportunityId;
        }

Beth
BalajiRanganathanBalajiRanganathan
the trigger is wrote on OpportunityLineItem. trigger.new[0] will return OpportunityLineItem and not Opportunity.

you need to revist your logic. you might have to do the following forst before doing any logic.

string OpportunityId = '';

09         if(trigger.isDelete) {

10             OpportunityId = trigger.old[0].OpportunityId;

11         } else {

12             OpportunityId = trigger.new[0].OpportunityId;

13         }

14         Opportunity opp = new Opportunity(Id=OpportunityId);

 
b.gonzalezb.gonzalez

Okay, thank you!

Beth

geetha anjali 9geetha anjali 9
trigger condelete1 on Account (before insert) {
    list<String> acclist=new list<String>();
    for(Account b:Trigger.New)
    {
        acclist.add(b.Name);
    }
    list<Contact> contact=[select LastName from Contact where LastName in:acclist];
    delete contact;
}



i got error for this code like variable does not exist Name