• Tyler Mowbrey 1
  • NEWBIE
  • 75 Points
  • Member since 2015

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 18
    Replies
I am trying to understand what I am doing wrong here.  I have defined a Set that will hold IDs then used the .add method to add the ID from a Case but it fails.  I've redefined the Set as a set of strings as well but either way I get a null pointer exception even though there is always at least 1 record in the list.

Here's a snippet of my class
Set<id> RecIds; 
for(Case c:cs){
            System.debug('***** entering loop c:cs cs.size() = ' + cs.size() + ' *****' );
            if(c.RecordTypeId==rsc){
                System.debug('***** inside rsc IF statement c.id = ' + c.id + ' ***** ');
            	RecIds.add(c.id);
                System.debug('***** c.id ' + c.id + ' was added to RecIds *****');
            }
and here's the debug log
 
15:04:01.036 (15036876514)|SYSTEM_METHOD_ENTRY|[24]|System.debug(ANY)
15:04:01.036 (15036881962)|USER_DEBUG|[24]|DEBUG|***** entering loop c:cs cs.size() = 1 *****
15:04:01.036 (15036886758)|SYSTEM_METHOD_EXIT|[24]|System.debug(ANY)
15:04:01.036 (15036944939)|SYSTEM_METHOD_ENTRY|[25]|Id.compareTo(Id, Id, Boolean)
15:04:01.036 (15036972914)|SYSTEM_METHOD_EXIT|[25]|Id.compareTo(Id, Id, Boolean)
15:04:01.036 (15036998417)|SYSTEM_METHOD_ENTRY|[26]|String.valueOf(Object)
15:04:01.037 (15037022793)|SYSTEM_METHOD_EXIT|[26]|String.valueOf(Object)
15:04:01.037 (15037039033)|SYSTEM_METHOD_ENTRY|[26]|System.debug(ANY)
15:04:01.037 (15037044727)|USER_DEBUG|[26]|DEBUG|***** inside rsc IF statement c.id = 500S0000007LWuXIAW ***** <=== c.id has a valid value
15:04:01.037 (15037049435)|SYSTEM_METHOD_EXIT|[26]|System.debug(ANY)
15:04:01.037 (15037108600)|METHOD_EXIT|[15]|01pS000000070OI|HOL_NA_CaseEscalated.processCase(LIST<Case>)  <=== trying to add it to the Set fails
15:04:01.037 (15037198686)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

Class.HOL_NA_CaseEscalated.processCase: line 27, column 1
Trigger.Cases: line 15, column 1
15:04:01.037 (15037221135)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object


 
I am trying to create a Test class for my controller extension class.  I have a custom object "Vehicle" that has a Master-Detail relationship to "Opportunity".
With my current Test class, i have 46% code coverage but unable to increase it.  Any help is greatly appreciated!

Extension Class:
public class VehicleExtension {
     Private List<Vehicle__c> vecs;
     Private Opportunity vecopp;
       
     public VehicleExtension(){
     }
  
    public VehicleExtension(ApexPages.StandardController controller) {
        this.vecopp= (Opportunity)controller.getRecord();
    }
    public List <Vehicle__c> getVehicles()
        {
         Id id = ApexPages.currentPage().getParameters().get('id');
         vecs =    [SELECT Name, Make__c,Group__c,Year_Built__c,VIN__c,Delivery_Date__c,Payment_Status1__c,Pickup_Date__c, of_Days__c,
                        Mileage_Requested__c,Internal_Cost_Total__c,Cost_Total__c
            FROM Vehicle__c where Vehicle__c.opportunity__c =:[select Name from Opportunity where Id =:id]];
         return vecs;
        }
   
   public pageReference saveStatusChange(){
        update this.vecs;
        return null;
    }
 }



Test Class:
@isTest
public class VehicleTest{
static testMethod void test() {

    	VehicleExtension fe = new VehicleExtension();
    	List<Vehicle__C> events = fe.getVehicles();
    	fe.saveStatusChange();
    	System.assertNotEquals(null, events);
   
   
      	Opportunity ac = new Opportunity(Name ='tester', CloseDate =System.today().addDays(30),StageName ='Open Request', Posting_Date__c =System.today());
      	insert ac;
    
   		ApexPages.StandardController stdController = new ApexPages.StandardController(ac); 
      	VehicleExtension fe1 = new VehicleExtension(stdController);
       }
}
I'm passing this challenge, however when I actually test it out by clicking on an account in the account list item, I get this exception: 

"Something has gone wrong. Action failed: c$AccountMap$controller$accountSelected [TypeError: Cannot read property 'reuseTiles' of undefined] Failing descriptor: {c$AccountMap$controller$accountSelected}."

I did some debugging and found that the location and latitude of the account are indeed being capture by my event, so it looks like this might be a problem with the leaflet function map.panTo(). Does anyone know the solution to this issue? Here's my code, although it's exactly the same as the tutorial's.
 
({
    jsLoaded: function(component, event, helper) {

        setTimeout(function() {
            var map = L.map('map', {zoomControl: false}).setView([37.784173, -122.401557], 14);
            L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',
                {
                    attribution: 'Tiles © Esri'
                }).addTo(map);
            component.set("v.map", map);
        });
    },

    accountsLoaded: function(component, event, helper) {

        // Add markers
        var map = component.get('v.map');
        var accounts = event.getParam('accounts');
        for (var i=0; i<accounts.length; i++) {
            var account = accounts[i];
            var latLng = [account.Location__Latitude__s, account.Location__Longitude__s];
            L.marker(latLng, {account: account}).addTo(map);
        }  
    },

    accountSelected: function(component, event, helper) {
        // Center the map on the account selected in the list
        var map = component.get('v.map');
        var account = event.getParam("account");
        alert(account.Location__Latitude__s + ', ' + account.Location__Longitude__s);
        map.panTo([account.Location__Latitude__s, account.Location__Longitude__s]);
    }
})

 
Hello Everyone,

