• SFHelpMePlease
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 10
    Replies
Hello - could any one help me with this problem in my test class?
Test class is having an issue with this statement:
if (String.isNotBlank(AcctId)){
     rec =  [Select Id, Name from Acct__c  where Id1__c =: decimal.valueOf(Id_in) and AcctId__c =: AcctId ];
 }

Error is: System.NullPointerException: Argument cannot be null 
SOQL will not be run if the AcctId is blank or null.
Would you know how I could fix?
 
Hi Everyone,
The contacts and account lookups work well on the standard objects.
I have created some custom objects and have been able to set up relations between account and my custom object. 
Data displays well in the reports.

My issue is I cannot add contacts to this report.
I have tried setting up lookup fields on both the account and contact objects, no luck (contact fields are blank)

In the report types, I tried adding the contact  object using a look up field (contact fields are blank).
Can you offer any detailed instruction on how I can create a report to show
Accounts, Contacts and my custom object  or  Contacts, Accounts and my custom object?

Thanks
 
Could you help me with my test class, I can only get 26% coverage?
I tried googling and different test but cannot get past 26% 


global class dtCheck implements Database.Batchable<sObject> {

    global Database.QueryLocator start(Database.BatchableContext BC) {
        //some records in ActivityHistory are not in Task table due to archive
        //lets capture all of the account ids
        Set<Id> ids = new Set<Id>();
        List<Account> acctList = new List<Account>();
        for(Account a : [Select Id,(Select Id, subject, whoid, whatid, accountid, createddate from ActivityHistories) FROM Account ])
        {
            if(!a.ActivityHistories.isEmpty()){
               ids.add(((Id)a.get('Id')));
               System.debug('ActivityHistory id ' + (Id)a.get('Id'));
            }
        }

        //could be dup accountIds between ActivityHistory and Task, select the distinct Ids
        Set<Id> distinctIds = new Set<Id>();
        List<AggregateResult> acctDistinctList= [SELECT Id From Account where Id in :ids group by Id];
        for (AggregateResult ar2 : acctDistinctList) {
          distinctIds.add(((Id)ar2.get('Id')));
          System.debug('Account to update ' + (Id)ar2.get('Id'));
        }

        String query = 'Select Id, Name, task_Over_90_Days__c  FROM Account  where Id in :distinctIds ';

        return Database.getQueryLocator(query);
    }


    global void execute(Database.BatchableContext BC, List<Account> scope) {
        
        // process each batch of records
        System.debug('execute batch: ' + scope.size());

        for(Account acc : scope)
        {
            integer noOfDays = 0;
            integer over90Days = 0;
         
            
            List<Task> taskList = [SELECT  Id, Subject, CreatedDate, AccountId, TaskSubtype FROM Task where AccountId = :acc.Id];
            for(Task t : taskList)
            {
                noOfDays = Date.today().daysBetween(t.CreatedDate.Date())*-1;
                if (noOfDays > 90)
                    over90Days = over90Days + 1;

            }
            List<Account> acctHistories = [Select Id,(Select Id, subject, whoid, whatid, accountid, createddate from ActivityHistories ) FROM Account where id = :acc.Id];
            for (Account a: acctHistories) {
                for (ActivityHistory ah : a.getSObjects('ActivityHistories')) 
                {
                    noOfDays = Date.today().daysBetween(ah.CreatedDate.Date())*-1;
                    if (noOfDays > 90)
                        over90Days = over90Days + 1;
                }
            }
            acc.Over_90_Days__c  = over90Days  ;
            update acc;
        }

         
    }   
      
    global void finish(Database.BatchableContext BC) {
        // execute any post-processing operations
  }
}






@isTest
public class dtCheckTest 
{
    static testMethod void testMethod1() 
    {
        List<Account> lstAcct = new List<Account>();
        List<Task> lstTask = new List<Task>();
        for(Integer i=0 ;i <10;i++)
        {
            Account acc = new Account();
            acc.Name ='Test Name'+i;
            lstAcct.add(acc);
        }
        insert lstAcct ;

        List<Account> acct = [Select Id, Name from Account Limit 1] ;
        for (Account a : acct)
        {
            Task tsk = new Task();
            tsk.Subject = 'Test ';
            tsk.WhatId = a.Id;
            lstTask.add(tsk);
        }
        insert lstTask ;

        

        Test.startTest();
        dtCheck obj = new dtCheck();
        DataBase.executeBatch(obj,10); 
        Test.stopTest();
    }
}
Hello,

