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
HAZLITT VASUDEVANHAZLITT VASUDEVAN 

Static method cannot be referenced from a non static context: String String.valueOf(Object)

public class sand {
public static void force()
    {
       Work_Order__c work = new Work_Order__c();
       work.Name = 'Asian Paints';
       work.WO_Number__c = 1547586597;
       work.Account_Id__c = 12345678;
       work.Email_Body__c = ' ';
       String a = work.Email_Body__c;
       String[] arr = new List<String>();
       arr.add('Hello.');
       arr.add('Welcome to salesforce,'); 
       arr.add('Name'); 
       arr.add('Asian Paints'); 
       arr.add('WO Number'); 
       arr.add('1547586597'); 
       arr.add('Account Id'); 
       arr.add('12345678');  
       for(integer i=0; i<arr.size(); i++)
       {
           System.debug(arr[i].valueOf(work.Email_Body__c));
       }
       insert work;
       System.debug(work);
    }
}
Surya GSurya G
Hi Hazlit, 
The error is in line system.debug statement, the valueOf string method declartion is wrong.
it should be like this
String.valueOf(argument which you want to convert it to string);
May I know the purpose of for loop and system.debug statement?  
Are you trying to convert work.Email_Body__c to string?

Thanks 
Surya G
mukesh guptamukesh gupta
Hi HAZLITT,

can you please tell what your trying to convert by valueOf, after that i will able to suggest for better approach.

Regards
Mukesh
Suraj Tripathi 47Suraj Tripathi 47

Hi Hazlitt,

your arr does not contain a value for work.Email_Body__c

so you can print array values like this

for(integer i=0; i<arr.size(); i++)
       {
           System.debug(arr[i]);
       }


All the values are string inside arr so need to convert.

ValueOf()=> this function use to convert data from one to another

example

integer count=5;
       // String data=count;//this will give error so i need to convert count to string so that it store in data
        String data=string.valueOf(count);
        String[] arr=new List<String>();
 

Please mark it as the Best Answer

Suraj Tripathi 47Suraj Tripathi 47

use:

       String a = work.Email_Body__c;

      arr.add(a);
for(integer i=0; i<arr.size(); i++) {
if(arr[i]==a){
System.debug(arr[i]);
}
}