• IKZ
  • NEWBIE
  • 20 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 8
    Replies
In lightning tables we have below attributes to determine if field is datetime or just date:
"typeAttributes": {
               "includesTime" : true,
               "year": "numeric",
               "month": "short",
               "day": "numeric",
               "hour": "2-digit",
               "minute": "2-digit"
}
but sometimes, when the primary tab table won't load correctly (which looks like SF bug anyway) we get the [Value null out of range for Intl.DateTimeFormat options property hour] error . Sf support is saying that because our code below return null value which is a bad practice, as lightning:formattedDateTime does not expect nulls. They recommend to update this to a non-null value.
public class LightningTableTypeAttributes{ @AuraEnabled 
public Boolean includesTime;
@AuraEnabled
public String hour { get { return includesTime != null && includesTime ? '2-digit' : null; } }

But I don't understand what else can be used if that’s the IF condition to determine if it’s datetime field or just date field?

Any help would be grately appreciated 
  • January 28, 2021
  • Like
  • 0
I've tried both options in custom lightning component and they work in sales app but as soon as I switch to console app refresh doesn't happen
1. 
refreshAndClose: function (component) {
        $A.get("e.force:refreshView").fire();
        let sObjectEvent = $A.get("e.force:navigateToSObject");
        sObjectEvent.setParams({
            "recordId": component.get("v.recordId")
        });
        sObjectEvent.fire();
    }

2.
({
    refreshFocusedTab : function(component, event, helper) {
        var workspaceAPI = component.find("workspace");
        workspaceAPI.getFocusedTabInfo().then(function(response) {
            var focusedTabId = response.tabId;
            workspaceAPI.refreshTab({
                      tabId: focusedTabId,
                      includeAllSubtabs: true
             });
        })
        .catch(function(error) {
            console.log(error);
        });
    }
})

and as per https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_lightning_refreshTab.htm​​​​​​​ efreshTab() only works in Lightning console apps

any suggestions please?

​​​​​​​thanks
 
