Change the format of all Contacts phone numbers in Salesforce - salesforce

Some of the phone numbers of Contacts are formatted as (123) 456-7891
I need to change the format of all phone numbers to 1234567891.
I don't want to create another formula field that contains the correct format. I want to change the format of all the current phone numbers(and future phone numbers) to the format 1234567891.
Do I need to create a batch Apex class for this? If so, how should I go about formatting the numbers? I couldn't find anything on google.
How should I proceed?

You should be able to do it code-free, with flow/workflow/process builder. Update with "formula"
if
CONTAINS(Phone,'(') || CONTAINS(Phone, ')') || CONTAINS(Phone, '-')
then field update action
Phone = SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(Phone, '(', ''), ')', ''), '-', '')
If you really would rather do it with a before insert, before update trigger that's an option too of course.
So that should solve it for future data, how about what's already in the system. One off batch job is an option but that's a lot of work (class, test class, deploy, run, afterwards destructive deployment...).
How much data we're talking about, couple thousands? You could design what you need as a bit of code to run in Developer Console's execute anonymous.
You could look into exporting all bad records with a report, running a fix in excel (or even not, depends how you wrote the 1st part. Did you make it run on every update or only when Phone changes?) and then importing back. If you made it run on every update you could even do a dummy edit (import just the ID column, as if user hit edit and save without changing anything). Depends on size you could use built-in Import Wizard or install Data Loader.

Related

"?" character in MSSQL DB getting replaced with (capital A with grave accennt) when displayed by ASP script

I'm attempting to provide support for a legacy ASP/MSSQL web application - I wasn't involved in the development of the software (the company that built it no longer exists) & I'm not the admin of the server where it's hosted, I just manage the hosting for the owners of the site via a reseller account. I'm also not an ASP developer (more a PHP guy), and am not that familiar with it beyond the basics - updating DB connection strings after server migrations, etc.
The issue is that the site in question stores the content of individuals pages in an MSSQL database, and much of the content includes links. Almost all of the internal links on the site are format like "main.asp?123" (with "123" being the ID of a database row). The problem is, starting sometime in the last 8 months or so*, something caused the links in the DB content to show up as "main.aspÀ123" instead - in other words, the "?" character is being replaced by the "À" character (capital A with grave accent). Which, of course, breaks all of those links. Note that Stackoverflow won't allow me to include that character in the post title, because it seems to think that it indicates I'm posting in Spanish...?
(*unfortunately I don't know the timing beyond that, the site owners didn't know when the issue started occurring, so all I have to go by is an archive.org snapshot from last October, where it was working)
I attempted to manually change the "?" character in one of the relevant DB records to "?" (the HTML entity for the question mark), but that didn't make any difference. I also checked the character encoding of the HTML code used to display the content, but that doesn't seem to be the cause either - the same ASP files contain hard-coded links to some of the same pages (formatted exactly the same way), and those work correctly: the "?" doesn't get replaced.
I've also connected to the database directly with the MSSQL Management Studio Express application, but couldn't find any charset/character encoding options for either the database or the table.
And I've tried contacting the hosting provider, but they (M247 UK, in case anyone is curious) have been laughably unhelpful. The responses from them have been along the lines of "durrrrrr, we checked a totally different link that wasn't actually the one that you clearly described AND highlighted in a screenshot, and it works when we check the wrong link, so the problem must be resolved, right?" Suffice it to say, I wouldn't recommend them - used to be a customer of RedFox hosting, and the quality of customer has dropped off substantially since M247 bought them.
Any suggestions? If this were PHP/MySQL, I'd probably start by creating a small test script that did nothing but fetch one of the relevant records and display it's contents, to narrow down the issue - but I'm not familiar enough with ASP to do that here, at least not without a fair amount of googl'ing (and most of the info I can find is specific to ASP.net instead).
Edit: the thread suggested as a solution appears to be for character encoding issues when writing to MSSQL, not reading from it - and I've tried the solutions suggested in that thread, none make any difference.
Looks like you're converting from UNICODE to ASCII somewhere along the line...
Have a look at this to get a quick demo of what happens. In particular, pay attention to the ascii derived from inr, versus the ascii derived from unicode...
SELECT
t.n,
ascii_char = CHAR(t.n),
unicode_char = NCHAR(t.n),
unicode_to_ascii = CONVERT(varchar(10), NCHAR(t.n))
FROM (
SELECT TOP (1024)
n = ROW_NUMBER() OVER (ORDER BY ao.object_id)
FROM
sys.all_objects ao
) t
WHERE 1 = 1
--AND CONVERT(varchar(10), NCHAR(t.n)) ='À'
;
I found a workaround that appears to do the trick: I was previously trying to replace the ? in the code with &#63 (took out the ; so that it will show the code rather than the output), which didn't work. BUT it seems to work if I use &quest instead.
One thing to note, it seemed that I was originally incorrect in thinking that the issue was only affecting content being read/displayed from the MSSQL DB. Rather, it looks like the same problem was also occurring with static content being "echo'd" by code in the ASP scripts (I'm more of a PHP guy, not sure the correct term is for ASP's equivalent to echo is). Though the links that were hardcoded as static (rather HTML being dynamically output by ASP) were unaffected. Though chancing the ? to &quest worked for those ones too (hardest part was tracking down the file I needed to edit).

Convert text to date sql

