• Matthew Ritter 17
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies
public static List<Lead> leadsThatMissed(List<Lead> leads) {
		List<Lead> missedLeads = new List<Lead>();
		for (Lead ld : leads) {
			if( ld.Next_Call_Date__c == Date.today().addDays(-1)) {
				ld.Call_Type__c = 'Missed';
				ld.Next_Call_Date__c = 
					ld.Next_Call_Date__c.addDays(1);
				missedLeads.add(ld);
			}
		}
		return missedLeads;
	}
In the above snippet on an Apex class, the ld.Next_Call_Date__c field is a date/time field and I need to get the date value from that field so the comparison works. Basically, I want to say If DATEVALUE(Next_Call_Date__C) == YESTERDAY then do everyhting in the code. 

I tried ld.Next_Call_Date__c.date but that did not work. Any thoughts? Thanks.
 
When querying objects via the  Bulk API, timestamps and dates are returned as millis not strings.  This is inconsistent with other salesforce APIs.  For timestamps this is not necessarily a problem since the conversion is straight-forward and all timezones are UTC-based.  For dates, it is actively returning incorrect values.  Our organization's default timezone is CST and we've verified that our dates are being stored as dates in CST.  When the Bulk API returns millis, they are being returned as midnight UTC instead of midnight in our default time zone.  Realistically, it should not be returning millis and indicating any time zone opinion at all since there is no time zone information stored on a date type. Anyone have some insights into this?
Hi,

Need some quick help for a test class that I did not write (and I am not a developer, but an admin) We need to make one change to the code, but the class is only covering 72% so we cannot deploy

This is our Code:

global class BW_AggregateROMCount implements Database.Batchable<sObject>, Database.Stateful{
    global Map<Id, Boolean> visitedMap;
    global List<DmlException> errors;
    String query;   
    global BW_AggregateROMCount() {
        visitedMap = new Map<Id, Boolean>();
        errors = new List<DmlException>();
        String commaSeparatedOwnerIds = String.join(new List<Id>(LeadHelper.getUsersWithActiveROMs()), '\',\'');
        this.query = 'SELECT Id, OwnerId FROM Lead WHERE (Status=\'New\' OR Status=\'Called\') AND OwnerId IN (\'' + commaSeparatedOwnerIds + '\') ORDER BY OwnerId';
    }
    global Database.QueryLocator start(Database.BatchableContext BC) {
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, List<sObject> scope) {
        try {
            if (!scope.isEmpty()) {
                BW_AggregateROMCountService.executeROMCount(scope, visitedMap);
            }
        }
        catch (DmlException de) {
            errors.add(de);
        }
    }
    global void finish(Database.BatchableContext BC) {
        if (!errors.isEmpty()) {
            ROM_Batch_Settings__c settings = ROM_Batch_Settings__c.getInstance();
            if (String.isNotBlank(settings.Batch_Error_Email_Recipient__c)) {
                BW_AggregateROMCountService.emailErrors(errors, settings.Batch_Error_Email_Recipient__c);
            }
        }
    }   
}

And this is the test:

@isTest
private class BW_AggregateROMCountTest {
    
    @testSetup static void setup() {
        Id profileId = [SELECT Id FROM Profile WHERE Name like '%Sales%' LIMIT 1].Id;
        User testUser = BW_TestingUtils.createUsers(1, profileId, 'Dylan', 'Bobward', false)[0];
        testUser.Assignment_Group_Active__c = true;
        insert testUser;

        Assignment_Group__c testAG = BW_TestingUtils.createAssignmentGroup('Austin Distribution', true, true);

        Assignment_Group_Member__c testAGM = BW_TestingUtils.createAssignmentGroupMember(testAG.Id, true, new List<Id>{testUser.Id}, true)[0];

        Record_Ownership_Maximum__c testROM = BW_TestingUtils.createRecordOwnershipMaxes(true, new List<Id>{testUser.Id}, false)[0];
        testROM.Lead_Current_Number_of_Records__c = 50;
        insert testROM;

        List<Lead> testLeads = new List<Lead>();
        for (Integer i=0; i<10; i++) {
            Lead l = new Lead();
            l.LastName = 'NewLead';
            l.Company = 'NewLead';
            l.Status = 'New';
            l.OwnerId = testUser.Id;
            testLeads.add(l);
        }
        for (Integer i=0; i<5; i++) {
            Lead l = new Lead();
            l.LastName = 'NotNewLead';
            l.Company = 'NotNewLead';
            l.Status = 'Not New';
            l.OwnerId = testUser.Id;
            testLeads.add(l);
        }
        insert testLeads;
    }