  • September 10, 2020
  • Like
  • 0
Whenever there is an active complaint linked to an account I would like to update Account.Active_Complaints__c checkbox. Objects are linked through a lookup Complaints__c.AccountName__c, but my trigger/class doesn't update the checkbox as expected. Any ideas please?
My trigger:
trigger ComplaintTrigger on Complaint__c (after delete, after insert, after undelete, after update, before delete, before insert, before update) {

    if (TriggerSettings.getInstance().isEnabled(ComplaintTriggerHandler.class.getName())) {

        TriggerHandler.ITrigger handler = new ComplaintTriggerHandler(Trigger.oldMap, Trigger.newMap, Trigger.old, Trigger.new);

        if (Trigger.isBefore) {
            handler.bulkBefore();
            if (Trigger.isDelete) {
                for (SObject so : Trigger.old) {
                    handler.beforeDelete(so);
                }
            } else if (Trigger.isInsert) {
                for (SObject so : Trigger.new) {
                    handler.beforeInsert(so);
                } 
            } else if (Trigger.isUpdate) {
                for (SObject so : Trigger.old) {
                    handler.beforeUpdate(so, Trigger.newMap.get(so.Id));
                }
            }
            handler.beforePostProcessing();
        } else {
            handler.bulkAfter();
            if (Trigger.isDelete) {
                for (SObject so : Trigger.old) {
                    handler.afterDelete(so);
                }
            } else if (Trigger.isInsert) {
                for (SObject so : Trigger.new) {
                    handler.afterInsert(so);
                }
            } else if (Trigger.isUpdate) {
                for (SObject so : Trigger.old) {
                    handler.afterUpdate(so, Trigger.newMap.get(so.Id));
                }
            }
            handler.postProcessing();
        }
    }
}

and handler:
public with sharing class ComplaintTriggerHandler extends TriggerHandler implements TriggerHandler.ITrigger {
    public ComplaintTriggerHandler(Map<Id, SObject> oldMap, Map<Id, SObject> newMap, List<SObject> oldList, List<SObject> newList) {
        super(oldMap, newMap, oldList, newList);
    }

    public void bulkBefore() {
    }

    public void bulkAfter() {
        if (Trigger.isDelete) {
            ComplaintTriggerHelper.getInstance().setHasActiveComplaintsOnAccount();
        }
    }

    public void beforeInsert(SObject so) {
    }

    public void beforeUpdate(SObject oldSo, SObject so) {
    }

    public void beforeDelete(SObject so) {
    }

    public void afterInsert(SObject so) {
        ComplaintTriggerHelper.getInstance().setHasActiveComplaintsOnAccount();
    }

    public void afterUpdate(SObject oldSo, SObject so) {
        ComplaintTriggerHelper.getInstance().setHasActiveComplaintsOnAccount();
    }

    public void afterDelete(SObject so) {
        ComplaintTriggerHelper.getInstance().setHasActiveComplaintsOnAccount();
    }

    public void postProcessing() {
        ComplaintTriggerHelper.getInstance().updateAccounts();
    }
}

and helper:
public with sharing class ComplaintTriggerHelper {
    
    public List <Complaint__c> Complaints;
    private Map<Id, Boolean> accountsToUpdateMap;
    private static ComplaintTriggerHelper instance;

    public static ComplaintTriggerHelper getInstance() {
        if (instance ==null) {
            instance = new ComplaintTriggerHelper();
        }
        return instance;
    }
    
    private ComplaintTriggerHelper() {
        accountsToUpdateMap = new Map<Id, Boolean>();
        Complaints = new List<Complaint__c>();
    }

    public void setHasActiveComplaintsOnAccount() {

        Set<Id> parentIds = new Set<Id>();

        for (Complaint__c com : Complaints) {
            parentIds.add(com.AccountName__c);
        }

        for (Account accountToUpdate : [SELECT Id, Active_Complaints__c, (Select Id, AccountName__c from Complaints__r WHERE Status__c = 'Open' OR Status__c = 'Pending') FROM Account WHERE Id IN :parentIds]) {
            accountsToUpdateMap.put(accountToUpdate.Id, accountToUpdate.Complaints__r.size() > 0);
        }
    }

    public void updateAccounts() {
        List<Account> acc = new List<Account>();

        for (Id accId : accountsToUpdateMap.keySet()){
            acc.add(new Account(Id = accId, Active_Complaints__c = accountsToUpdateMap.get(accId)));
        }

        update acc;
    }


}

​​​​​​​​​​​​​​
  • October 22, 2019
  • Like
  • 0
getting CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CaseTrigger: execution of BeforeUpdate error
caused by: System.NullPointerException: Attempt to de-reference a null object

Class.BusinessHoursHelper.getBusinessHoursByRecordType: line 43, column 1
Class.CaseTriggerHelper.calculateBusinessHours: line 79, column 1
Class.CaseTriggerHandler.beforeUpdate: line 48, column 1
Trigger.CaseTrigger: line 19, column 1: []
Stack Trace
Class.BusinessHoursHelperTest.testcalculateBusinessHours: line 35, column 1
in below test class:
@isTest
private class BusinessHoursHelperTest {
    private static final Integer BULK_SIZE = 10;
    