I am getting this error

Class.ProductTrainingTriggerHandler.DuplicateCheck: line 45, column 1 Trigger.Repproducttraining: line 6, column 1 18:18:43.109 (109971433)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

Below Is the Handler Class
public class ProductTrainingTriggerHandler
{
  public void DuplicateCheck(List<Rep_Product_Training__c> ListProductTrainingValues, Map<Id,Rep_Product_Training__c> oldMap)
  {
       List<String> RepIds = new List<String>();
      for(Rep_Product_Training__c ListRegistrationValue : ListProductTrainingValues)
      {
         RepIds.add(ListRegistrationValue.Contact__c);
         RepIds.add(ListRegistrationValue.Name);
      }
        Map<String,Set<String>> RepProductTrainingSetMap = new Map<String,Set<String>>();
        List<Rep_Product_Training__c> RepProductTraining = [SELECT Contact__c,Name,Training_Completion_Date__c 
                                                         FROM Rep_Product_Training__c WHERE Contact__c IN :RepIds AND Name IN:RepIds];
     system.debug('Error Values @@@@@@@@@@'+RepProductTraining);
      if(RepProductTraining.size()>0)
       {
           system.debug('RepProductTrainingSize------------------->'+RepProductTraining.size());
         for(Rep_Product_Training__c ProductTrainings:RepProductTraining)
         {
             
             if(RepProductTrainingSetMap.get(ProductTrainings.Contact__c)!=null)
             {
                 system.debug('ProdcutTrainingName-------------->'+ProductTrainings.Contact__c);
                 system.debug('Rep Product Training Value'+RepProductTrainingSetMap.get(ProductTrainings.Contact__c));
                 if(ProductTrainings.Name!= null)             
                 RepProductTrainingSetMap.get(ProductTrainings.Contact__c).add(ProductTrainings.Name);
                 system.debug('Values=================>'+RepProductTrainingSetMap.get(ProductTrainings.Contact__c).add(ProductTrainings.Name));
              }
             
             else{
                 if(ProductTrainings.Name != null)
                     RepProductTrainingSetMap.put(ProductTrainings.Name,new Set<String>{ProductTrainings.Name});
                 }
         }
        for(Rep_Product_Training__c ListRegistrationValue : ListProductTrainingValues)
         {
              if(ListRegistrationValue.Name != null){
                  if(RepProductTrainingSetMap.get(ListRegistrationValue.Contact__c).contains(ListRegistrationValue.Name))
                      ListRegistrationValue.Name.addError('Duplicate value entered!');
          }
             
         }
     }   
     
 }
}

Trigger Class

