• Zen Newman 16
  • NEWBIE
  • 30 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
Hello- I'm writing a scheduled Apex class that grabs all Accounts that are listed as 'Active' in a custom field, find's the most recent closed won Opportunity and passes a value from a lookup field on that opp back to another lookup on the Account. The class isn't flagging any problems for me, but throws an error when it tries to run upon being scheduled.

The error seems to indicate that it couldn't find any records to update. I verified that there are records that meet the criteria, and when I run the SOQL query in isolation it finds those records. When I try to debug it in the Execute Annonymous window, it also doesn't return any system.debug messages. I appreciate any help figuring out where I'm going wrong! 
The error:
Sandbox

Apex script unhandled exception by user/organization: 0053i000002hKdg/00D1g0000002qa7
Source organization: 00D3i000000ttF8 (null)
Scheduled job 'Se Update2' threw unhandled exception.

caused by: System.QueryException: List has no rows for assignment to SObject

Class.UpdateSEOnAccount.execute: line 8, column 1
The Apex Class:
global class UpdateSEOnAccount implements Schedulable{
    global void execute (SchedulableContext ctx){
        UpdateSE();
    }
    public void UpdateSE(){
        List<Account> Actlst = new list<account>();
        for(Account a : [SELECT Id FROM Account WHERE Customer_Status__c = 'Active']){    
             a.Sales_Engineer__c = [SELECT Id, SE__c, AccountId 
                          FROM Opportunity 
                          WHERE AccountId = : a.id AND StageName = 'Closed Won'
                          ORDER BY CloseDate DESC LIMIT 1].SE__c;
           system.debug('a is '+ a.Id);
           if(a.SE__c <> NULL){
           Actlst.add(a);
           }
            system.debug('size of list is '+ Actlst.size());
        }
        if(Actlst.size()>0){
            update Actlst;
        }
    }
}


 
Hello, I have a fairly simple apex class that seems to working correctly to remove the html from a rich text field and populate a plain text field with the content. The test class, however, is producing zero code coverage and I'm not sure why. I appreciate any help on where I'm going wrong.

The main class:
public class HTMLStripper {
	@InvocableMethod(label = 'HTML Stripper' description = 'Strips HTML from rich text fields and returns text value') 
    public static void Stripper(List<Id> Ids){
    	List<Opportunity> lstOpp = new List<Opportunity>();
        for(Opportunity opp : [SELECT Id, XDR_Notes__c FROM Opportunity WHERE Id IN : Ids]) { 
            opp.XDR_Notes_Text__c = opp.XDR_Notes__c.replaceAll('<[/a-zAZ0-9&]*>',' ');
            lstOpp.add(opp); 
        }
        if(lstOpp.size()>0){
            update lstOpp;
        }	
    } 
}
And the Test Class:
@isTest
public class HTMLStripperTest {
    static testMethod void HTMLRemoval() {
       //insert test lead
       Account a = new Account(Name = 'Test');
       insert a;  
       Opportunity o = new Opportunity(Name = 'Test', AccountId = a.Id, CloseDate = Date.today(), 
                                       XDR_Notes__c = 'These are test lead notes'); 
       insert o;
        
       //retrieve and test 
       List<Id>lstOppId = new list<Id>{o.Id}; 
       HTMLStripper.Stripper(lstOppId);  
       Boolean result = o.XDR_Notes_Text__c.contains('>'); 
       System.assertEquals(False, result);
       
    }
}


 
Hello,

I've written an apex class intending to invoke it from a flow. When I try to call the class from a test class, however, I'm hitting an error that I haven't been able to figure out. Hoping someone can point me to where I'm going wrong.

The apex class:
public class EuroOppRoundRobin {
    
    @InvocableMethod(label = 'Round Robin European Opps')
   
    public static void RoundRobin(List<Id> OppId){
        
        Opportunity Opp = [SELECT Id, OwnerId, OppAutoNum__c FROM Opportunity WHERE Id in :OppId];
    
        List<GroupMember> reps = [SELECT UserOrGroupId FROM GroupMember WHERE GroupId = '00G1g000003VvQnEAK' 
                           ORDER BY Id ASC];
        Integer Count = [SELECT COUNT() FROM GroupMember WHERE GroupId = '00G1g000003VvQnEAK'];
        Integer OppNum = integer.valueOf(Opp.OppAutoNum__c);
        Double roundRobin = OppNum / Count;
        Integer roundRobinId = roundRobin.intValue();
        
        Integer salesId = math.mod(roundRobinId, Count);
            
        Opp.OwnerId = reps[salesId].UserOrGroupId;
        update Opp;        
    }
		 
}
The test class:
@isTest
private class EuroRoundRobinTest {
    static testMethod void validateEuroRoundRobin() { 
        
        //Create & insert account
    	Account a = new Account(Name = 'Test Account', Sales_Territory__c = 'Europe', OwnerId = '0053i000002gvY2AAI');
        System.debug('The accounts name is ' + a.Name + ' and the sales territroy is ' + a.Sales_Territory__c + 
                     ' the owneris ' + a.OwnerId);
		insert a; 
        
        //Create & insert opportunity
        Opportunity opp = new Opportunity(Name = 'Test Opp', AccountId = a.Id, StageName = 'Pre-Qualified', 
                                          CloseDate = Date.today(), Payment_Frequency__c = 'Annual', 
                                          OwnerId = '0053i000002gvY2AAI');
        System.debug(opp.Name + opp.AccountId + opp.StageName + opp.CloseDate + opp.Payment_Frequency__c + opp.OwnerId); 
        insert opp; 
        
        //Retrieve the test opp and check if owner has updated
        List<Opportunity> OppId = [SELECT Id FROM Opportunity WHERE Id =: opp.Id];
        
        EuroOppRoundRobin.RoundRobin(OppId);  
        System.assertNotEquals('0053i000002gvY2AAI', opp.OwnerId);           
    }
}
The error I'm getting is on line 21 in the test class when I try to invoike the apex class and the error is: Method does not exist or incorrect signature: void RoundRobin(List<Opportunity>) from the type EuroOppRoundRobin
EuroOppRoundRobin.RoundRobin(OppId);

