function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Yuhai HuangYuhai Huang 

could anybody help find out errors in below code?

Set<String> setConcurReportIds = new Set<String>();
for (Expense_Cache__c eCache: lstec_existed_merge) {
System.debug(' ec.Concur_Report_Id__c is here ' + ec.Concur_Report_Id__c);
System.debug('eCache.Concur_Report_Id__c is here ' + eCache.Concur_Report_Id__c);
System.debug('eCache.Expense_Report__c is here ' + eCache.Expense_Report__c);

line 725: if (eCache.Concur_Report_Id__c == ec.Concur_Report_Id__c && eCache.Expense_Report__c != '') {     setConcurReportIds.add(eCache.Expense_Report__c);
} }

Concur_Report_Id__c is text type.
Expense_Report__c is lookup id.

Can anybody help find out why the invalid id error happens?

16:00:57.26 (1446525074)|SYSTEM_METHOD_ENTRY|[722]|System.debug(ANY)
16:00:57.26 (1446530656)|USER_DEBUG|[722]|DEBUG|    ec.Concur_Report_Id__c is here 401328
16:00:57.26 (1446536314)|SYSTEM_METHOD_EXIT|[722]|System.debug(ANY)
16:00:57.26 (1446539625)|STATEMENT_EXECUTE|[723]
16:00:57.26 (1446546287)|HEAP_ALLOCATE|[723]|Bytes:41
16:00:57.26 (1446552175)|SYSTEM_METHOD_ENTRY|[723]|System.debug(ANY)
16:00:57.26 (1446555285)|USER_DEBUG|[723]|DEBUG|eCache.Concur_Report_Id__c is here 401328
16:00:57.26 (1446559344)|SYSTEM_METHOD_EXIT|[723]|System.debug(ANY)
16:00:57.26 (1446562165)|STATEMENT_EXECUTE|[724]
16:00:57.26 (1446583131)|SYSTEM_METHOD_ENTRY|[724]|String.valueOf(Object)
16:00:57.26 (1446589079)|HEAP_ALLOCATE|[724]|Bytes:18
16:00:57.26 (1446600036)|SYSTEM_METHOD_EXIT|[724]|String.valueOf(Object)
16:00:57.26 (1446604857)|HEAP_ALLOCATE|[724]|Bytes:51
16:00:57.26 (1446609913)|SYSTEM_METHOD_ENTRY|[724]|System.debug(ANY)
16:00:57.26 (1446613386)|USER_DEBUG|[724]|DEBUG|eCache.Expense_Report__c is here a1G6F000003VESYUA4
16:00:57.26 (1446618236)|SYSTEM_METHOD_EXIT|[724]|System.debug(ANY)
16:00:57.26 (1446768110)|HEAP_ALLOCATE|[725]|Bytes:16
16:00:57.26 (1446787793)|METHOD_EXIT|[397]|01p90000006RpI3|dldcExpenses.getExpenseReport(Expense_Cache__c)
16:00:57.26 (1446797257)|SYSTEM_MODE_EXIT|false
16:00:57.26 (1446804851)|METHOD_EXIT|[26]|01p90000006RpI3|dldcExpenses.Create(List<Expense_Cache__c>)
16:00:57.26 (1446883993)|FATAL_ERROR|System.StringException: Invalid id: 

Class.dldcExpenses.getExpenseReport: line 725, column 1
Class.dldcExpenses.Create: line 397, column 1
Trigger.dldcConcurExpenseUpload: line 26, column 1
16:00:57.26 (1446898598)|FATAL_ERROR|System.StringException: Invalid id: 

I tried hard and can't any reason Invalid Id error happens.

Can anybody help on this?
Kai Herng LauKai Herng Lau
Hi Yuhai,

Can you try this:
if (eCache.Concur_Report_Id__c == ec.Concur_Report_Id__c && eCache.Expense_Report__c != null) { 
   .....
}

 
Waqar Hussain SFWaqar Hussain SF
try below code snippet.
 
if(eCache.Concur_Report_Id__c != null && ec.Concur_Report_Id__c){
 if (eCache.Concur_Report_Id__c == ec.Concur_Report_Id__c && eCache.Expense_Report__c != '') {     setConcurReportIds.add(eCache.Expense_Report__c);
} 
}

 
Yuhai HuangYuhai Huang
Hi, Thank you Kai Herng Lau and Waqar Hussain SF.

I replaced empty string check with null check and error no longer appears.
eCache.Expense_Report__c != null

But I still can't figure out why it thew errors when I checked Id on empty string.
Waqar Hussain SFWaqar Hussain SF
Actutlly you were comparing two field, as below
eCache.Concur_Report_Id__c == ec.Concur_Report_Id__c

As per my understanding If any of the field is null, system will through null pointer exception.