• Ramanjot Sidhu
  • NEWBIE
  • 40 Points
  • Member since 2015
  • Salesforce Admin
  • Communitech

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 19
    Replies
Hi everyone,

I am trying to deploy a set of codes from my sandbox to production  but one of classes is failing:
Error Details:
Error Message System.AssertException: Assertion Failed: Same value: null
Stack Trace Class.EventBriteRegistrantScheduleTest.EventBriteRegistrantScheduleTest: line 29, column 1

What does this error mean? How can I go about fixing it?

My class:
global class EventBriteRegistrantSchedule implements Schedulable {  
  // cron expression
    // Seconds Minutes Hours Day_of_month Month Day_of_week optional_year
    public static String CRON_EXP = '0 45 * * * ?';
    public static String jobName = 'Scheduled Batch EventBrite Registrant Account/Contact Matching';

    global void execute(SchedulableContext SC) {
    String q = '';
    q = EventBriteRegistrantBatch.batchQuery;
    EventBriteRegistrantBatch brm = new EventBriteRegistrantBatch(q);    
        ID batchprocessid = Database.executeBatch(brm, brm.scopeLimit);
    }
    
    public static CronTrigger scheduleJob() {
      CronTrigger ct = null;
      
      try {
          // Schedule the test job  
          String jobId = System.schedule(jobName, EventBriteRegistrantSchedule.CRON_EXP, new EventBriteRegistrantSchedule());
  
          // Get the information from the CronTrigger API object  
          ct = [SELECT id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];
  
      } catch (Exception e) {
      System.Debug(LoggingLevel.ERROR, 'Job already scheduled');
      }        
        
        return ct;
    }
    
    public static void unscheduleJob() {
       // Get the information from the CronTrigger API object  
        List<CronTrigger> cts = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE CronExpression = :CRON_EXP];
        if (cts != null) {
          for (CronTrigger ct : cts) {
            System.abortJob(ct.Id);
          }
        }
    }
}

Test Class (Failing)
 
isTest
public class EventBriteRegistrantScheduleTest {
  
  @isTest
  public static void EventBriteRegistrantScheduleTest() {
      
    CronTrigger ct;
      DateTime dateToday = DateTime.now();
      
      // calculate next run time
    DateTime nextRun = dateToday;
    
      if (dateToday.minute() < 45) {
        nextRun = DateTime.newInstance(nextRun.year(), nextRun.month(), nextRun.day(), nextRun.hour(), 45, 0);
      } else {
        nextRun = nextRun.addHours(1);
        nextRun = DateTime.newInstance(nextRun.year(), nextRun.month(), nextRun.day(), nextRun.hour(), 45, 0);
      }
    
    // specify job name
        String jobName = EventBriteRegistrantSchedule.jobName;
    
        Test.startTest();
        
        // Schedule job
        ct = EventBriteRegistrantSchedule.scheduleJob();
          
        // Verify successfully created
        system.assertNotEquals(null, ct);

    // Verify the expressions are the same
    System.assertEquals(EventBriteRegistrantSchedule.CRON_EXP, ct.CronExpression);
  
    // Verify the job has not run
     System.assertEquals(0, ct.TimesTriggered);
          
    // Verify the next time the job will run
      System.assertEquals(nextRun, ct.NextFireTime);

    // Try scheduling job again
        ct = EventBriteRegistrantSchedule.scheduleJob();
          
        // Verify job failed
        system.assertEquals(null, ct);

        Test.stopTest();
        
        EventBriteRegistrantSchedule.unscheduleJob();
    }
    
}