I've seen a few posts on here and dotted around on the internet but I'm still struggling to implement my findings to get this to work.
I am currently trying to pull through a date field and run parameters on this field however everything I do fails and it still comes through as text or I experience an error.
Here is my current code:
SELECT CEL_SLT.ACCOUNT,
CEL_SLA.NAME,
CEL_SLT.STOCK_CODE,
**CEL_SLT.DATE**,
CEL_SLT.STOCK_QTY,
CEL_SLT.AMOUNT,
CEL_SLT.ORDER_NO
FROM Datafile.dbo.CEL_SLA CEL_SLA, Datafile.dbo.CEL_SLT CEL_SLT
WHERE CEL_SLA.ACCOUNT = CEL_SLT.ACCOUNT
AND ((CEL_SLT.STOCK_CODE Like 'F%' And CEL_SLT.STOCK_CODE Not Like 'FNX%')
AND (CEL_SLT.ACCOUNT=?)
I need the field CEL_SLT.DATE to come through as a date field.
I hope this makes sense and someone can help.
Assuming that your data is clean (in other words, the text data actually looks like a date), you can do it with either the CAST or CONVERT command.
SELECT CAST(CEL_slt.DATE as date)

import old data from postgres to elasticsearch

I have a lot of data in my postgres database( on a remote). This is the data of the past 1 year, and I want to push it to elasticsearch now.
The data has a time field in it in this format 2016-09-07 19:26:36.817039+00.
I want this to be the timefield(#timestamp) in elasticsearch. So that I can view it in kibana, and see some visualizations over the last year.
I need help on how do I push all this data efficiently. I cannot get that how do I get all this data from postgres.
I know we can inject data via jdbc plugin, but I think I cannot create my #timestamp field with that.
I also know about zombodb but not sure if that also gives me feature to give my own timefield.
Also, the data is in bulk, so I am looking for an efficient solution
I need help on how I can do this. So, suggestions are welcome.
I know we can inject data via jdbc plugin, but I think I cannot create
my #timestamp field with that.
This should be doable with Logstash. The first starting point should probably be this blog post. And remember that Logstash always consists of 3 parts:
Input: JDBC input. If you only need to import once, skip the schedule otherwise set the right timing in cron syntax.
Filter: This one is not part of the blog post. You will need to use the Date filter to set the right #timestamp value — adding an example at the end.
Output: This is simply the Elasticsearch output.
This will depend on the format and field name of the timestamp value in PostgreSQL, but the filter part should look something like this:
date {
match => ["your_date_field", "dd-mm-YYYY HH:mm:ss"]
remove_field => "your_date_field" # Remove now redundant field, since we're storing it in #timestamp (the default target of date)
}
If you're concerned with the performance:
You will need to set the right jdbc_fetch_size.
Elasticsearch output is batched by default.

How to create user in MediaWiki using database

I've tried to add a new user with phpmyadmin of my host but it didn't work. After I
add a new record in user table (same of other users info) and tried to login with
my new username to the MediaWiki, the system said user doesn't exist.
Don't touch the database manually, if you need to do this server-side, there's a script for that called createAndPromote.php in maintenance/.
If you want to import many user at a time ,you can use ImportUsers extension, it allows you to import a CSV file (with user list) into the system.
You can not insert records in User table for it has a password field which being encrypted by a PHP function.But for other tables like tw_group or user_groups,you can change it directly in database.
Was evaluating BlueSpice (based on MediaWiki) and came to that point, too.
Problem in my case was: In table user, column user_name, entries must have capital first letter! E.g.
|user_name|
|test |
is not working.
|user_name|
|Test |
is working.
Also, regarding the "password" problem mentioned in the other answer: You can create it by yourself. Here's a quick and dirty solution using some webtools.
Create random hex for salt (32 bit)
https://www.browserling.com/tools/random-hex
Turn salt to base64
https://base64.guru/converter/encode/hex
Create key from password (30000 Iterations; dkLen 512; PBKDF2WithHmacSHA512)
https://8gwifi.org/pbkdf.jsp
Create Key String (replace >>XX<< with the values from above)
:pbkdf2:sha512:30000:64:>>SALT_IN_BASE64<<:>>KEY_STRING<<
Ps: For the user_token I used a random 32bit hex.
Be extremely careful when making direct changes to the database. Always test extensively. This is not for newbies who copy from StackOverflow without understanding what they are doing!

SSRS how to format memo field

I'm pulling data from a SQL Server 2008 R2 database and one of the fields is a memo field.
When the data is displayed it comes out in the format DATE/USER/then the message. There is a line break and this repeats. For example:
30/10/2013 11:34 TRACEY : order Created
30/10/2013 11:38 AUTO : order Authorised
30/10/2013 11:40 TRACEY : order Issued
30/10/2013 11:41 TRACEY : order processed
I don't have an control in changing SQL database tables/fields.
I want to be able to format this ugly block of text but really struggling to find a solution - for display in SSRS report. Is there any way I can add a space between each line? Or strip out certain words or complete lines based on some specific parameter?
I just don;t seem to be enable control formatting of memo fields. Any help appreciated.
You can write your own function (in the report' declaration) which will perform the formatting, but this is not the simple task. After this you can call this function and receive a formatted text.
Samples of this you can find in the following articles:
http://technet.microsoft.com/en-us/library/ms156028.aspx
http://technet.microsoft.com/en-us/library/ms155798%28v=sql.100%29.aspx

Resources