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
click-api-userclick-api-user 

Appending To Existing Field Value

I'm new to Salesforce and just started on a simple integration project that utilizes Salesforce WSDL / Java. I have a custom object with field that serves something like a history entry.  Updates to this field are always appends to its current value.  Since this value can grow in size i would like to avoid fetching the current value, do a string append then save it back. I'm looking for some options so that my java client can just send increments and have the Salesforce platform append the increment to the existing value. Is this possible to achieve with some sort of field configuration or special API? If not what are my other options? Thank you.

 

 

SuperfellSuperfell

There's no out of the box way to do this in the API (people generally model history as rows in a related object), but if you wanted to do this without round tripping the strings over the api, you could build a custom web service in apex to do the appending, and then call that from java, it'd be something like

 

 

global class AppendService {
  webservice void appendTo(Id recordId, String toAppend) {
    account a = [select historyField from account where id=:recordId]; 
    a.historyField += toAppend;
    update a;
 }
}

 

You could expand this to use dynamic apex and make it more generic (if you have history fields on lots of different objects), and of course, you could make a bulk version that updates a bunch of rows in one round trip.

 

 

thomp361thomp361
3.5 years later...where does this stand?  Is there a way to accomplish this out of the box?