• Takunda Burutsa
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Execute Anonymous: Variable does not exist
Hey Guys, 
I'm stuck on trying to debug this piece of code in Anonymous Window. I set the variables using a map on the Opportunity object, but the child object "Payment__c" is not recognizing the lookup to Opportunity record maps. It's a master-detail relationship. The error message I'm seeing when I try executing is: Line: 41, Column: 30. Variable does not exist: BudBeer. Which is not making sense to me, is there something I'm not seeing? 
I'm sure it's something very silly, here's the code:
 
/* Insert Account Map */
             Map<String, Account> Accts= new Map<String, Account>{};
                Accts.put('BudweiserFac', new Account(Name='Budweiser Co'));
                Accts.put('SamAdams', new Account(Name='Sam Adams Co'));  
            insert Accts.values(); 
         
        /* Insert Contact Map */
            Map<String, Contact> Con= new Map<String, Contact>{};
                Con.put('JohnSmith', new Contact(FirstName='John',LastName='Smith',AccountId=Accts.get('SamAdams').Id));
                Con.put('TakuBurutsa', new Contact(FirstName='Taku',LastName='Burutsa',AccountId=Accts.get('BudweiserFac').Id));
            insert Con.values(); 
            
        /* Instantiate Opportunity Record Type variables */
                Id GrantId = Schema.SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('Grant').getRecordTypeId();
                    System.debug('Grant RecTypeId = '+GrantId);

                Id GiftId = Schema.SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('Gift').getRecordTypeId();
                    System.debug('Gift RectypeId ='+GiftId);
 
        /* Insert Opportunity Map */
  
            Map<String,Opportunity> Opptys=new Map<String,Opportunity>{};
                Opptys.put('SamBeer', new Opportunity(Name='Sam Beer $',CloseDate=date.parse('07/17/2019'),StageName='Closed',
                	Amount=100,AccountId=Accts.get('SamAdams').Id,Primary_Contact__c=Con.get('TakuBurutsa').Id,RecordTypeId=GiftId));
                Opptys.put('BudBeer', new Opportunity(Name='Bud Beer $',CloseDate=date.parse('07/17/2019'),StageName='Closed',
                    Amount=100,AccountId=Accts.get('BudweiserFac').Id,
                    Primary_Contact__c=Con.get('JohnSmith').Id,
                    RecordTypeId=GrantId)); 
            insert Opptys.values();
System.debug('Gift RectypeId ='+GiftId);
/* Insert Payment Map */
            Map<String,Payment__c> Pmts=new Map<String,Payment__c>{};
                Pmts.put('BudPmt1', new Payment__c(Paid__c=TRUE,Refund__c=FALSE,Payment_Method__c='Credit Card',
                Check_Date__c=date.parse('07/17/2019'),Cash_Received_Date__c=date.parse('07/17/2019'),Payment_Amount__c=100,
                CONTRIBUTION__C=Opptys.get('BudBeer').Id));

				Pmts.put('SamPmt1', new Payment__c(Paid__c=TRUE,Refund__c=FALSE,Payment_Method__c='Credit Card',
                Check_Date__c=date.parse('08/17/2019'),Cash_Received_Date__c=date.parse('08/17/2019'),Payment_Amount__c=100,
                CONTRIBUTION__C=Opptys.get('SamBeer').Id));
            insert Pmts.values();  
                System.debug(BudBeer);
		System.debug(SamBeer);

 
Execute Anonymous: Variable does not exist
Hey Guys, 
I'm stuck on trying to debug this piece of code in Anonymous Window. I set the variables using a map on the Opportunity object, but the child object "Payment__c" is not recognizing the lookup to Opportunity record maps. It's a master-detail relationship. The error message I'm seeing when I try executing is: Line: 41, Column: 30. Variable does not exist: BudBeer. Which is not making sense to me, is there something I'm not seeing? 
I'm sure it's something very silly, here's the code:
 
/* Insert Account Map */
             Map<String, Account> Accts= new Map<String, Account>{};
                Accts.put('BudweiserFac', new Account(Name='Budweiser Co'));
                Accts.put('SamAdams', new Account(Name='Sam Adams Co'));  
            insert Accts.values(); 
         
        /* Insert Contact Map */
            Map<String, Contact> Con= new Map<String, Contact>{};
                Con.put('JohnSmith', new Contact(FirstName='John',LastName='Smith',AccountId=Accts.get('SamAdams').Id));
                Con.put('TakuBurutsa', new Contact(FirstName='Taku',LastName='Burutsa',AccountId=Accts.get('BudweiserFac').Id));
            insert Con.values(); 
            
        /* Instantiate Opportunity Record Type variables */
                Id GrantId = Schema.SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('Grant').getRecordTypeId();
                    System.debug('Grant RecTypeId = '+GrantId);

                Id GiftId = Schema.SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('Gift').getRecordTypeId();
                    System.debug('Gift RectypeId ='+GiftId);
 
        /* Insert Opportunity Map */
  
            Map<String,Opportunity> Opptys=new Map<String,Opportunity>{};
                Opptys.put('SamBeer', new Opportunity(Name='Sam Beer $',CloseDate=date.parse('07/17/2019'),StageName='Closed',
                	Amount=100,AccountId=Accts.get('SamAdams').Id,Primary_Contact__c=Con.get('TakuBurutsa').Id,RecordTypeId=GiftId));
                Opptys.put('BudBeer', new Opportunity(Name='Bud Beer $',CloseDate=date.parse('07/17/2019'),StageName='Closed',
                    Amount=100,AccountId=Accts.get('BudweiserFac').Id,
                    Primary_Contact__c=Con.get('JohnSmith').Id,
                    RecordTypeId=GrantId)); 
            insert Opptys.values();
System.debug('Gift RectypeId ='+GiftId);
/* Insert Payment Map */
            Map<String,Payment__c> Pmts=new Map<String,Payment__c>{};
                Pmts.put('BudPmt1', new Payment__c(Paid__c=TRUE,Refund__c=FALSE,Payment_Method__c='Credit Card',
                Check_Date__c=date.parse('07/17/2019'),Cash_Received_Date__c=date.parse('07/17/2019'),Payment_Amount__c=100,
                CONTRIBUTION__C=Opptys.get('BudBeer').Id));

				Pmts.put('SamPmt1', new Payment__c(Paid__c=TRUE,Refund__c=FALSE,Payment_Method__c='Credit Card',
                Check_Date__c=date.parse('08/17/2019'),Cash_Received_Date__c=date.parse('08/17/2019'),Payment_Amount__c=100,
                CONTRIBUTION__C=Opptys.get('SamBeer').Id));
            insert Pmts.values();  
                System.debug(BudBeer);
		System.debug(SamBeer);