Test CLass:
@isTest public class EventBriteRegistrantScheduleTest {      @isTest   public static void EventBriteRegistrantScheduleTest() {            CronTrigger ct;       DateTime dateToday = DateTime.now();              // calculate next run time     DateTime nextRun = dateToday;            if (dateToday.minute() < 45) {         nextRun = DateTime.newInstance(nextRun.year(), nextRun.month(), nextRun.day(), nextRun.hour(), 45, 0);       } else {         nextRun = nextRun.addHours(1);         nextRun = DateTime.newInstance(nextRun.year(), nextRun.month(), nextRun.day(), nextRun.hour(), 45, 0);       }          // specify job name         String jobName = EventBriteRegistrantSchedule.jobName;              Test.startTest();                  // Schedule job         ct = EventBriteRegistrantSchedule.scheduleJob();                    // Verify successfully created         system.assertNotEquals(null, ct);     // Verify the expressions are the same     System.assertEquals(EventBriteRegistrantSchedule.CRON_EXP, ct.CronExpression);        // Verify the job has not run      System.assertEquals(0, ct.TimesTriggered);                // Verify the next time the job will run       System.assertEquals(nextRun, ct.NextFireTime);     // Try scheduling job again         ct = EventBriteRegistrantSchedule.scheduleJob();                    // Verify job failed         system.assertEquals(null, ct);         Test.stopTest();                  EventBriteRegistrantSchedule.unscheduleJob();     }      }

Hi,

I am trying to depoly from production to sandbox but one of my test classes are failing in production. I do not know what to do, I have researched everywhere and cannot find a solution. We have an eventbrite integration in Salesforce, and maybe I would have to contact them. If  you could help out, I would appreciate it.

 

Error Details:
Error Message System.AssertException: Assertion Failed: Same value: null
Stack Trace Class.EventBriteRegistrantScheduleTest.EventBriteRegistrantScheduleTest: line 29, column 1

EventBriteClass:
 

global class EventBriteRegistrantSchedule implements Schedulable {  
  // cron expression
    // Seconds Minutes Hours Day_of_month Month Day_of_week optional_year
    public static String CRON_EXP = '0 45 * * * ?';
    public static String jobName = 'Scheduled Batch EventBrite Registrant Account/Contact Matching';

    global void execute(SchedulableContext SC) {
    String q = '';
    q = EventBriteRegistrantBatch.batchQuery;
    EventBriteRegistrantBatch brm = new EventBriteRegistrantBatch(q);    
        ID batchprocessid = Database.executeBatch(brm, brm.scopeLimit);
    }
    
    public static CronTrigger scheduleJob() {
      CronTrigger ct = null;
      
      try {
          // Schedule the test job  
          String jobId = System.schedule(jobName, EventBriteRegistrantSchedule.CRON_EXP, new EventBriteRegistrantSchedule());
  
          // Get the information from the CronTrigger API object  
          ct = [SELECT id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];
  
      } catch (Exception e) {
      System.Debug(LoggingLevel.ERROR, 'Job already scheduled');
      }        
        
        return ct;
    }
    
    public static void unscheduleJob() {
       // Get the information from the CronTrigger API object  
        List<CronTrigger> cts = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE CronExpression = :CRON_EXP];
        if (cts != null) {
          for (CronTrigger ct : cts) {
            System.abortJob(ct.Id);
          }
        }
    }
}

Test Class (Failing)
 
@isTest
public class EventBriteRegistrantScheduleTest {
  
  @isTest
  public static void EventBriteRegistrantScheduleTest() {
      
    CronTrigger ct;
      DateTime dateToday = DateTime.now();
      
      // calculate next run time
    DateTime nextRun = dateToday;
    
      if (dateToday.minute() < 45) {
        nextRun = DateTime.newInstance(nextRun.year(), nextRun.month(), nextRun.day(), nextRun.hour(), 45, 0);
      } else {
        nextRun = nextRun.addHours(1);
        nextRun = DateTime.newInstance(nextRun.year(), nextRun.month(), nextRun.day(), nextRun.hour(), 45, 0);
      }
    
    // specify job name
        String jobName = EventBriteRegistrantSchedule.jobName;
    
        Test.startTest();
        
        // Schedule job
        ct = EventBriteRegistrantSchedule.scheduleJob();
          
        // Verify successfully created
        system.assertNotEquals(null, ct);

    // Verify the expressions are the same
    System.assertEquals(EventBriteRegistrantSchedule.CRON_EXP, ct.CronExpression);
  
    // Verify the job has not run
     System.assertEquals(0, ct.TimesTriggered);
          
    // Verify the next time the job will run
      System.assertEquals(nextRun, ct.NextFireTime);

    // Try scheduling job again
        ct = EventBriteRegistrantSchedule.scheduleJob();
          
        // Verify job failed
        system.assertEquals(null, ct);

        Test.stopTest();
        
        EventBriteRegistrantSchedule.unscheduleJob();
    }
    
}

 
Hi everyone,

I am trying to deploy a set of codes from my sandbox to production  but one of classes is failing:
Error Details:
Error Message System.AssertException: Assertion Failed: Same value: null
Stack Trace Class.EventBriteRegistrantScheduleTest.EventBriteRegistrantScheduleTest: line 29, column 1

What does this error mean? How can I go about fixing it?

My class:
global class EventBriteRegistrantSchedule implements Schedulable {  
  // cron expression
    // Seconds Minutes Hours Day_of_month Month Day_of_week optional_year
    public static String CRON_EXP = '0 45 * * * ?';
    public static String jobName = 'Scheduled Batch EventBrite Registrant Account/Contact Matching';

    global void execute(SchedulableContext SC) {
    String q = '';
    q = EventBriteRegistrantBatch.batchQuery;
    EventBriteRegistrantBatch brm = new EventBriteRegistrantBatch(q);    
        ID batchprocessid = Database.executeBatch(brm, brm.scopeLimit);
    }
    
    public static CronTrigger scheduleJob() {
      CronTrigger ct = null;
      
      try {
          // Schedule the test job  
          String jobId = System.schedule(jobName, EventBriteRegistrantSchedule.CRON_EXP, new EventBriteRegistrantSchedule());
  
          // Get the information from the CronTrigger API object  
          ct = [SELECT id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];
  
      } catch (Exception e) {
      System.Debug(LoggingLevel.ERROR, 'Job already scheduled');
      }        
        
        return ct;
    }
    
    public static void unscheduleJob() {
       // Get the information from the CronTrigger API object  
        List<CronTrigger> cts = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE CronExpression = :CRON_EXP];
        if (cts != null) {
          for (CronTrigger ct : cts) {
            System.abortJob(ct.Id);
          }
        }
    }
}



Test CLass:
@isTest
public class EventBriteRegistrantScheduleTest {
  
