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
Prasad KasotePrasad Kasote 

Split Comma Separated Values Into different fields salesforce

I have data coming from API in one Single field: 
Customer Information : Ben Matthew, Xtream. Inc., benmatthew@Xtream.com

I want to update this value in 3 different fields on a different object:
Name = Ben Matthew
Company = Xtream. Inc.
Email - benmatthew@xtream.com

how do I go about doing this?

Any help will be highly appreciated.
Shiva RajendranShiva Rajendran
Hi Prasad ,
If my understanding is correct you primarly concentrates on splitting string based on a character and update some object fields by that.
In the below code look at the function processData() .
It splits the csv string and update 3 fields on account object.
public class HttpCalloutSample {

  // Pass in the endpoint to be used using the string url
  public String getCalloutResponseContents(String url) {

    // Instantiate a new http object
    Http h = new Http();

     // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
    HttpRequest req = new HttpRequest();
    req.setEndpoint(url);
    req.setMethod('GET');

    // Send the request, and return a response
    HttpResponse res = h.send(req);
    return res.getBody();
  }
//Lets assume this processData contain the csv data though the res.getBody returns json
     public String processData()
      {
          String csvData=getCalloutResponseContents();
            Sting allFields[]=  csvData.split(',');
       Account acc=new Account();
        acc.name=allFields[0];
   acc.Company=allFields[1];
   acc.Email=allFields[2];
   update acc;
 
       }
}
Let me know if you need any further support.
Thanks and Regards,
Shiva RV
 
Prasad KasotePrasad Kasote
Thanks for your response Shiva.
I want to do this declaratively using Process builder.

any idea about achieving this using process ?
Shiva RajendranShiva Rajendran
Hi Prasad , 
Not sure of doing inside Process builder.
Just add @InvocableMethod  above processData function , i believe it should be on both the methods
refer the document given below
https://help.salesforce.com/articleView?id=process_action_apex.htm&language=en_US&type=0
Now in process builder based on certain criteria ,invoke this method.
There are settings for calling apex function in process builder.
Let me know if you need further help.
Thanks and Regards,
Shiva RV
 
Aaqib Niaz 5Aaqib Niaz 5
Hi Prasad,
Were u able to do that using declarative?