I appreciate any guidance, thanks!

 
Hello- I'm writing a scheduled Apex class that grabs all Accounts that are listed as 'Active' in a custom field, find's the most recent closed won Opportunity and passes a value from a lookup field on that opp back to another lookup on the Account. The class isn't flagging any problems for me, but throws an error when it tries to run upon being scheduled.

The error seems to indicate that it couldn't find any records to update. I verified that there are records that meet the criteria, and when I run the SOQL query in isolation it finds those records. When I try to debug it in the Execute Annonymous window, it also doesn't return any system.debug messages. I appreciate any help figuring out where I'm going wrong! 
The error:
Sandbox

Apex script unhandled exception by user/organization: 0053i000002hKdg/00D1g0000002qa7
Source organization: 00D3i000000ttF8 (null)
Scheduled job 'Se Update2' threw unhandled exception.

caused by: System.QueryException: List has no rows for assignment to SObject

Class.UpdateSEOnAccount.execute: line 8, column 1
The Apex Class:
global class UpdateSEOnAccount implements Schedulable{
    global void execute (SchedulableContext ctx){
        UpdateSE();
    }
    public void UpdateSE(){
        List<Account> Actlst = new list<account>();
        for(Account a : [SELECT Id FROM Account WHERE Customer_Status__c = 'Active']){    
             a.Sales_Engineer__c = [SELECT Id, SE__c, AccountId 
                          FROM Opportunity 
                          WHERE AccountId = : a.id AND StageName = 'Closed Won'
                          ORDER BY CloseDate DESC LIMIT 1].SE__c;
           system.debug('a is '+ a.Id);
           if(a.SE__c <> NULL){
           Actlst.add(a);
           }
            system.debug('size of list is '+ Actlst.size());
        }
        if(Actlst.size()>0){
            update Actlst;
        }
    }
}


 
Hello,

I've written an apex class intending to invoke it from a flow. When I try to call the class from a test class, however, I'm hitting an error that I haven't been able to figure out. Hoping someone can point me to where I'm going wrong.

The apex class:
public class EuroOppRoundRobin {
    
    @InvocableMethod(label = 'Round Robin European Opps')
   
    public static void RoundRobin(List<Id> OppId){
        
        Opportunity Opp = [SELECT Id, OwnerId, OppAutoNum__c FROM Opportunity WHERE Id in :OppId];
    
        List<GroupMember> reps = [SELECT UserOrGroupId FROM GroupMember WHERE GroupId = '00G1g000003VvQnEAK' 
                           ORDER BY Id ASC];
        Integer Count = [SELECT COUNT() FROM GroupMember WHERE GroupId = '00G1g000003VvQnEAK'];
        Integer OppNum = integer.valueOf(Opp.OppAutoNum__c);
        Double roundRobin = OppNum / Count;
        Integer roundRobinId = roundRobin.intValue();
        
        Integer salesId = math.mod(roundRobinId, Count);
            
        Opp.OwnerId = reps[salesId].UserOrGroupId;
        update Opp;        
    }
		 
}
The test class:
@isTest
private class EuroRoundRobinTest {
    static testMethod void validateEuroRoundRobin() { 
        
        //Create & insert account
    	Account a = new Account(Name = 'Test Account', Sales_Territory__c = 'Europe', OwnerId = '0053i000002gvY2AAI');
        System.debug('The accounts name is ' + a.Name + ' and the sales territroy is ' + a.Sales_Territory__c + 
                     ' the owneris ' + a.OwnerId);
		insert a; 
        
        //Create & insert opportunity
        Opportunity opp = new Opportunity(Name = 'Test Opp', AccountId = a.Id, StageName = 'Pre-Qualified', 
                                          CloseDate = Date.today(), Payment_Frequency__c = 'Annual', 
                                          OwnerId = '0053i000002gvY2AAI');
        System.debug(opp.Name + opp.AccountId + opp.StageName + opp.CloseDate + opp.Payment_Frequency__c + opp.OwnerId); 
        insert opp; 
        
        //Retrieve the test opp and check if owner has updated
        List<Opportunity> OppId = [SELECT Id FROM Opportunity WHERE Id =: opp.Id];
        
        EuroOppRoundRobin.RoundRobin(OppId);  
        System.assertNotEquals('0053i000002gvY2AAI', opp.OwnerId);           
    }
}
The error I'm getting is on line 21 in the test class when I try to invoike the apex class and the error is: Method does not exist or incorrect signature: void RoundRobin(List<Opportunity>) from the type EuroOppRoundRobin
EuroOppRoundRobin.RoundRobin(OppId);

I appreciate any guidance, thanks!