I created a test class for the below apex code but cannot get coverage when calling the AccountConversationUpdate  execute() (It is red in the console).  Could you explain what I need to do. The code works and gives me the results I need.    Thanks!

global class AccountUpdate implements Database.Batchable<sObject> {

    global Database.QueryLocator start(Database.BatchableContext BC) {

        List<AggregateResult> acctIdList= [SELECT AccountId From Task where subject like 'Re%' group by AccountId];
        Set<Id> ids = new Set<Id>();
        for (AggregateResult ar : acctIdList) {
          ids.add(((Id)ar.get('AccountId')));
          System.debug('Account to update ' + (Id)ar.get('AccountId'));
       }
        String query = 'SELECT  Id, Name  From Account where Id in :ids';
        return Database.getQueryLocator(query);
    }

     
    global void execute(Database.BatchableContext BC, List<Account> acctList) {
        
        integer noOfDays = 0;
        integer 90Days =0;
         
        for(Account acc : acctList)
        {
            List<Task> taskList = [SELECT  Id, Subject, CreatedDate, AccountId, TaskSubtype FROM Task where subject like 'Re%' and AccountId = :acc.Id];
            for(Task t : taskList)
            {
                noOfDays = Date.today().daysBetween(t.CreatedDate.Date())*-1;
                if (noOfDays > 90)
                    90Days = 90Days + 1;
            }
            acc.90_Days__c  = 90Days ;
            update acctList;
        }
    }   
     
    global void finish(Database.BatchableContext BC) {
        // execute any post-processing operations
  }
}



