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
sanjaypatidarsanjaypatidar 

Not able to set the System Methods in a Map.

Hi All,

 

I have a requirement where I need to read a set of values from one object and set it to the new record before insert. The values in the Objects can be of 3 types (String, Integer and System Methods)

 

Example -

 

Field LabelAPI NameDefault ValueData Type
StageStageNameNegotiation/ReviewString
QuantityTotalOpportunityQuantity25Integer
User IdCurrentUserId__cuserinfo.getUserId()System Method

 

So I read the data from here and set the Default value from the above table and set it in a SObject (Map). as below - 

			for(integer i=0; i<exceptions.size(); i++)
				{
				if(exceptions.get(i).Data_Type__c == 'String')
					{
					System.debug('Field Name - ['+exceptions.get(i).API_Name__c + '] with Value ['+ exceptions.get(i).Default_Value__c+']');
					cloneId.put(exceptions.get(i).API_Name__c, exceptions.get(i).Default_Value__c); 
					}

				if(exceptions.get(i).Data_Type__c == 'Integer')
					{
					System.debug('Field Name - ['+exceptions.get(i).API_Name__c + '] with Value ['+ Integer.valueof(exceptions.get(i).Default_Value__c.trim())+']');	
					cloneId.put(exceptions.get(i).API_Name__c,  Integer.valueof(exceptions.get(i).Default_Value__c.trim())); 
					}

 

But when I try to pass the System Method records, it is considering it as a String and not the real value from the method.

 

I am using the below line for it.

 

if(exceptions.get(i).Data_Type__c == 'System Method')

{

cloneId.put(exceptions.get(i).API_Name__c, exceptions.get(i).Default_Value__c);

}

 

where as if I simply put it explicity, it works Like - cloneId.put(exceptions.get(i).API_Name__c, userinfo.getUserId());

 

My Question is that why the value of the userinfo.getUserId() is not getting calculated before it sets it in the Map.

 

Any pointers please..

 

Thanks,
Sanjay 

 

Bindhyachal Kumar SinghBindhyachal Kumar Singh

Hi Sanjay,

You are using System Method in if condition. it may not be a datatype that you compare with exceptions.get(i).Data_Type__c field.

 

if(exceptions.get(i).Data_Type__c == 'System Method')

{

cloneId.put(exceptions.get(i).API_Name__c, exceptions.get(i).Default_Value__c);

}

is it contains System Method Data Type?