  @isTest
  public static void EventBriteRegistrantScheduleTest() {
      
    CronTrigger ct;
      DateTime dateToday = DateTime.now();
      
      // calculate next run time
    DateTime nextRun = dateToday;
    
      if (dateToday.minute() < 45) {
        nextRun = DateTime.newInstance(nextRun.year(), nextRun.month(), nextRun.day(), nextRun.hour(), 45, 0);
      } else {
        nextRun = nextRun.addHours(1);
        nextRun = DateTime.newInstance(nextRun.year(), nextRun.month(), nextRun.day(), nextRun.hour(), 45, 0);
      }
    
    // specify job name
        String jobName = EventBriteRegistrantSchedule.jobName;
    
        Test.startTest();
        
        // Schedule job
        ct = EventBriteRegistrantSchedule.scheduleJob();
          
        // Verify successfully created
        system.assertNotEquals(null, ct);

    // Verify the expressions are the same
    System.assertEquals(EventBriteRegistrantSchedule.CRON_EXP, ct.CronExpression);
  
    // Verify the job has not run
     System.assertEquals(0, ct.TimesTriggered);
          
    // Verify the next time the job will run
      System.assertEquals(nextRun, ct.NextFireTime);

    // Try scheduling job again
        ct = EventBriteRegistrantSchedule.scheduleJob();
          
        // Verify job failed
        system.assertEquals(null, ct);

        Test.stopTest();
        
        EventBriteRegistrantSchedule.unscheduleJob();
    }
    
}
Hi, I have a code for counting completed activities and it works well in my sandbox. However I cannot deploy it to production because the testclass keeps failing..  I get this error:

Class test_ActivityUtils
Method Name mainTest
Pass/Fail Fail
Error Message System.AssertException: Assertion Failed: Expected: 3, Actual: 0
Stack Trace Class.test_ActivityUtils.mainTest: line 86, column 1

I have bolded line 86


@isTest(seeAllData = true)
private class test_ActivityUtils {
 
    static testMethod void mainTest() {
                Account acc = new Account();
                acc.Name = 'Test Account';
                acc.Industry = 'Transportation'; 
                insert acc;
 
 try { // Perform some database operations that 
 // might cause an exception. 
 insert acc; } 
 catch(DmlException e) { // DmlException handling code here. 
 System.debug('The following exception has occurred:  ' + e.getMessage());
 
 }
        Contact c = new Contact();
        c.FirstName = 'Joe';
        c.LastName = 'Smith';
        c.AccountId = acc.Id;
        c.Email = 'ramanjot_sidhu@hotmail.com';
        insert c;

  try { // Perform some database operations that 
 // might cause an exception. 
 insert c; } 
 catch(DmlException e) { // DmlException handling code here. 
 System.debug('The following exception has occurred: ' + e.getMessage());
 }
        Opportunity o = new Opportunity();
        o.AccountId = acc.Id;
        o.StageName = 'Open';
        o.Amount = 5000.00;
        o.CloseDate = Date.today() + 7;
        o.Name = 'Test Opp';
        insert o;
 
   try { // Perform some database operations that 
 // might cause an exception. 
 insert o; } 
 catch(DmlException e) { // DmlException handling code here. 
 System.debug('The following exception has occurred: ' + e.getMessage());
 }
         
        Task[] tList = new list<task>();
        for(Integer i=0; i<3; i++) {
            Task t = new Task();
            t.Status = 'Not Started';
            t.Priority = 'Normal';
            t.Type = 'Scheduled Call Back';
            if(i==0) t.WhatId = acc.Id;
            if(i==1) t.WhatId = o.Id;
            if(i==2) t.WhoId = c.Id;
            tList.add(t);
 
          
          Event[] eList = new list<event>();
          {
            Event e = new Event();
            e.StartDateTime = DateTime.now() + 7;
            e.EndDateTime = DateTime.now() + 14;
            if(i==0) e.WhatId = acc.Id;
            if(i==1) e.WhatId = o.Id;
            if(i==2) e.WhoId = c.Id;
             eList.add(e);
        }
        insert tList;
        insert eList;
 
   try { // Perform some database operations that 
 // might cause an exception. 
 insert tlIST; } 
 catch(DmlException e) { // DmlException handling code here. 
 System.debug('The following exception has occurred:' + e.getMessage());
 }
 
    try { // Perform some database operations that 
 // might cause an exception. 
 insert elIST; } 
 catch(DmlException e) { // DmlException handling code here. 
 System.debug('The following exception has occurred: ' + e.getMessage());
 }
 
 
        test.startTest();
           system.assertEquals(3, [SELECT Completed_Activities__c FROM Account WHERE Id = :acc.Id].Completed_Activities__c);

            system.assertEquals(2, [SELECT Completed_Activities__c FROM Opportunity WHERE Id = :o.Id].Completed_Activities__c);
            system.assertEquals(2, [SELECT Completed_Activities__c FROM Contact WHERE Id = :c.Id].Completed_Activities__c);
            
            //Delete some activities and run assertions again
            delete eList;
            system.assertEquals(3, [SELECT Completed_Activities__c FROM Account WHERE Id = :acc.Id].Completed_Activities__c);
            system.assertEquals(1, [SELECT Completed_Activities__c FROM Opportunity WHERE Id = :o.Id].Completed_Activities__c);
            system.assertEquals(1, [SELECT Completed_Activities__c FROM Contact WHERE Id = :c.Id].Completed_Activities__c);
           
          
            //Delete the rest activities and run assertions again for zero
            delete tList;
            system.assertEquals(0, [SELECT Completed_Activities__c FROM Account WHERE Id = :acc.Id].Completed_Activities__c);
            system.assertEquals(0, [SELECT Completed_Activities__c FROM Opportunity WHERE Id = :o.Id].Completed_Activities__c);
            system.assertEquals(0, [SELECT Completed_Activities__c FROM Contact WHERE Id = :c.Id].Completed_Activities__c);
         
         
        }
 
}
}

