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
Vetriselvan ManoharanVetriselvan Manoharan 

Using maps for validation

Hi,

Below is my code. Hope there is some mistakes while getting the errors string from the map for corresponding records.
 
Map<String, List<Account>> errorRecords = new Map<String, List<Account>>();
List<Account> accError = new List<Account>();
if((record.Discount_Type__c == 'Date Specified' || record.Discount_Type__c == 'Life Time') &&  opps.Coupon_Codes__c == null)
			            	{
		            			accError.add(record);
		            			errorRecords.put(' Please provide coupon code for the discount type specified!', accError);
			            	}
			            	else if(record.Discount_Type__c == 'Date Specified' && String.valueOf(record.Discount_End_Date__c) == null)
			            	{
		            			accError.add(record);
		            			errorRecords.put(' Please choose the discount end date in account before clone the new opportunity', accError);
			            	}


Here I am adding the error messages to record

for(String str : errorRecords.keySet()) 
		    {
	    		for(Account o : errorRecords.get(str)) 
	    		{
        			Account oAccErrors = accountNewMap.get(o.Id); 
        			oAccErrors.addError(str); 
	    		}
		    }
Error records is seperated perfectly but the error message is displaying as same. Thanks in advance
 
ra811.3921220580267847E12ra811.3921220580267847E12
Hi,



else if(record.Discount_Type__c == 'Date Specified' && String.valueOf(record.Discount_End_Date__c) == null)
{
accError.clear();
accError.add(record);
errorRecords.put(' Please choose the discount end date in account before clone the new opportunity', accError);
}

Thank you