    static testMethod void testcalculateBusinessHours() {
        SetupDataBH setupData = new SetupDataBH();
        
        Date startOfWeek = Datetime.now().date().toStartOfWeek();
        System.debug('startOfWeek: ' + startOfWeek);
        
        System.debug(Business_Hours__c.getAll());
        User u = setupData.TestUser;
        System.runAs(u){
            Account acc = [SELECT Id FROM Account LIMIT 1];
            Case c = new Case(AccountId = acc.Id, 
                              Subject='test', 
                              CreatedDate = Datetime.now().addDays(Date.today().daysBetween(startOfWeek) == 0 ? -3 : -1),
                              Initial_FCO_Date__c = Datetime.now(),
                              RecordTypeId = RecordTypeUtility.getIdByName(RecordTypeUtility.CASE_CUSTOMER),
                              Status = 'New',
                              Origin = 'Phone'
                             );
                             
                              System.debug('Date.today().daysBetween(startOfWeek): ' + Date.today().daysBetween(startOfWeek));
                              System.debug('1newCase.CreatedDate: ' + c.CreatedDate);
            
            insert c;
            
            Test.startTest();
            
            for (List<Case> inserted_cases : c.Id) {
                inserted_cases.Initial_FCO_Date__c = Datetime.now();
            }
            update inserted_cases;
            
            Test.stopTest();
            
            
            List<Case> test_cases = [SELECT Id, CreatedDate, Initial_FCO_Date__c, Business_Hours_FCO_Created_CreateDate__c, Status, Origin FROM Case WHERE Id = :c.Id];            

            for (Case updated_case : test_cases) {
                System.assert (updated_case.Initial_FCO_Date__c != null);
                System.assert (updated_case.Business_Hours_FCO_Created_CreateDate__c != null);
                System.assert(updated_case.Business_Hours_FCO_Created_CreateDate__c >= 8.50 && updated_case.Business_Hours_FCO_Created_CreateDate__c < 8.51, 'Business_Hours_FCO_Created_CreateDate__c = ' + updated_case.Business_Hours_FCO_Created_CreateDate__c );
            }
        }
        
    }
    
    class SetupDataBH {
        public User TestUser;
        public User TestFCOUser;
        public User DataImporter;
        public List <BusinessHours> TestBusinessHours;
        
        public SetupDataBH() {
            TestUser = [SELECT Id FROM User WHERE LastName = 'BusinessHoursHelperTest' AND FirstName = 'SYSADMIN' LIMIT 1];
            TestFCOUser = [SELECT Id FROM User WHERE LastName = 'BusinessHoursHelperTest' AND FirstName = 'FCO' LIMIT 1];
            DataImporter = [SELECT Id FROM User WHERE Alias = 'Importer' AND LastName = 'Importer' AND FirstName = 'Data'];
            TestBusinessHours = [SELECT Id FROM BusinessHours WHERE IsDefault = true];
        }
    }
    
    @testSetup
    static void createAndInsertTestUser() {
        List<sObject> ls = Test.loadData(Business_Hours__c.sObjectType, 'BusinessHourRecords');
        system.debug(ls);
        
        System.runAs(new User(Id=UserInfo.getUserId())){
            UserTestData.getUserForTest()
                .setProfile(ProfileUtilities.ProfileType.FCO)
                .setFirstName('FCO')
                .setLastName('BusinessHoursHelperTest')
                .save()
                .getRecord();
            
            User testUser = UserTestData.getUserForTest()
                .setProfile(ProfileUtilities.ProfileType.SYSADMIN)
                .setFirstName('SYSADMIN')
                .setLastName('BusinessHoursHelperTest')
                .save()
                .getRecord();
            
            AccountBuilder.getBuilder().setFirstName('fName').setLastName('lName').setRecordType(RecordTypeUtility.ACCOUNT_PERSON_ACCOUNT).save().getRecord();
        }
    }
}

not sure how to fix that, an pleasey ideas?
  • July 31, 2019
  • Like
  • 0
I'm trying to add WorkflowRule to destructiveChanges and the format as far as I know should be:
<types>
        <members>Object__c.Name</members>
        <name>WorkflowRule</name>
	</types>
but how can I get unique name of the rule if always have spaces, e.g.:
 
<rules>
        <fullName>Case Set Test</fullName>

 
  • May 23, 2019
  • Like
  • 0
we update Business_Hours_SLA_Start_Initial_Now__c with number of business hours (between CreatedDate & now) and it works fine, but I would like to change that to live update rather than number of hours between created and last modified as it's doing now
 
if (newCase.CreatedDate != null && newCase.BusinessHoursId != null) {
            Double timeSinceLastStatus = BusinessHours.diff(newCase.BusinessHoursId, newCase.CreatedDate, Datetime.now())/3600000.0;
            newCase.Business_Hours_SLA_Start_Initial_Now__c = timeSinceLastStatus;
            System.debug(newCase.Business_Hours_SLA_Start_Initial_Now__c);
        }
thank you in advance
 