Hi, using a trigger I found online I tweeked to also count closed activities. I am a noob at apex, and  need this trigger to only count closed activities if the due date is within the current calender year.  Please let me know your thoughts. Thanks

 

Below is my Class:

public class ClosedActivityUtils {
 
//config
String fieldToUpdate = 'Closed_Activity_Count__c'; //this field must be added to each object we're updating

//state
set<id> accountIds;
set<id> contactIds;
set<id> opportunityIds;
set<id> leadIds;

public ClosedActivityUtils(sObject[] records) {
accountIds = new set<id>();
contactIds = new set<id>();
opportunityIds = new set<id>();
leadIds = new set<id>();
captureWhatAndWhoIds(records);
addAccountIdsFromRlatedObjects();
}

public void updateAccountActivityHistory() {
if(accountIds.size() == 0) return;
updateActivityHistory('Account','WhatId', getStringFromIdSet(accountIds));
}
public void updateContactActivityHistory() {
if(contactIds.size() == 0) return;
updateActivityHistory('Contact','WhoId', getStringFromIdSet(contactIds));
}
public void updateOpportunityActivityHistory() {
if(opportunityIds.size() == 0) return;
updateActivityHistory('Opportunity','WhatId', getStringFromIdSet(opportunityIds));
}
public void updateLeadActivityHistory() {
if(leadIds.size() == 0) return;
updateActivityHistory('Lead','WhoId', getStringFromIdSet(leadIds));
}
private void updateActivityHistory(String objToUpdate, String queryFld, String updateIds) 
string strQuery = 'SELECT Id, (SELECT Id FROM ActivityHistories) FROM ' + objToUpdate + ' WHERE Id IN (' + updateIds + ')'; 
System.debug(strQuery); sObject[] 
sobjects = new list<sobject>(); 
for(sObject so : database.query(strQuery)) {
ActivityHistory[] oActivities = so.getSObjects('ActivityHistories'); 
Integer closedActivityCount = oActivities == null ? 0 : oActivities.size(); 
sObject obj = createObject(objToUpdate, so.Id); 
obj.put(fieldToUpdate, closedActivityCount); 
sobjects.add(obj); 
system.debug('ActivityHistoryCount: ' + closedActivityCount);
}
update sobjects;
}}

private void captureWhatAndWhoIds(sObject[] objects) {
for(sObject o : objects) {
Id whatId = (Id)o.get('WhatId');
Id whoId = (Id)o.get('WhoId');
if(whatId != null) {
String objectName = getObjectNameFromId(whatId);
if(objectName == 'account') accountIds.add(whatId);
if(objectName == 'opportunity') opportunityIds.add(whatId);
}
if(whoId != null) {
String objectName = getObjectNameFromId(whoId);
if(objectName == 'contact') contactIds.add(whoId);
if(objectName == 'lead') leadIds.add(whoId);
}
}
}

private void addAccountIdsFromRlatedObjects() {
for(Opportunity o : [SELECT AccountId FROM Opportunity WHERE Id IN :opportunityIds]) accountIds.add(o.AccountId);
for(Contact c : [SELECT AccountId FROM Contact WHERE Id IN :contactIds]) accountIds.add(c.AccountId);
}

private String getObjectNameFromId(Id objId) {
String preFix = String.valueOf(objId).left(3).toLowercase();
if(prefix == '001') return 'account';
if(prefix == '003') return 'contact';
if(prefix == '006') return 'opportunity';
if(prefix == '00q') return 'lead';
return '';
}

private String getStringFromIdSet(set<id> idSet) {
string idString = '';
for(Id i : idSet) idString+= '\'' + i + '\',';
return idString == '' ? idString : idString.left(idString.length()-1); //If idString contains some ids we want to ensure we strip out the last comma
}

//The main part of the method below was taken from //Taken fromhttp://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dynamic_dml.htm
//However we've modified this to accept an object id
private sObject createObject(String typeName, Id objId) {
Schema.SObjectType targetType = Schema.getGlobalDescribe().get(typeName);
if (targetType == null) {
// throw an exception
}

// Instantiate an sObject with the type passed in as an argument
//  at run time.
return targetType.newSObject(objId);
}

}


Task Trigger:
trigger ClosedTaskTrigger on Task (after insert, after update, after delete, after undelete) {
 
    sObject[] triggerRecords;
    if(!trigger.isDelete) triggerRecords = trigger.new;
    else triggerRecords = trigger.old;
 
    //Update Closed Activity Count
    ClosedActivityUtils au = new ClosedActivityUtils(triggerRecords);
    au.updateAccountActivityHistory();
    au.updateContactActivityHistory();
    au.updateLeadActivityHistory();
    au.updateOpportunityActivityHistory();
 
}