    static testMethod void testBatch() {

        Test.startTest();

            BW_AggregateROMCount countBatch = new BW_AggregateROMCount();
            Database.executeBatch(countBatch, 15);

        Test.stopTest();

        System.assertEquals(10, [SELECT Id, Lead_Current_Number_of_Records__c FROM Record_Ownership_Maximum__c LIMIT 1].Lead_Current_Number_of_Records__c,
            'Only the new leads should count towards the Record Count');
    }

    static testMethod void testEmailErrors() {
        List<Lead> testLeads = [SELECT Id FROM Lead];
        for (Lead ld : testLeads) {
            ld.LastName = null;
        }

        Test.startTest();

        try {
            update testLeads;
        }
        catch (DmlException de) {
            BW_AggregateROMCountService.emailErrors(new List<DmlException>{de}, 'test.email@testEmail.test');
        }
        
        Test.stopTest();

        
    }
    
}

We can get it to run, but its only at 72% and not sure why. PLEASE HELP!

I want a custom link to open multiple tabs with one click. Right now we have a bunch of links that open only one tab at a time. Is this possible? I have tried, but cannot figure out the Java Script to make it work.

What we have now:
Custom Link 1 =
window.open("http://www.google.com/search?q={!Lead.Company} {!Lead.City__c} {!Lead.State__c}")

Custom Link 2 = 
window.open("https://foursquare.com/explore?near={!Lead.City__c}%2C%20{!Lead.State__c}&q={!SUBSTITUTE(JSENCODE(Lead.Company),'&','and')}")

Custom Link 3 = etc.

What I want is:
Custom Link =
window.open("https://foursquare.com/explore?near={!Lead.City__c}%2C%20{!Lead.State__c}&q={!SUBSTITUTE(JSENCODE(Lead.Company),'&','and')}") + window.open("http://www.google.com/search?q={!Lead.Company} {!Lead.City__c} {!Lead.State__c}") + etc...
  
public static List<Lead> leadsThatMissed(List<Lead> leads) {
		List<Lead> missedLeads = new List<Lead>();
		for (Lead ld : leads) {
			if( ld.Next_Call_Date__c == Date.today().addDays(-1)) {
				ld.Call_Type__c = 'Missed';
				ld.Next_Call_Date__c = 
					ld.Next_Call_Date__c.addDays(1);
				missedLeads.add(ld);
			}
		}
		return missedLeads;
	}
In the above snippet on an Apex class, the ld.Next_Call_Date__c field is a date/time field and I need to get the date value from that field so the comparison works. Basically, I want to say If DATEVALUE(Next_Call_Date__C) == YESTERDAY then do everyhting in the code. 

I tried ld.Next_Call_Date__c.date but that did not work. Any thoughts? Thanks.
 
I want a custom link to open multiple tabs with one click. Right now we have a bunch of links that open only one tab at a time. Is this possible? I have tried, but cannot figure out the Java Script to make it work.

What we have now:
Custom Link 1 =
window.open("http://www.google.com/search?q={!Lead.Company} {!Lead.City__c} {!Lead.State__c}")

Custom Link 2 = 
window.open("https://foursquare.com/explore?near={!Lead.City__c}%2C%20{!Lead.State__c}&q={!SUBSTITUTE(JSENCODE(Lead.Company),'&','and')}")

Custom Link 3 = etc.

What I want is:
Custom Link =
window.open("https://foursquare.com/explore?near={!Lead.City__c}%2C%20{!Lead.State__c}&q={!SUBSTITUTE(JSENCODE(Lead.Company),'&','and')}") + window.open("http://www.google.com/search?q={!Lead.Company} {!Lead.City__c} {!Lead.State__c}") + etc...