@isTest
public class AccountUpdateTest 
{
    static testMethod void testMethod1() 
    {
        List<Account> lstAcct = new List<Account>();
        List<Task> lstTask = new List<Task>();
        for(Integer i=0 ;i <200;i++)
        {
            Account acc = new Account();
            acc.Name ='Name'+i;
            lstAcct.add(acc);

            Task tsk = new Task();
            tsk.Subject = 'Re ' + i;
            tsk.TaskSubType = 'Call';
            tsk.WhatId = acc.Id;
            lstTask.add(tsk);

        }
        insert lstAcct ;
        insert lstTask ;

        Test.startTest();
            AccountConversationUpdate  obj = new AccountConversationUpdate();
            DataBase.executeBatch(obj); 
        Test.stopTest();
    }
}
Hello,
I have the below code and now need to write a test class to promote code to production.  I have attempted to write a test class but the account trigger is not getting any code coverage. Am I inserting the data in the correct place. Could you help me? 

    trigger AccountTrigger on Account (before insert, before update) 
    {
        TriggerHandler handler = new TriggerHandler();
    
        if(TriggerHandler.runTriggerOnce) {
            TriggerHandler.runTriggerOnce = false;
    
            if(Trigger.IsUpdate) {
                handler.accountBeforeUpdate();
            }    
       }
    }
    
    public class TriggerHandler
    {
        public static boolean runTriggerOnce= true; 
    
        public void accountBeforeUpdate()
        { 
            accountUpdates();
        }
    
        private void accountUpdates()
        {
            for(Account newAcc: (List<Account>)Trigger.New)
            {
                List<Other_Opp__c> opps = [Select Id, Name, Type__c From Other_Opp__c WHERE Opp_Name__c = :newAcc.Id ];
                if(opps.size() > 0){
                     For (Other_Opp__c f : opps) {
                        f.Type__c = newAcc.Field1__c;
                     }
                     update opps
                }
                
            }
    
    @isTest
    private class TriggerHandler_Test{
      @isTest static void test1() {
    Test.startTest();
    
            Account acc = new Account(Name = 'New Acct');
            insert acc;
    
            Opp_Name__c  opp = new Opp_Name__c (Name = 'New Opp');
            insert opp;
            
            
            Account a = [Select Id, Name, Field1__c from Account where Id = :acc.Id];
            a.Field1__c = 'test1';
            update a;
    
    Test.stopTest();
        }
    }
Having many problems today working with dataloader.
- stopped using edge
- in IE, I have selected the TLS 1.2 option only
- updated to Java 8
- uninstalled old dataloaders
- installed newest dataloader (39 version)
Try logging in to dataloader and receive message stating I have to select TLS1.0, TLS1.1 and TLS1.2, I choose the newest TLS1.2
Try numerous times logging in, finally it allows me (no other change made between tries)
I load data and will just stop in the middle of the load.
Any suggestions? spent a lot of time just trying to load information into 2 objects.
select upload, object and file and mapping, can't set up the job or fails in between.
Sometimes it works, most time not.
Any suggestions.

 
How would I check if the URL is populated in the below code?
What I would like to do is display 'Open URL' if a URL exists.
If no URL, then I would like to display 'No URL Available' or leave it blank.

 <apex:pageBlockSectionItem >
      <apex:outputLabel value="MY URL" />
     <apex:outputLink value="{!defaultURL.MY_URL__c}" target="_blank">Open URL</apex:outputLink>
 </apex:pageBlockSectionItem>
 
I am at 71%, 4 lines of code cannot be run in the test for some reason.
When I test myself in Salesforce it works (those lines of code are running).
How can I get these lines of code to run?
1. Lines not running, in second for loop
   {   nextId=Integer.Valueof(c.next_id__c);     }
2. third for loop
            btnRecord.next_id__c = newid + 1;
            btnRecord.last_id__c = newId;
            btnRecord.last_assigned_starting_id__c = nextId;
            btnRecord.last_assigned_ending_id__c = newId;
trigger getNextId on tracking__c (before insert, before update) {
    Integer newId;
    Integer lastId;
    Integer nextId;
    newId=0;
    lastId=0;
    nextId =0;
    //add the total accounts to the last_id
    for (tracking__c bt: Trigger.new) {
        //get the next id
        List<tracking_next_id__c> btnxtid = [SELECT  next_id__c FROM tracking_next_id__c];
        for (tracking_next_id__c c : btnxtid )
        {
           nextId=Integer.Valueof(c.next_id__c);
        }
        newId = Integer.Valueof(bt.total_account__c) + nextId;
        bt.starting_id__c = nextId;
        bt.ending_id__c = newId;
       
        tracking_next_id__c[] nextIdToUpdate = [SELECT last_id__c, next_id__c, last_assigned_starting_id__c, last_assigned_ending_id__c FROM tracking_next_id__c];
        for(tracking_next_id__c btnRecord : nextIdToUpdate ){
            btnRecord.next_id__c = newid + 1;
            btnRecord.last_id__c = newId;
            btnRecord.last_assigned_starting_id__c = nextId;
            btnRecord.last_assigned_ending_id__c = newId;
        }
        update nextIdToUpdate ;
   }
}
----------------------------------------------------------------------------------
--Test
----------------------------------------------------------------------------------
@isTest
private class getNextIdTest {
    static testMethod void validateOnInsert(){
Test.startTest();
    tracking__c b = new tracking__c(total_account__c=Integer.Valueof(99));
    System.debug('before insert : ' + b.total_account__c);
    insert b;
    System.debug('after insert : ' + b.total_account__c);
    List<tracking__c> customObjectList = [SELECT total_account__c FROM tracking__c ];
    for(bid_tracking__c ont : customObjectList){
      ont.total_account__c = 5;
      }
      update customObjectList;
Test.stopTest();
}
}
 
Hello - could any one help me with this problem in my test class?
Test class is having an issue with this statement:
if (String.isNotBlank(AcctId)){
     rec =  [Select Id, Name from Acct__c  where Id1__c =: decimal.valueOf(Id_in) and AcctId__c =: AcctId ];
 }

Error is: System.NullPointerException: Argument cannot be null 
SOQL will not be run if the AcctId is blank or null.
Would you know how I could fix?
 
Hi Everyone,
The contacts and account lookups work well on the standard objects.
I have created some custom objects and have been able to set up relations between account and my custom object. 
Data displays well in the reports.

My issue is I cannot add contacts to this report.
I have tried setting up lookup fields on both the account and contact objects, no luck (contact fields are blank)

In the report types, I tried adding the contact  object using a look up field (contact fields are blank).
Can you offer any detailed instruction on how I can create a report to show
Accounts, Contacts and my custom object  or  Contacts, Accounts and my custom object?

Thanks
 
Could you help me with my test class, I can only get 26% coverage?
I tried googling and different test but cannot get past 26% 


global class dtCheck implements Database.Batchable<sObject> {

    global Database.QueryLocator start(Database.BatchableContext BC) {
        //some records in ActivityHistory are not in Task table due to archive
        //lets capture all of the account ids
        Set<Id> ids = new Set<Id>();
        List<Account> acctList = new List<Account>();
        for(Account a : [Select Id,(Select Id, subject, whoid, whatid, accountid, createddate from ActivityHistories) FROM Account ])
        {
            if(!a.ActivityHistories.isEmpty()){
               ids.add(((Id)a.get('Id')));
               System.debug('ActivityHistory id ' + (Id)a.get('Id'));
            }
        }

        //could be dup accountIds between ActivityHistory and Task, select the distinct Ids
        Set<Id> distinctIds = new Set<Id>();
        List<AggregateResult> acctDistinctList= [SELECT Id From Account where Id in :ids group by Id];
        for (AggregateResult ar2 : acctDistinctList) {
          distinctIds.add(((Id)ar2.get('Id')));
          System.debug('Account to update ' + (Id)ar2.get('Id'));
        }

        String query = 'Select Id, Name, task_Over_90_Days__c  FROM Account  where Id in :distinctIds ';

        return Database.getQueryLocator(query);
    }


    global void execute(Database.BatchableContext BC, List<Account> scope) {
        
        // process each batch of records
        System.debug('execute batch: ' + scope.size());

        for(Account acc : scope)
        {
            integer noOfDays = 0;
            integer over90Days = 0;
         
            
            List<Task> taskList = [SELECT  Id, Subject, CreatedDate, AccountId, TaskSubtype FROM Task where AccountId = :acc.Id];
            for(Task t : taskList)
            {
                noOfDays = Date.today().daysBetween(t.CreatedDate.Date())*-1;
                if (noOfDays > 90)
                    over90Days = over90Days + 1;

            }
            List<Account> acctHistories = [Select Id,(Select Id, subject, whoid, whatid, accountid, createddate from ActivityHistories ) FROM Account where id = :acc.Id];
            for (Account a: acctHistories) {
                for (ActivityHistory ah : a.getSObjects('ActivityHistories')) 
                {
                    noOfDays = Date.today().daysBetween(ah.CreatedDate.Date())*-1;
                    if (noOfDays > 90)
                        over90Days = over90Days + 1;
                }
            }
            acc.Over_90_Days__c  = over90Days  ;
            update acc;
        }

         
    }   
      
    global void finish(Database.BatchableContext BC) {
        // execute any post-processing operations
  }
}






@isTest
public class dtCheckTest 
{
    static testMethod void testMethod1() 
    {
        List<Account> lstAcct = new List<Account>();
        List<Task> lstTask = new List<Task>();
        for(Integer i=0 ;i <10;i++)
        {
            Account acc = new Account();
            acc.Name ='Test Name'+i;
            lstAcct.add(acc);
        }
        insert lstAcct ;

        List<Account> acct = [Select Id, Name from Account Limit 1] ;
        for (Account a : acct)
        {
            Task tsk = new Task();
            tsk.Subject = 'Test ';
            tsk.WhatId = a.Id;
            lstTask.add(tsk);
        }
        insert lstTask ;

        

        Test.startTest();
        dtCheck obj = new dtCheck();
        DataBase.executeBatch(obj,10); 
        Test.stopTest();
    }
}
Hello,

I created a test class for the below apex code but cannot get coverage when calling the AccountConversationUpdate  execute() (It is red in the console).  Could you explain what I need to do. The code works and gives me the results I need.    Thanks!

global class AccountUpdate implements Database.Batchable<sObject> {

    global Database.QueryLocator start(Database.BatchableContext BC) {

        List<AggregateResult> acctIdList= [SELECT AccountId From Task where subject like 'Re%' group by AccountId];
        Set<Id> ids = new Set<Id>();
        for (AggregateResult ar : acctIdList) {
          ids.add(((Id)ar.get('AccountId')));
          System.debug('Account to update ' + (Id)ar.get('AccountId'));
       }
        String query = 'SELECT  Id, Name  From Account where Id in :ids';
        return Database.getQueryLocator(query);
    }

     
    global void execute(Database.BatchableContext BC, List<Account> acctList) {
        
        integer noOfDays = 0;
        integer 90Days =0;
         
        for(Account acc : acctList)
        {
            List<Task> taskList = [SELECT  Id, Subject, CreatedDate, AccountId, TaskSubtype FROM Task where subject like 'Re%' and AccountId = :acc.Id];
            for(Task t : taskList)
            {
                noOfDays = Date.today().daysBetween(t.CreatedDate.Date())*-1;
                if (noOfDays > 90)
                    90Days = 90Days + 1;
            }
            acc.90_Days__c  = 90Days ;
            update acctList;
        }
    }   
     
    global void finish(Database.BatchableContext BC) {
        // execute any post-processing operations
  }
}



@isTest
public class AccountUpdateTest 
{
    static testMethod void testMethod1() 
    {
        List<Account> lstAcct = new List<Account>();
        List<Task> lstTask = new List<Task>();
        for(Integer i=0 ;i <200;i++)
        {
            Account acc = new Account();
            acc.Name ='Name'+i;
            lstAcct.add(acc);

            Task tsk = new Task();
            tsk.Subject = 'Re ' + i;
            tsk.TaskSubType = 'Call';
            tsk.WhatId = acc.Id;
            lstTask.add(tsk);

        }
        insert lstAcct ;
        insert lstTask ;

        Test.startTest();
            AccountConversationUpdate  obj = new AccountConversationUpdate();
            DataBase.executeBatch(obj); 
        Test.stopTest();
    }
}
Hello,
I have the below code and now need to write a test class to promote code to production.  I have attempted to write a test class but the account trigger is not getting any code coverage. Am I inserting the data in the correct place. Could you help me? 

    trigger AccountTrigger on Account (before insert, before update) 
    {
        TriggerHandler handler = new TriggerHandler();
    
        if(TriggerHandler.runTriggerOnce) {
            TriggerHandler.runTriggerOnce = false;
    
            if(Trigger.IsUpdate) {
                handler.accountBeforeUpdate();
            }    
       }
    }
    
    public class TriggerHandler
    {
        public static boolean runTriggerOnce= true; 
    
        public void accountBeforeUpdate()
        { 
            accountUpdates();
        }
    
        private void accountUpdates()
        {
            for(Account newAcc: (List<Account>)Trigger.New)
            {
                List<Other_Opp__c> opps = [Select Id, Name, Type__c From Other_Opp__c WHERE Opp_Name__c = :newAcc.Id ];
                if(opps.size() > 0){
                     For (Other_Opp__c f : opps) {
                        f.Type__c = newAcc.Field1__c;
                     }
                     update opps
                }
                
            }
    
    @isTest
    private class TriggerHandler_Test{
      @isTest static void test1() {
    Test.startTest();
    
            Account acc = new Account(Name = 'New Acct');
            insert acc;
    
            Opp_Name__c  opp = new Opp_Name__c (Name = 'New Opp');
            insert opp;
            
            
            Account a = [Select Id, Name, Field1__c from Account where Id = :acc.Id];
            a.Field1__c = 'test1';
            update a;
    
    Test.stopTest();
        }
    }
I am at 71%, 4 lines of code cannot be run in the test for some reason.
When I test myself in Salesforce it works (those lines of code are running).
How can I get these lines of code to run?
1. Lines not running, in second for loop
   {   nextId=Integer.Valueof(c.next_id__c);     }
2. third for loop
            btnRecord.next_id__c = newid + 1;
            btnRecord.last_id__c = newId;
            btnRecord.last_assigned_starting_id__c = nextId;
            btnRecord.last_assigned_ending_id__c = newId;
trigger getNextId on tracking__c (before insert, before update) {
    Integer newId;
    Integer lastId;
    Integer nextId;
    newId=0;
    lastId=0;
    nextId =0;
    //add the total accounts to the last_id
    for (tracking__c bt: Trigger.new) {
        //get the next id
        List<tracking_next_id__c> btnxtid = [SELECT  next_id__c FROM tracking_next_id__c];
        for (tracking_next_id__c c : btnxtid )
        {
           nextId=Integer.Valueof(c.next_id__c);
        }
        newId = Integer.Valueof(bt.total_account__c) + nextId;
        bt.starting_id__c = nextId;
        bt.ending_id__c = newId;
       
        tracking_next_id__c[] nextIdToUpdate = [SELECT last_id__c, next_id__c, last_assigned_starting_id__c, last_assigned_ending_id__c FROM tracking_next_id__c];
        for(tracking_next_id__c btnRecord : nextIdToUpdate ){
            btnRecord.next_id__c = newid + 1;
            btnRecord.last_id__c = newId;
            btnRecord.last_assigned_starting_id__c = nextId;
            btnRecord.last_assigned_ending_id__c = newId;
        }
        update nextIdToUpdate ;
   }
}
----------------------------------------------------------------------------------
--Test
----------------------------------------------------------------------------------
@isTest
private class getNextIdTest {
    static testMethod void validateOnInsert(){
Test.startTest();
    tracking__c b = new tracking__c(total_account__c=Integer.Valueof(99));
    System.debug('before insert : ' + b.total_account__c);
    insert b;
    System.debug('after insert : ' + b.total_account__c);
    List<tracking__c> customObjectList = [SELECT total_account__c FROM tracking__c ];
    for(bid_tracking__c ont : customObjectList){
      ont.total_account__c = 5;
      }
      update customObjectList;
Test.stopTest();
}
}