Closed Event Trigger:
trigger ClosedEventTrigger on Event (after insert, after update, after delete, after undelete) {
 
    sObject[] triggerRecords;
    if(!trigger.isDelete) triggerRecords = trigger.new;
    else triggerRecords = trigger.old;
 
    //Update Closed Activity Count
    ClosedActivityUtils au = new ClosedActivityUtils(triggerRecords);
    au.updateAccountActivityHistory();
    au.updateContactActivityHistory();
    au.updateLeadActivityHistory();
    au.updateOpportunityActivityHistory();
 
}

trigger SetContactOnOrderItem on Line_item__c (before update, before insert) {
    Set<Integer> lineitemnumbers = new Set<Integer>();

    for (Line_item__c collectNumFromLineitem : Trigger.new) {
        lineitemnumbers.add(collectNumFromLineitem.Name);
    }

    List<Opportunity> oppList = [SELECT id, Related_Sponsorship_Offer__c
 FROM Opportunity WHERE Related_Sponsorship_Offer__c IN :lineitemnumbers];

    Map<Integer, Opportunity> lineitemNumToOppMap = new Map<Integer, Contact>();

    for (Opportunity c : oppList) {
        lineitemNumToOppMap.put(c.Related_Sponsorship_Offer__c, c);
    }

    for (Line_item__c o : Trigger.new) {
        if (o.Name != null) {
            o.Opportunity__c = lineitemNumToOppMap.get(o.Name).id;
        }
        else {
            o.Opportunity__c = null;
        }
    }
}


I have a custom object named: Line_item__c and a standard object called opportunity. The custom object has a lookup field for an opportunity. The opportunity page also has a lookup field for the custom object. When a opportunity look up field is populated on the custom object, it should autopopulate the related Line item on the look up field on the opportunity. I tried this trigger but I get the following error. I am new the apex and any help would be appreciated.

Thank you

 trigger ControlOpportunityStage on Line_Item__c (after update) {
       List<Opportunity> parentlist = new List<Opportunity>();
       List<Opportunity> opportunityId = new list<Opportunity>();
           for(Line_item__c lirecord : [SELECT Opportunity__r.id, Opportunity__r.StageName

from Line_item__c
               where Line_item__c.Opportunity__c <> null]){
                    
        for(Opportunity opt : parentlist)
            if(Opportunity.StageName != Line_item__c.Stage__c)
                Opportunity.StageName = Line_item__c.Stage__c;
                opportunityId.add(opportunity.Id);
       
 {
      if(opportunityId != null & opportunityId.Size()>0)
            update opportunityId;
               
       
 }     
}
}
I am trying to update parent stage(Opportunity: StageName) with child stage (Line_item__c : Stage__C) and get the error:

Compile Error: Loop with query must provide a statement at line 4 column 12


trigger ControlOpportunityStage on Line_Item__c (after update) {
       List<Opportunity> parentlist = new List<Opportunity>();
       List<Opportunity> opportunityId = new list<Opportunity>();
           for(Line_item__c lirecord : [SELECT Opportunity__r.id, Opportunity__r.StageName from Line_item__c
               where Line_item__c.Opportunity__c <> null]);{
               
               
       
           
        for(Opportunity opt : parentlist)
            if(Opportunity.StageName != Line_item__c.Stage__c){
                Opportunity.StageName = Line_item__c.Stage__c;
                optId.add(opt);
            
      }
     }
         if(opportunityId != null & opportunityId.Size()>0)
            upsert opportunityId;
}
Trigger Not Working

I have two objects: Opportunity (Parent),  Sponsorship Offer(Line_item__c) (Child)
On the Opportunity object there is a standardpicklist field called "Stage (StageName), and there is a custom field on the Sponsorship Offer page called Stage (Stage__c) with the same picklist. When an individual goes on to the Opportunity page, and tries to change the Stage, if the value is not equal to the Sponsorship Offer field "Stage", then I want to produce an error.. My trigger is not working. Any help would be greatly appreciated as I am new to apex.

 

Compile Error: Variable does not exist: o.StageName at line 7 column 8

trigger UpdateStage on Opportunity (before update) {
    List<Line_item__c> opportunitywithsponsorshipoffer = [SELECT Opportunity__r.id, Opportunity__r.StageName 
    from Line_item__c where Line_item__c.Opportunity__c <> Null];
   
    for (Opportunity o: opportunitywithsponsorshipoffer);
       for(Line_item__c li : o.li){
       o.StageName = li.Stage__c;
    if(o.StageName <> null){//If the opportunity stage name is not the same as the Sponsorship Offer stage name present error message 
         o.StageName = Line_item__c.Stage__c;
     } else {
      o.adderror ('Cannot track Stage on Opportunity page, please refer to the related Sponsorship Offer page');
     } //close for loop
     }// close for if statement
     }// close trigger
On my opportunity page, I have a child object called Sponsorship Offer. When a Sponsorship offer is related to an opportunity, I want to prevent the Stage field from being change on the Opportunity page, but be controlled via a custom stage field on the custom object. Is this even possible through a trigger?
Hi everyone,