  • March 05, 2019
  • Like
  • 0
i've added sort() to my code, but values from the custom setting are still listed in random order, what am i missing?
 
public List<SelectOption> getAvailableDocumentTypes() {
        List<SelectOption> options = new List<SelectOption>();
        options.sort();
        for (Available_Document_Types__c doc_type : Available_Document_Types__c.getall().values()) {
            options.add(new SelectOption(doc_type.Value__c, doc_type.Name));
        }
        return options;
    }

 
  • November 27, 2018
  • Like
  • 0
Hi, I would like to include changes in Chatter Feed Tracking in our deployment process, but now sure which metadata type is that, would be grateful if someone could help

Thanks
  • November 19, 2018
  • Like
  • 0
I’m trying to write a test class for class calculating business hours
In CaseTriggerHandler we have:
public void beforeUpdate(SObject oldSo, SObject so){
 
        CaseTriggerHelper.calculateBusinessHours((Case)oldSo, (Case)so);
    }

And in CaseTriggerHelper:
public static void calculateBusinessHours(Case oldCase, Case newCase){
        if (oldCase.Initial_FCO_Date__c != newCase.Initial_FCO_Date__c && newCase.Initial_FCO_Date__c != null ){
            Double timeSinceLastStatus = BusinessHours.diff(newCase.BusinessHoursId, newCase.CreatedDate, newCase.Initial_FCO_Date__c)/3600000.0;
            newCase.Business_Hours_FCO_Created_CreateDate__c =timeSinceLastStatus;
        }
    }
}

and in my CaseTriggerHandlerTest so far I got:
static testMethod void testCalculateBusinessHours() {
	    SetupDataClass setup_data = new SetupDataClass();
		setup_data.upsertTestCases();
        System.runAs(setup_data.TestUser){

            Test.startTest();
                Case test_case = [SELECT Id, CreatedDate, Initial_FCO_Date__c, Business_Hours_FCO_Created_CreateDate__c FROM CASE WHERE Id = :setup_data.TestCase.Id];
				BusinessHours calculateBusinessHours = [SELECT Id FROM BusinessHours WHERE IsDefault=true];
				
				for(Case case_to_update : setup_data.TestCases){
                    case_to_update.CreatedDate = Datetime.now().addDays(-1);
                    case_to_update.Initial_FCO_Date__c = Datetime.now();
					case_to_update.Business_Hours_FCO_Created_CreateDate__c = '8.50';
			Test.stopTest();
			
			for (Case updated_case : setup_data.TestCases) {
            System.assertEquals(setup_data.TestUser.Id, test_case.CreatedDate != NULL);
			System.assertEquals(setup_data.TestUser.Id, test_case.Initial_FCO_Date__c != NULL);
				}
			}
        }
    }
Error: Compile Error: Illegal assignment from String to Decimal at line 60 column 21    

that's: 
System.assertEquals(setup_data.TestUser.Id, test_case.CreatedDate != NULL);

thank you

 
  • September 28, 2018
  • Like
  • 0
I've tried both options in custom lightning component and they work in sales app but as soon as I switch to console app refresh doesn't happen
1. 
refreshAndClose: function (component) {
        $A.get("e.force:refreshView").fire();
        let sObjectEvent = $A.get("e.force:navigateToSObject");
        sObjectEvent.setParams({
            "recordId": component.get("v.recordId")
        });
        sObjectEvent.fire();
    }

2.
({
    refreshFocusedTab : function(component, event, helper) {
        var workspaceAPI = component.find("workspace");
        workspaceAPI.getFocusedTabInfo().then(function(response) {
            var focusedTabId = response.tabId;
            workspaceAPI.refreshTab({
                      tabId: focusedTabId,
                      includeAllSubtabs: true
             });
        })
        .catch(function(error) {
            console.log(error);
        });
    }
})

and as per https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_lightning_refreshTab.htm​​​​​​​ efreshTab() only works in Lightning console apps