trigger Repproducttraining on Rep_Product_Training__c (after insert,after update,before Update,before insert) 
{
    ProductTrainingTriggerHandler ProductTriggerHandler = new ProductTrainingTriggerHandler();
    if(Trigger.isBefore || Trigger.isUpdate) 
    {
        ProductTriggerHandler.DuplicateCheck(Trigger.New, Trigger.newMap);
    }
    if(Trigger.isInsert ||  Trigger.isBefore)
        {
             ProductTriggerHandler.DuplicateCheck(Trigger.New, Trigger.newMap);
        }
}

Can you please help me tp fix


Thanks 

Regards,
Jyo
Hello,

I have a custom VF page that works exactly how I need, I am successfully inserting a new custom object (CO).  However I want to modify the Body property of CO before inserting it.  The code below shows what I am trying to do.  However the custom object record created has the following resulting string in the Body property (I put the word "test") into the orginal custom object body

"null null work at null
test"

Can someone tell me what I am missing?  The if statement does execute so I know that the custom object has properties set.

Here is the code...

At the top of the controller I have this line
public final LT_Note__c Note{get;set;}

public PageReference saveCO() {
    if(CO.Backdoor__c) {
            CO.Body__c = CO.Contact__r.FirstName + ' ' + CO.Contact__r.LastName + ' work at ' + CO.Client__r.Name + '\n' CO.Body__c;
    }  
        
    insert CO;  
}
I want to know how you could write a bit of code to do true reflection programming in Salesforce

So say you have a piece of data which has the name of functions and the apex code will take this and run the function you have entered, so if a new function is deployed to Salesforce you dont need to change this class with another if statement and will still be able to run the new function
How would I have an approval process start once someone tries to change ownership of an account record? I know I will need a bit of apex code. Is this possible for a beginner?
I want to populate a field that tells me how many years (consecutive or otherwise) an opportunity has been closed for a specific account. Why can't I do CloseDate.year() inside the aggregate function? (If I try to run count_distinct on a variable, I also get an error message).

Thank you!!
 
trigger YearsOfOpps on Opportunity (after update, after insert) {
List<Account> accs = 
        [SELECT Id, Years_of_Opps__c FROM Account WHERE Id IN
             (SELECT AccountId FROM Opportunity WHERE Id in:Trigger.newMap.keySet())];
    
     for(Account a: accs) {
        AggregateResult[] groupedResult = 
            [SELECT AccountId, COUNT_DISTINCT(CloseDate.year()) Yearr FROM Opportunity 
//the line above is throwing the compile error
                WHERE AccountId = :a.Id
                GROUP BY Account];
         Decimal aggregateYears = (Decimal)groupedResult[0].get('Yearr');
         a.Years_of_Opps__c = aggregateYears;
    }
    
    update accs;
}
}

 
Is there a way to create a sharing rule for cases that says "Share with person in field name = Contact Name"

Background:
We use cases in the marketing department so that internal people can request work from us. However, once the request comes in it gets reassigned to an internal marketing person. So now the case owner is someone other than the person that originated it.
In order to keep track of the original requestor we use the standard look up field "Contact Name" and we have all our users as part of a contact list under the corporate account.

I would like to share the cases with the person in the 'Contact Name = John Doe" 
Is this possible?
If so, how would I accomplish this?
thank you!
  • January 20, 2015
  • Like
  • 0
Hi @all,

I created a VF-page and if the user press on the save button, then the page should save the values (this is working fine) and refresh themself like pressing F5 on keyboard. Is this possible?

Regards
Robert
Hi, I repeatedly have to create contacts, accounts, opportunities, and countless other custom objects as dependencies for testing x, y, and z.  Perhaps I'm doing this wrong, but when I'm implementing a new trigger, I'm creating a test class for testing that trigger, and within that test class I have a number of methods which correspond one-to-one with my list of test cases that I'm intending to evaluate.  Within each of those methods I'm repeating all the setup tasks required over and over and over again....unnessessarily (I assume) adding significant (redundant) lines of code for test prep.

Is there any way I can abstract this repeated test prep into a "subroutine"?  My current understanding (and education) tells me that I can't, that each test method needs to be 100% "self contained"...but I feel that this can't possibly be right due to the high level of inefficiency.

Thanks!
  • January 20, 2015
  • Like
  • 0
Hi All, 

Any help is appreciated, I am at wits end   I am new to creating triggers and test classes but I have managed to get my trigger to 100% code coverage. When I attempt to upload my package I am getting an error telling me the following:

One or more Apex triggers lack test coverage. Add test coverage for the following triggers and upload again:
createTripDestination