I am trying to deploy a set of codes from my sandbox to production  but one of classes is failing:
Error Details:
Error Message System.AssertException: Assertion Failed: Same value: null
Stack Trace Class.EventBriteRegistrantScheduleTest.EventBriteRegistrantScheduleTest: line 29, column 1

What does this error mean? How can I go about fixing it?

My class:
global class EventBriteRegistrantSchedule implements Schedulable {  
  // cron expression
    // Seconds Minutes Hours Day_of_month Month Day_of_week optional_year
    public static String CRON_EXP = '0 45 * * * ?';
    public static String jobName = 'Scheduled Batch EventBrite Registrant Account/Contact Matching';

    global void execute(SchedulableContext SC) {
    String q = '';
    q = EventBriteRegistrantBatch.batchQuery;
    EventBriteRegistrantBatch brm = new EventBriteRegistrantBatch(q);    
        ID batchprocessid = Database.executeBatch(brm, brm.scopeLimit);
    }
    
    public static CronTrigger scheduleJob() {
      CronTrigger ct = null;
      
      try {
          // Schedule the test job  
          String jobId = System.schedule(jobName, EventBriteRegistrantSchedule.CRON_EXP, new EventBriteRegistrantSchedule());
  
          // Get the information from the CronTrigger API object  
          ct = [SELECT id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];
  
      } catch (Exception e) {
      System.Debug(LoggingLevel.ERROR, 'Job already scheduled');
      }        
        
        return ct;
    }
    
    public static void unscheduleJob() {
       // Get the information from the CronTrigger API object  
        List<CronTrigger> cts = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE CronExpression = :CRON_EXP];
        if (cts != null) {
          for (CronTrigger ct : cts) {
            System.abortJob(ct.Id);
          }
        }
    }
}

Test Class (Failing)
 
isTest
public class EventBriteRegistrantScheduleTest {
  
  @isTest
  public static void EventBriteRegistrantScheduleTest() {
      
    CronTrigger ct;
      DateTime dateToday = DateTime.now();
      
      // calculate next run time
    DateTime nextRun = dateToday;
    
      if (dateToday.minute() < 45) {
        nextRun = DateTime.newInstance(nextRun.year(), nextRun.month(), nextRun.day(), nextRun.hour(), 45, 0);
      } else {
        nextRun = nextRun.addHours(1);
        nextRun = DateTime.newInstance(nextRun.year(), nextRun.month(), nextRun.day(), nextRun.hour(), 45, 0);
      }
    
    // specify job name
        String jobName = EventBriteRegistrantSchedule.jobName;
    
        Test.startTest();
        
        // Schedule job
        ct = EventBriteRegistrantSchedule.scheduleJob();
          
        // Verify successfully created
        system.assertNotEquals(null, ct);

    // Verify the expressions are the same
    System.assertEquals(EventBriteRegistrantSchedule.CRON_EXP, ct.CronExpression);
  
    // Verify the job has not run
     System.assertEquals(0, ct.TimesTriggered);
          
    // Verify the next time the job will run
      System.assertEquals(nextRun, ct.NextFireTime);

    // Try scheduling job again
        ct = EventBriteRegistrantSchedule.scheduleJob();
          
        // Verify job failed
        system.assertEquals(null, ct);

        Test.stopTest();
        
        EventBriteRegistrantSchedule.unscheduleJob();
    }
    
}




Test CLass:
@isTest public class EventBriteRegistrantScheduleTest {      @isTest   public static void EventBriteRegistrantScheduleTest() {            CronTrigger ct;       DateTime dateToday = DateTime.now();              // calculate next run time     DateTime nextRun = dateToday;            if (dateToday.minute() < 45) {         nextRun = DateTime.newInstance(nextRun.year(), nextRun.month(), nextRun.day(), nextRun.hour(), 45, 0);       } else {         nextRun = nextRun.addHours(1);         nextRun = DateTime.newInstance(nextRun.year(), nextRun.month(), nextRun.day(), nextRun.hour(), 45, 0);       }          // specify job name         String jobName = EventBriteRegistrantSchedule.jobName;              Test.startTest();                  // Schedule job         ct = EventBriteRegistrantSchedule.scheduleJob();                    // Verify successfully created         system.assertNotEquals(null, ct);     // Verify the expressions are the same     System.assertEquals(EventBriteRegistrantSchedule.CRON_EXP, ct.CronExpression);        // Verify the job has not run      System.assertEquals(0, ct.TimesTriggered);                // Verify the next time the job will run       System.assertEquals(nextRun, ct.NextFireTime);     // Try scheduling job again         ct = EventBriteRegistrantSchedule.scheduleJob();                    // Verify job failed         system.assertEquals(null, ct);         Test.stopTest();                  EventBriteRegistrantSchedule.unscheduleJob();     }      }
Hi, I have a code for counting completed activities and it works well in my sandbox. However I cannot deploy it to production because the testclass keeps failing..  I get this error:

Class test_ActivityUtils
Method Name mainTest
Pass/Fail Fail
Error Message System.AssertException: Assertion Failed: Expected: 3, Actual: 0
Stack Trace Class.test_ActivityUtils.mainTest: line 86, column 1

I have bolded line 86


@isTest(seeAllData = true)
private class test_ActivityUtils {
 