any suggestions please?

​​​​​​​thanks
 
  • September 10, 2020
  • Like
  • 0
getting CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CaseTrigger: execution of BeforeUpdate error
caused by: System.NullPointerException: Attempt to de-reference a null object

Class.BusinessHoursHelper.getBusinessHoursByRecordType: line 43, column 1
Class.CaseTriggerHelper.calculateBusinessHours: line 79, column 1
Class.CaseTriggerHandler.beforeUpdate: line 48, column 1
Trigger.CaseTrigger: line 19, column 1: []
Stack Trace
Class.BusinessHoursHelperTest.testcalculateBusinessHours: line 35, column 1
in below test class:
@isTest
private class BusinessHoursHelperTest {
    private static final Integer BULK_SIZE = 10;
    
    static testMethod void testcalculateBusinessHours() {
        SetupDataBH setupData = new SetupDataBH();
        
        Date startOfWeek = Datetime.now().date().toStartOfWeek();
        System.debug('startOfWeek: ' + startOfWeek);
        
        System.debug(Business_Hours__c.getAll());
        User u = setupData.TestUser;
        System.runAs(u){
            Account acc = [SELECT Id FROM Account LIMIT 1];
            Case c = new Case(AccountId = acc.Id, 
                              Subject='test', 
                              CreatedDate = Datetime.now().addDays(Date.today().daysBetween(startOfWeek) == 0 ? -3 : -1),
                              Initial_FCO_Date__c = Datetime.now(),
                              RecordTypeId = RecordTypeUtility.getIdByName(RecordTypeUtility.CASE_CUSTOMER),
                              Status = 'New',
                              Origin = 'Phone'
                             );
                             
                              System.debug('Date.today().daysBetween(startOfWeek): ' + Date.today().daysBetween(startOfWeek));
                              System.debug('1newCase.CreatedDate: ' + c.CreatedDate);
            
            insert c;
            
            Test.startTest();
            
            for (List<Case> inserted_cases : c.Id) {
                inserted_cases.Initial_FCO_Date__c = Datetime.now();
            }
            update inserted_cases;
            
            Test.stopTest();
            
            
            List<Case> test_cases = [SELECT Id, CreatedDate, Initial_FCO_Date__c, Business_Hours_FCO_Created_CreateDate__c, Status, Origin FROM Case WHERE Id = :c.Id];            

            for (Case updated_case : test_cases) {
                System.assert (updated_case.Initial_FCO_Date__c != null);
                System.assert (updated_case.Business_Hours_FCO_Created_CreateDate__c != null);
                System.assert(updated_case.Business_Hours_FCO_Created_CreateDate__c >= 8.50 && updated_case.Business_Hours_FCO_Created_CreateDate__c < 8.51, 'Business_Hours_FCO_Created_CreateDate__c = ' + updated_case.Business_Hours_FCO_Created_CreateDate__c );
            }
        }
        
    }
    
    class SetupDataBH {
        public User TestUser;
        public User TestFCOUser;
        public User DataImporter;
        public List <BusinessHours> TestBusinessHours;
        
        public SetupDataBH() {
            TestUser = [SELECT Id FROM User WHERE LastName = 'BusinessHoursHelperTest' AND FirstName = 'SYSADMIN' LIMIT 1];
            TestFCOUser = [SELECT Id FROM User WHERE LastName = 'BusinessHoursHelperTest' AND FirstName = 'FCO' LIMIT 1];
            DataImporter = [SELECT Id FROM User WHERE Alias = 'Importer' AND LastName = 'Importer' AND FirstName = 'Data'];
            TestBusinessHours = [SELECT Id FROM BusinessHours WHERE IsDefault = true];
        }
    }
    
