Update Contact fields from Custom Object - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Harsharndeep DhillonHarsharndeep Dhillon 

Update Contact fields from Custom Object

Hello, Team.

Hope all are well!

We have a custom object in Salesforce called Interactions which is used to capture info when prospect/customer fills out a form on our website. We have a field called Raw data which contains all the email or body of a form with all the details.

We have recently decided to send NPS forms to customers and once customer will fill this form, it will be generatd as Interaction with all the info in Raw data field.

On the other side, we have created new fields on contact related to NPS which has to be updated via Interactions or from the Raw data field.

As per my understanding, this can be done with the help of REGEX (I have never worked on this before) or is there any other way to accomplish this?

Would appreciate your response.

Thank you!
Best Answer chosen by Harsharndeep Dhillon
Paul McCollumPaul McCollum
Substring(  //1 open
	RawData__c, 
	(Find(RawData__c, 'Satisfaction Score:')+19 ),   //2 open, 2 close
	(Find(RawData__c, 'Satisifaction Last Start Date:')+19 -Find(RawData__c, 'Satisfaction Score:') ) //3 open, 3 close

)  //1 close

 

All Answers

Kundan Kumar JhaKundan Kumar Jha
Hey,

In Salesforce, Regex is a function tool used to guide any user in creating data and entering it to the system in a proper format. It utilizes a string of letters, numbers and special characters used as a single code to build a validation rule.
For field update operation you need to use process builder.Look below link for more info :

 https://help.salesforce.com/articleView?id=process_action_update.htm&r=https%3A%2F%2Fwww.google.com%2F&type=5

https://help.salesforce.com/articleView?id=000340214&type=1&mode=1


Thanks!!!
Harsharndeep DhillonHarsharndeep Dhillon
Hello, Kundan. Yes i understand that it will be done through process builder. But, the custom fields which i want to update from interaction are not fields on Interaction and they are a part of field called Raw data (which contains all the details about NPS form) I would need to extract those fields (for example: Rating is a field on NPS form and is a part of Raw data field) from the Raw data field as a criteria and then only i can update fields on contact object as a result. How can i extract those fields from Interaction? Looking forward to your response! Get Outlook for iOS
Kundan Kumar JhaKundan Kumar Jha
++ If both object related with each other than you can extract fields value and update them.
Paul McCollumPaul McCollum
Harsharndeep,
Could you list what a start value is for each of the objects and what the end value is that you want and I can help build the formula. 


Ex. 
Given fields:
Account.CurrencyRate = 13
Contact.CurrentAge  = 20
New Formula field: 
 Contact.AgeRate = 260


)If you can list those, i can write the formula and will let you know if it requires regex. We'll hope it doesn't. :)
Paul McCollumPaul McCollum
And yes how the fields are related will also matter. 
To reference a related record you add "__r" to the object name,

If my PB is on an Account and i want to know the first name of the owner i was use Owner__r.Id 
I think owner is one of the standard object exceptions that doesn't need __r but that's the patter. 
Harsharndeep DhillonHarsharndeep Dhillon
Hello, Paul.
Appreicate your response.

Here is the field called Raw Data on Interaction__c object from which i want to extract information and then map on contact.
User-added image
Highlighted are the 4 fields from the form which i want to extract and then map to contact object fields.

I believe i have to create an automated process on Interaction__c object?
How can i extract those fields as a criteria?

 
Paul McCollumPaul McCollum
Oh wow. 

You have a unstructured TextArea field that has "structured" data in it. 

I'm going to have to test tonight to see if this works on TextArea fields but this should get you started. 
Approach:
Use location of know strings "Satisfaction Score:" and "Satisifaction Last Start Date:" as bookends for the data. 
substr(string,position,[length])
FIND(search_text, text[, start_num])


Satisfaction Score: 
Substring(RawData__c, Find(RawData__c, 'Satisfaction Score:')+19, Find(RawData__c, 'Satisifaction Last Start Date:') )
That's the prototype of the formula you need but sometimes FLOWS/PB can't touch/read LONG/TEXTAREA fields. 