    static testMethod void mainTest() {
                Account acc = new Account();
                acc.Name = 'Test Account';
                acc.Industry = 'Transportation'; 
                insert acc;
 
 try { // Perform some database operations that 
 // might cause an exception. 
 insert acc; } 
 catch(DmlException e) { // DmlException handling code here. 
 System.debug('The following exception has occurred:  ' + e.getMessage());
 
 }
        Contact c = new Contact();
        c.FirstName = 'Joe';
        c.LastName = 'Smith';
        c.AccountId = acc.Id;
        c.Email = 'ramanjot_sidhu@hotmail.com';
        insert c;

  try { // Perform some database operations that 
 // might cause an exception. 
 insert c; } 
 catch(DmlException e) { // DmlException handling code here. 
 System.debug('The following exception has occurred: ' + e.getMessage());
 }
        Opportunity o = new Opportunity();
        o.AccountId = acc.Id;
        o.StageName = 'Open';
        o.Amount = 5000.00;
        o.CloseDate = Date.today() + 7;
        o.Name = 'Test Opp';
        insert o;
 
   try { // Perform some database operations that 
 // might cause an exception. 
 insert o; } 
 catch(DmlException e) { // DmlException handling code here. 
 System.debug('The following exception has occurred: ' + e.getMessage());
 }
         
        Task[] tList = new list<task>();
        for(Integer i=0; i<3; i++) {
            Task t = new Task();
            t.Status = 'Not Started';
            t.Priority = 'Normal';
            t.Type = 'Scheduled Call Back';
            if(i==0) t.WhatId = acc.Id;
            if(i==1) t.WhatId = o.Id;
            if(i==2) t.WhoId = c.Id;
            tList.add(t);
 
          
          Event[] eList = new list<event>();
          {
            Event e = new Event();
            e.StartDateTime = DateTime.now() + 7;
            e.EndDateTime = DateTime.now() + 14;
            if(i==0) e.WhatId = acc.Id;
            if(i==1) e.WhatId = o.Id;
            if(i==2) e.WhoId = c.Id;
             eList.add(e);
        }
        insert tList;
        insert eList;
 
   try { // Perform some database operations that 
 // might cause an exception. 
 insert tlIST; } 
 catch(DmlException e) { // DmlException handling code here. 
 System.debug('The following exception has occurred:' + e.getMessage());
 }
 
    try { // Perform some database operations that 
 // might cause an exception. 
 insert elIST; } 
 catch(DmlException e) { // DmlException handling code here. 
 System.debug('The following exception has occurred: ' + e.getMessage());
 }
 
 
        test.startTest();
           system.assertEquals(3, [SELECT Completed_Activities__c FROM Account WHERE Id = :acc.Id].Completed_Activities__c);

            system.assertEquals(2, [SELECT Completed_Activities__c FROM Opportunity WHERE Id = :o.Id].Completed_Activities__c);
            system.assertEquals(2, [SELECT Completed_Activities__c FROM Contact WHERE Id = :c.Id].Completed_Activities__c);
            
            //Delete some activities and run assertions again
            delete eList;
            system.assertEquals(3, [SELECT Completed_Activities__c FROM Account WHERE Id = :acc.Id].Completed_Activities__c);
            system.assertEquals(1, [SELECT Completed_Activities__c FROM Opportunity WHERE Id = :o.Id].Completed_Activities__c);
            system.assertEquals(1, [SELECT Completed_Activities__c FROM Contact WHERE Id = :c.Id].Completed_Activities__c);
           
          
            //Delete the rest activities and run assertions again for zero
            delete tList;
            system.assertEquals(0, [SELECT Completed_Activities__c FROM Account WHERE Id = :acc.Id].Completed_Activities__c);
            system.assertEquals(0, [SELECT Completed_Activities__c FROM Opportunity WHERE Id = :o.Id].Completed_Activities__c);
            system.assertEquals(0, [SELECT Completed_Activities__c FROM Contact WHERE Id = :c.Id].Completed_Activities__c);
         
         
        }
 
}
}

trigger SetContactOnOrderItem on Line_item__c (before update, before insert) {
    Set<Integer> lineitemnumbers = new Set<Integer>();

    for (Line_item__c collectNumFromLineitem : Trigger.new) {
        lineitemnumbers.add(collectNumFromLineitem.Name);
    }

    List<Opportunity> oppList = [SELECT id, Related_Sponsorship_Offer__c
 FROM Opportunity WHERE Related_Sponsorship_Offer__c IN :lineitemnumbers];

    Map<Integer, Opportunity> lineitemNumToOppMap = new Map<Integer, Contact>();

    for (Opportunity c : oppList) {
        lineitemNumToOppMap.put(c.Related_Sponsorship_Offer__c, c);
    }

    for (Line_item__c o : Trigger.new) {
        if (o.Name != null) {
            o.Opportunity__c = lineitemNumToOppMap.get(o.Name).id;
        }
        else {
            o.Opportunity__c = null;
        }
    }
}


I have a custom object named: Line_item__c and a standard object called opportunity. The custom object has a lookup field for an opportunity. The opportunity page also has a lookup field for the custom object. When a opportunity look up field is populated on the custom object, it should autopopulate the related Line item on the look up field on the opportunity. I tried this trigger but I get the following error. I am new the apex and any help would be appreciated.

Thank you

