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
edwin_beltranedwin_beltran 

string updateOpp(string oId, string fieldName, string fieldValue) {} - Is this possible?

Hi team,

 

I am trying to figure it out if this is possible?

 

WebService static string updateOpportunity(string oppId, string fieldName, string fieldValue)
        {
        	try
            {   
            	integer i = Database.countQuery('select count() from Opportunity where Id = :oppId');
            	if (i > 0) {
	        Opportunity o = [select :fieldName from Opportunity where Id = :oppId limit 1];
	        	o.fieldName = fieldValue;
	        	update o;
	        	return 'OK';
            	}	        		        
          	}	
           	catch (DmlException e) {                       
           		return string.valueof(e); 
           	}        
        }

 

someone gets the idea... is this possible?

 

please post or sms me.

 

Best Answer chosen by Admin (Salesforce Developers) 
hemantgarghemantgarg

You can do by following :-

 

o.put(fieldName, fieldValue);

All Answers

hemantgarghemantgarg

Try changing below line of code :-

Opportunity o = Database.query('select '+fieldName+' from Opportunity where Id = :oppId ');
edwin_beltranedwin_beltran
Ok... And what about accessing later the fieldName to assign the fieldValue?

Can I use?

o.fieldName = fieldValue;

What you think?
hemantgarghemantgarg

You can do by following :-

 

o.put(fieldName, fieldValue);

This was selected as the best answer
edwin_beltranedwin_beltran

cool! I will test it right away...

 

 

hemantgarghemantgarg

happy code :)