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
Dev_AryaDev_Arya 

Compare the String field against other Datatype fields

Hi All, 

Here is the scenario,

I have a custom field: 'strField' or Datatype String. I also have Case c, which has fields of type Date, Integer, String, Picklist, currency, etc. 
I need to compare  strField with Case c field. I cannot convert the Case c fields to String type because for numbers or Date or etc. , it will produce incorrect results.
For example
// this is wrong
if(strField == String.vakueOf(c.CloseDate)){
    // Do something
}

// this is also wrong
if(strField == String.valueOf(c.someIntegerField)){
    // Do something
}
Therefore, I need to cast the strField based on the Case c Field Datatype. I have the Case c field datatype but I do not know how to convert strField to that respective Datatype.
...
String datatype = t.Textbaustein__r.Feld3__r.DataType; // this returns datatype in string format
....
//I want to achieve this. The below code is wrong, it is just for reference: 
if((datatype)strField == c.get(t.Textbaustein__r.Feld3__r.QualifiedAPIName)){
   // Do something
}

Any help will be highly appreciated. (If anyone wants to know the complete use case, feel free to ask.)

Thanks.

Cheers,Dev