 trigger ControlOpportunityStage on Line_Item__c (after update) {
       List<Opportunity> parentlist = new List<Opportunity>();
       List<Opportunity> opportunityId = new list<Opportunity>();
           for(Line_item__c lirecord : [SELECT Opportunity__r.id, Opportunity__r.StageName

from Line_item__c
               where Line_item__c.Opportunity__c <> null]){
                    
        for(Opportunity opt : parentlist)
            if(Opportunity.StageName != Line_item__c.Stage__c)
                Opportunity.StageName = Line_item__c.Stage__c;
                opportunityId.add(opportunity.Id);
       
 {
      if(opportunityId != null & opportunityId.Size()>0)
            update opportunityId;
               
       
 }     
}
}
I am trying to update parent stage(Opportunity: StageName) with child stage (Line_item__c : Stage__C) and get the error:

Compile Error: Loop with query must provide a statement at line 4 column 12


trigger ControlOpportunityStage on Line_Item__c (after update) {
       List<Opportunity> parentlist = new List<Opportunity>();
       List<Opportunity> opportunityId = new list<Opportunity>();
           for(Line_item__c lirecord : [SELECT Opportunity__r.id, Opportunity__r.StageName from Line_item__c
               where Line_item__c.Opportunity__c <> null]);{
               
               
       
           
        for(Opportunity opt : parentlist)
            if(Opportunity.StageName != Line_item__c.Stage__c){
                Opportunity.StageName = Line_item__c.Stage__c;
                optId.add(opt);
            
      }
     }
         if(opportunityId != null & opportunityId.Size()>0)
            upsert opportunityId;
}
Trigger Not Working

I have two objects: Opportunity (Parent),  Sponsorship Offer(Line_item__c) (Child)
On the Opportunity object there is a standardpicklist field called "Stage (StageName), and there is a custom field on the Sponsorship Offer page called Stage (Stage__c) with the same picklist. When an individual goes on to the Opportunity page, and tries to change the Stage, if the value is not equal to the Sponsorship Offer field "Stage", then I want to produce an error.. My trigger is not working. Any help would be greatly appreciated as I am new to apex.

 

Compile Error: Variable does not exist: o.StageName at line 7 column 8

trigger UpdateStage on Opportunity (before update) {
    List<Line_item__c> opportunitywithsponsorshipoffer = [SELECT Opportunity__r.id, Opportunity__r.StageName 
    from Line_item__c where Line_item__c.Opportunity__c <> Null];
   
    for (Opportunity o: opportunitywithsponsorshipoffer);
       for(Line_item__c li : o.li){
       o.StageName = li.Stage__c;
    if(o.StageName <> null){//If the opportunity stage name is not the same as the Sponsorship Offer stage name present error message 
         o.StageName = Line_item__c.Stage__c;
     } else {
      o.adderror ('Cannot track Stage on Opportunity page, please refer to the related Sponsorship Offer page');
     } //close for loop
     }// close for if statement
     }// close trigger
On my opportunity page, I have a child object called Sponsorship Offer. When a Sponsorship offer is related to an opportunity, I want to prevent the Stage field from being change on the Opportunity page, but be controlled via a custom stage field on the custom object. Is this even possible through a trigger?

I made this testclass which handles cases + and cases contains account + setup information. Now I'm getting this error :

System.AssertException: Assertion Failed: Same value: null and I don't understand where this is coming from?

@isTest
private class AMobileHandlerTest {
   
    static testMethod void saveCaseTest() {
        // String account = ...;
        String connId = '12345678';
        String buyersID = 'bid';
        String classification = 'P3';
        String subject = 'Unit test subject';
        String description = 'Unit test description';
       
        Account ma = new account();
        ma.Name = 'test account';
        RecordType recordTypeMa = [ select Id, Name from RecordType where SObjectType = 'Account' and Name = 'Main Account' LIMIT 1];
        ma.RecordTypeId = recordTypeMa.Id;
        insert ma;
       
        Account ac = new account();
        ac.ParentId = ma.Id;
        ac.Name = 'test account';
        ac.ShippingCity = 'oulu';
        ac.ShippingCountry = 'finland';
        ac.ShippingPostalCode = '90550';
        ac.ShippingState = 'na';
        ac.ShippingStreet = 'eletie';
        RecordType recordType = [ select Id, Name from RecordType where SObjectType = 'Account' and Name = 'Site' LIMIT 1];
        ac.recordTypeId = recordType.Id;
        insert ac;
        System.assertNotEquals(null, ac.Id);
       
        Setup__c setuppi = new Setup__c();
        setuppi.Name = 'test';
        setuppi.SOC_LL_ID__c = connId;
        setuppi.site__c = ac.Id;
        insert setuppi;
        System.assertNotEquals(null, setuppi.Id);
       
       
        // AMobileHandler hndlr = new AMobileHandler();
        Test.startTest();
        string id = AMobileHandler.saveCase(connId, buyersId, classification, subject, description);
        Test.stopTest();
       
        System.assertNotEquals(null, id);

  • October 23, 2013
  • Like
  • 0