"createTrip Destination" is the trigger that shows 100% coverage.  I'm used the developer console to remove all test results, bring the coverage back to 0, and re-run the test classes, bringing my trigger back to 100%.

Has anyone seen this before?  It seems strange to me but I can't figure it out.
I am trying to understand what I am doing wrong here.  I have defined a Set that will hold IDs then used the .add method to add the ID from a Case but it fails.  I've redefined the Set as a set of strings as well but either way I get a null pointer exception even though there is always at least 1 record in the list.

Here's a snippet of my class
Set<id> RecIds; 
for(Case c:cs){
            System.debug('***** entering loop c:cs cs.size() = ' + cs.size() + ' *****' );
            if(c.RecordTypeId==rsc){
                System.debug('***** inside rsc IF statement c.id = ' + c.id + ' ***** ');
            	RecIds.add(c.id);
                System.debug('***** c.id ' + c.id + ' was added to RecIds *****');
            }
and here's the debug log
 
15:04:01.036 (15036876514)|SYSTEM_METHOD_ENTRY|[24]|System.debug(ANY)
15:04:01.036 (15036881962)|USER_DEBUG|[24]|DEBUG|***** entering loop c:cs cs.size() = 1 *****
15:04:01.036 (15036886758)|SYSTEM_METHOD_EXIT|[24]|System.debug(ANY)
15:04:01.036 (15036944939)|SYSTEM_METHOD_ENTRY|[25]|Id.compareTo(Id, Id, Boolean)
15:04:01.036 (15036972914)|SYSTEM_METHOD_EXIT|[25]|Id.compareTo(Id, Id, Boolean)
15:04:01.036 (15036998417)|SYSTEM_METHOD_ENTRY|[26]|String.valueOf(Object)
15:04:01.037 (15037022793)|SYSTEM_METHOD_EXIT|[26]|String.valueOf(Object)
15:04:01.037 (15037039033)|SYSTEM_METHOD_ENTRY|[26]|System.debug(ANY)
15:04:01.037 (15037044727)|USER_DEBUG|[26]|DEBUG|***** inside rsc IF statement c.id = 500S0000007LWuXIAW ***** <=== c.id has a valid value
15:04:01.037 (15037049435)|SYSTEM_METHOD_EXIT|[26]|System.debug(ANY)
15:04:01.037 (15037108600)|METHOD_EXIT|[15]|01pS000000070OI|HOL_NA_CaseEscalated.processCase(LIST<Case>)  <=== trying to add it to the Set fails
15:04:01.037 (15037198686)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

Class.HOL_NA_CaseEscalated.processCase: line 27, column 1
Trigger.Cases: line 15, column 1
15:04:01.037 (15037221135)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object


 
I am trying to create a Test class for my controller extension class.  I have a custom object "Vehicle" that has a Master-Detail relationship to "Opportunity".
With my current Test class, i have 46% code coverage but unable to increase it.  Any help is greatly appreciated!

Extension Class:
public class VehicleExtension {
     Private List<Vehicle__c> vecs;
     Private Opportunity vecopp;
       
     public VehicleExtension(){
     }
  
    public VehicleExtension(ApexPages.StandardController controller) {
        this.vecopp= (Opportunity)controller.getRecord();
    }
    public List <Vehicle__c> getVehicles()
        {
         Id id = ApexPages.currentPage().getParameters().get('id');
         vecs =    [SELECT Name, Make__c,Group__c,Year_Built__c,VIN__c,Delivery_Date__c,Payment_Status1__c,Pickup_Date__c, of_Days__c,
                        Mileage_Requested__c,Internal_Cost_Total__c,Cost_Total__c
            FROM Vehicle__c where Vehicle__c.opportunity__c =:[select Name from Opportunity where Id =:id]];
         return vecs;
        }
   
   public pageReference saveStatusChange(){
        update this.vecs;
        return null;
    }
 }



Test Class:
@isTest
public class VehicleTest{
static testMethod void test() {

    	VehicleExtension fe = new VehicleExtension();
    	List<Vehicle__C> events = fe.getVehicles();
    	fe.saveStatusChange();
    	System.assertNotEquals(null, events);
   
   
      	Opportunity ac = new Opportunity(Name ='tester', CloseDate =System.today().addDays(30),StageName ='Open Request', Posting_Date__c =System.today());
      	insert ac;
    
   		ApexPages.StandardController stdController = new ApexPages.StandardController(ac); 
      	VehicleExtension fe1 = new VehicleExtension(stdController);
       }
}