    @testSetup
    static void createAndInsertTestUser() {
        List<sObject> ls = Test.loadData(Business_Hours__c.sObjectType, 'BusinessHourRecords');
        system.debug(ls);
        
        System.runAs(new User(Id=UserInfo.getUserId())){
            UserTestData.getUserForTest()
                .setProfile(ProfileUtilities.ProfileType.FCO)
                .setFirstName('FCO')
                .setLastName('BusinessHoursHelperTest')
                .save()
                .getRecord();
            
            User testUser = UserTestData.getUserForTest()
                .setProfile(ProfileUtilities.ProfileType.SYSADMIN)
                .setFirstName('SYSADMIN')
                .setLastName('BusinessHoursHelperTest')
                .save()
                .getRecord();
            
            AccountBuilder.getBuilder().setFirstName('fName').setLastName('lName').setRecordType(RecordTypeUtility.ACCOUNT_PERSON_ACCOUNT).save().getRecord();
        }
    }
}

not sure how to fix that, an pleasey ideas?
  • July 31, 2019
  • Like
  • 0
i've added sort() to my code, but values from the custom setting are still listed in random order, what am i missing?
 
public List<SelectOption> getAvailableDocumentTypes() {
        List<SelectOption> options = new List<SelectOption>();
        options.sort();
        for (Available_Document_Types__c doc_type : Available_Document_Types__c.getall().values()) {
            options.add(new SelectOption(doc_type.Value__c, doc_type.Name));
        }
        return options;
    }

 
  • November 27, 2018
  • Like
  • 0
Hi, I would like to include changes in Chatter Feed Tracking in our deployment process, but now sure which metadata type is that, would be grateful if someone could help

Thanks
  • November 19, 2018
  • Like
  • 0
I’m trying to write a test class for class calculating business hours
In CaseTriggerHandler we have:
public void beforeUpdate(SObject oldSo, SObject so){
 
        CaseTriggerHelper.calculateBusinessHours((Case)oldSo, (Case)so);
    }

And in CaseTriggerHelper:
public static void calculateBusinessHours(Case oldCase, Case newCase){
        if (oldCase.Initial_FCO_Date__c != newCase.Initial_FCO_Date__c && newCase.Initial_FCO_Date__c != null ){
            Double timeSinceLastStatus = BusinessHours.diff(newCase.BusinessHoursId, newCase.CreatedDate, newCase.Initial_FCO_Date__c)/3600000.0;
            newCase.Business_Hours_FCO_Created_CreateDate__c =timeSinceLastStatus;
        }
    }
}

and in my CaseTriggerHandlerTest so far I got:
static testMethod void testCalculateBusinessHours() {
	    SetupDataClass setup_data = new SetupDataClass();
		setup_data.upsertTestCases();
        System.runAs(setup_data.TestUser){

            Test.startTest();
                Case test_case = [SELECT Id, CreatedDate, Initial_FCO_Date__c, Business_Hours_FCO_Created_CreateDate__c FROM CASE WHERE Id = :setup_data.TestCase.Id];
				BusinessHours calculateBusinessHours = [SELECT Id FROM BusinessHours WHERE IsDefault=true];
				
				for(Case case_to_update : setup_data.TestCases){
                    case_to_update.CreatedDate = Datetime.now().addDays(-1);
                    case_to_update.Initial_FCO_Date__c = Datetime.now();
					case_to_update.Business_Hours_FCO_Created_CreateDate__c = '8.50';
			Test.stopTest();
			
			for (Case updated_case : setup_data.TestCases) {
            System.assertEquals(setup_data.TestUser.Id, test_case.CreatedDate != NULL);
			System.assertEquals(setup_data.TestUser.Id, test_case.Initial_FCO_Date__c != NULL);
				}
			}
        }
    }
Error: Compile Error: Illegal assignment from String to Decimal at line 60 column 21    

that's: 
System.assertEquals(setup_data.TestUser.Id, test_case.CreatedDate != NULL);

thank you

 
  • September 28, 2018
  • Like
  • 0
I submitted this ticket as a case and was directed by Salesforce to use this forum to post it instead.

I set up way back in November a usage notification alert to be sent to me at 85%. Well, yesterday we tapped out our API usage and never got a notification. It brought our entire client facing website down for about an hour until I could frantically get Salesforce support to raise our limit.

This is a crucial feature, as we often have spikes that might affect this. Can you please look into this?