If that doesn't work, you may have not choice to go to code or alter your field definition to be a regular TEXT field. 

 
Harsharndeep DhillonHarsharndeep Dhillon
Hello, Paul.

What does +19 indicate?
 
Harsharndeep DhillonHarsharndeep Dhillon
Hello, Paul.

I tried adding this and getting error of  Missing ')'

User-added image

Can you please help me to build this process, it is really urgent.

Would appreicate your response!
Paul McCollumPaul McCollum
the +19 is the size of the string  "Satisfaction Score:"
Paul McCollumPaul McCollum
Substring(
	RawData__c, 
	(Find(RawData__c, 'Satisfaction Score:')+19 ), 
	(Find(RawData__c, 'Satisifaction Last Start Date:')+19 -Find(RawData__c, 'Satisfaction Score:') )
)

what each line does:
  1. splits rawdata fumction
  2. string to be split
  3. finds the marker for the start of the piece of data we want.
    1. this would be the S in Satisfaction, so we add 19 to it to start right after it.
  4. length of characters to isolate. 
    1. we dont know how many it will be each time so we look the the characters we know that come right afterwards.
    2. once we know that location, we subtract the End from the Start toget the length of the snip;

Make sense?
Harsharndeep DhillonHarsharndeep Dhillon
Thank you so much Paul for such a detailed response :-) I will test this and will let you know the result on Monday :-) Get Outlook for iOS
Harsharndeep DhillonHarsharndeep Dhillon
Hello, Paul. It is still giving me an error of Missing ‘)’ Appreciate your response.
Paul McCollumPaul McCollum
Can you post a screen shot? My last links matches up per my count. 
Paul McCollumPaul McCollum
Substring(  //1 open
	RawData__c, 
	(Find(RawData__c, 'Satisfaction Score:')+19 ),   //2 open, 2 close
	(Find(RawData__c, 'Satisifaction Last Start Date:')+19 -Find(RawData__c, 'Satisfaction Score:') ) //3 open, 3 close

)  //1 close

 
This was selected as the best answer
Harsharndeep DhillonHarsharndeep Dhillon

Hello, Paul.

Thank you so much for your response.

I figured another solution with the help of one team member.

I will need a little help from you to accomplish this. This is the actual format of email which will be included in Raw data (Long Text Area) field:

Source: Riva Satisfaction Survey
First Name: Test
Last Name: Contact

Email: test@rivacrmintegration.com
Website: testemail.com

NPS Score: 8
Survey Sent: 2020-07-30

Comments:
TEST only


This is the process builder which we created and everything looks good for score and Date except comments:
Satisfaction Rating: VALUE(TRIM(MID([Interaction__c].description__c ,FIND("NPS Score: ",[Interaction__c].description__c)+11, 1)))  

Satisfaction Response Date: DATEVALUE(TRIM(MID([Interaction__c].description__c ,FIND("Survey Sent: ",[Interaction__c].description__c)+13, 10)))

Satisfaction Comments(TRIM(MID([Interaction__c].description__c ,FIND("Comments: ",[Interaction__c].description__c)+10, (LEN([Interaction__c].description__c)-FIND("Comments: ",[Interaction__c].description__c)))))


I just want Test Only to appear in the Satisfaction Comment while it is giving me this whoe email body in Comments:
Source: Riva Satisfaction Survey
First Name: Test
Last Name: Contact

Email: test@rivacrmintegration.com
Website: testemail.com

NPS Score: 8
Survey Sent: 2020-07-30

Comments:
TEST only

I think process is reading Comments: Test Only
But actually it is on different line
Comments:
Test Only

Would really appreciate your quick reponse on this!

Paul McCollumPaul McCollum
Thanks. Glad the solution helped. Please mark as "best answer" and submit other questions as new questions. 
Harsharndeep DhillonHarsharndeep Dhillon
If you can help me with the comments field which I mentioned, that would be great 😊
Harsharndeep DhillonHarsharndeep Dhillon
I have just postes the new question with the subject: Update Contact fields via Custom Object