Is it possible to put comments in SOQL?
The Force.com explorer doesn't support basic operations like undo/redo and I can't find any way to enter comments so experimenting with queries is painful.
I've tried all the usual suspects --, #, /*, //
No, I don't think there's a way to use comments in SOQL. You can comment out pieces of queries you've issued in Apex though.
There are some tools that you might like more than the official Flash-based Explorer and the sluggish querying utility in Eclipse IDE.
My favorite is Real Force Explorer - has the searchable history of SOQL and Apex snippets, you can select the piece you want to run if you have several queries (like in Oracle's SQLDeveloper)...
I've heard some good stuff about BrainEngine too, didn't try it yet (basic version is free, cough up cash for more). The screenshots look tempting ;)
You might also like web-based tools like the official Workbench - if you're not a fan of providing the credentials in the officially hosted one you can download it and host it on your own machine.
Last but not least - JitterBit Data Loader got promoted some time ago to be listed in Setup pages. Haven't played with it either (might be it's just a data loader, not really suited for query editor tasks).
If you're SQL Server guy - have a look at DBAmp ($$$ again). I doubt it's the only connector to Salesforce, there have to be some more ODBC-like translation attempts. So you might be able to find a plugin for your favorite SQL editor after all.
(no, I'm not related to any of companies or projects behind these links)
If you are writing inline SOQL inside of Apex, you can add Apex comments. Both block and single-line comments work.
You can verify this in the Execute Anonymous Window in the Developer Console:
List<Account> accounts = [
SELECT ID From Account
// single line comment
WHERE Name = 'Test' /* block comment */
];
The Execution log shows that the comments are removed from the actual query:
SOQL_EXECUTE_BEGIN [1]|Aggregations:0|SELECT ID FROM Account WHERE Name = 'Test'
I use SOQL Studio from VisualSoftwareSystems.net. It supports line comments and block comments as well as full syntax highlighting.
OK, in SOQL you don't have the usual commenting mechanism. So now it's time for Boolean phantoms: appending an OR clause that can never be true, but contains comment info. Something like this:
SELECT id FROM Account WHERE Name = 'IBM' OR Name = 'This is the comment text explaining what this query is for'
This bit of hackery will slow down the query a little tiny bit...but if you simply must put the comment inside the SOQL (rather than at the end of the line invoking it), it does work.
Related
I have 3 'old' Permission Sets (PS1, PS2 and PS3) which need to be merged into a Permission Set #4 (PS4).
PS1, PS2 and PS3 will be deprecated after adding its respective permissions into PS4. PS4 will remain as the future Permission Set which will gather ALL the permissions for a specific set of Users.
For now, I see that this is a very manual task ("Eye-ball" comparing each PS1, PS2, PS3 with PS4 and adding the missing permissions into PS4) and, as all manual tasks, it is prone to errors.
QUESTIONS:
Can you suggest a tool to COMPARE Permission Sets to make sure I am not missing any permission?
or (even better)
Can you suggest a tool to MERGE Permission Sets in a safe way (to mitigate risk of errors)?
or
Would you recommend a "best approach" or "best practice" for this task?
Thank you very much.
Developer way
You'd need a developer to connect with sfdx (if commandline is scary - there's VSCode editor) or similar tool and download "metadata". And then compare the XML files using something like WinMerge
https://trailhead.salesforce.com/content/learn/projects/quickstart-vscode-salesforce might help if you've never done it and don't have a developer handy.
Profiles and permission sets can be very big, what's being downloaded depends on what else you're downloading. Define "everything". If you indicate in "package.xml" that you want all objects, classes and permission sets - the permission set file should include checkboxes for "Apex Class Access", field level security, allowed record types etc - but might not include "Visualforce Page Access", tab visibilities etc because you didn't include them). There's cool plugin to VSCode for building the "package.xml" file for you, picking what you need.
Once you have that you could load them up in Winmerge (or any "diff tool" you like) and compare up to 3 files. It takes a while to get used to (you could start with comparing two, not 3).
You'll see an overview of changed lines on the left and you can decide to say make leftmost file the merged one. Go line by line and add permissions as you see them. You could then save the final file as 4th perm set and use same sfdx/vscode to deploy it.
Analyst way
If you feel like Excel guru... This data should be queryable so you could export it and crack some comparisons that way. Again - the checkboxes would be spread across different tables so you'd need to compare object rights, then field level security, then class access, then...
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_erd_profile_permissions.htm
This would be a start
SELECT Parent.Name, SobjectType, PermissionsRead, PermissionsCreate, PermissionsEdit, PermissionsDelete
FROM ObjectPermissions
WHERE SobjectType IN ('Account', 'Contact', 'Case') AND Parent.Name IN ('PS1', 'PS2', 'PS3')
ORDER BY SobjectType, Parent.Name
It's very ungrateful job because you'd need to write formulas across rows or pivot it somehow... Also note my PS2 didn't have access to Cases at all - SF doesn't bother holding a row with all false, it just isn't there.
¥€$ way
Money solves everything, eh? Deployment & backup tools like OwnBackup, Gearset, Copado etc have something for detecting changes between projects on disk and orgs... You could rename PS2 to PS1 in another sandbox and make the tool compare them? (I'm not affiliated with any such tool vendor)
There's also https://perm-comparator.herokuapp.com/ if you're not afraid 3rd party app will get sysadmin access to your org (haven't used personally, just Googled it)
Ages ago my colleague got promising exports out of Config Workbook. Again - haven't used personally, screenshots look nice.
I have some text data in an SQL Server 2014 table in which I want to detect complex patterns and extract certain portions of the text if the text matches the pattern. Because of this, I need capturing groups.
E.g.
From the text
"Some title, Some Journal name, vol. 5, p. 20-22"
I want to grab the volume number
, vol\. ([0-9]+), p\. [0-9]+
Mind that I have simplified this use-case to improve readability. The above use-case could be solved without capturing groups. The actual use-case handles a lot more exceptions, like:
The journal/title containing "vol.".
Volume numbers/pages containing letters
"vol" being followed by ":" or ";" instead of "."
...
The actual regex I use is the following (yet, this is not a question on regex structure, just elaborating on why I need capturing groups).
(^|§|[^a-z0-9])vol[^a-z0-9]*([a-z]?[0-9]+[a-z]?)
As far as I know, there are two ways of getting Regex functionality into SQL Server.
Through CLR: https://www.simple-talk.com/sql/t-sql-programming/clr-assembly-regex-functions-for-sql-server-by-example/ . Yet, this example (from 2009) does not support groups. Are there any commonly used solutions out there that do?
By installing Master Data Services
Since installing and setting up the entire Master Data Services package felt like overkill to get some Regex functionality, I was hoping there'd be an easy, common way out...
I have found a CLR implementation that is super easy to install, and includes Regex capturing group functions.
http://www.sqlsharp.com/
I have installed this in a separate database called 'SQL#' (simply by using the provided installation .sql script), and the functions are located inside a schema with the same name. As a result I can use the function as follows:
select SQL#.SQL#.RegEx_CaptureGroup( 'test (2005) test', '\((20[012][0-9]|19[5-9][0-9])\)', 1, NULL, 1, -1, '');
Would be nice if this was included by default in SQL Server...
So Im new to databases and Im trying to learn the ropes. I have a DB2 database that Im getting familiar with. I was assigned a task where I need to write a method that does a search on the database. The search will take in two parameters, a username and a user id number. If the user and the user id number does not match or if one or the other turns out null then It needs to throw a error. If its valid then it will continue with spitting out information about the user.
I was told to use the findall() function or something similar to it. I was looking online and what I have found is examples that deal with like or ilike and im not sure how something like that will work in my situation. What would be a decent example of how I would start to go about this?
any help is appreciated. Ill post back if I make any progress.
note: Im using groovy/grails. Domain,Controller,View setup.
Is this some homework assignment from school?
findall() is usually a method in regular expressions which I don't think is relevant in here. If you have a SQL database, that means you have a RDBMS which uses SQL as query language. You need to learn about the SELECT command which can look daunting when you look the first the time to the manual but it's actually simple for your case. You need something like:
SELECT userfield1, userfield2,..
FROM myusertable
WHERE myusertable.username = 'uname' AND myusertable.userid = userid
uname and userid are your search parameters. Please note that this SQL query should be done with a PREPARED statement for security reasons.
When you run this query using your database library you get back an array of results which you have to analyze. If it is empty, no user found.
Edit: updated to take into account the use of hibernate
Hibernate uses HQL which is like SQL and has indeed a findAll method. See http://grails.org/doc/latest/ref/Domain%20Classes/findAll.html
In SSMS and its immediate or locals window, is there a way to see the contents of table variable?
I can select and view the value of scalars, but I can't seem to find a way to query the contents of tables or even run
SELECT * FROM #someTableVarInMySproc
in the immediate window. Is there any way to do this?
No, sorry, this is not possible in current versions of Management Studio. It has been asked for, and it's been stated that they are considering something similar in a future version. You can vote and add constructive comments on the following items, though there is no guarantee they'll ever actually do it:
http://connect.microsoft.com/SQL/feedback/details/623353
http://connect.microsoft.com/SQL/feedback/details/582167
http://connect.microsoft.com/SQL/feedback/details/454870
http://connect.microsoft.com/SQL/feedback/details/363054
The first item in that list has an interesting workaround:
In addition to the obvious caveat that you may not be able to inject additional code to capture the data in an XML variable (because after all, if you can do this, you could also add old-school debugging techniques like SELECT * FROM #table), and the cumbersome nature of trying to read this information from XML, Management Studio 2012 crashed on me the first time I tried to do this - so if you're going to try it, make sure you do so in an isolated instance.
I've just started using Subsonic 2.2 and so far very impressed - think it'll save me some serious coding time.
Before I dive into using it full time though there is something bugging me that I'd like to sort out.
In my current database (a SQL2008 db) I have split the tables, views, sps etc. up into separate chunks by schema/owner name, so all the customer tables are in the customer. schema, products in the product. schema etc., so a to select from the customers address table i'd do a select * from customer.address
Unfortunately, Subsonic ignores the schema/owner name and just gives me the base table name. This is fine as I've no duplicates between schemas (e.g Customer.Address and Supplier.Address don't both exist) but I just feel the code could be clearer if I could split by schema.
Ideally I'd like to be able to alter the namespace by schema/owner - I think this would have least impact on SubSonic yet make the resulting code easier to read.
Problem is, I've crawled all over the Subsonic source and don't have a clue how to do this (doesn't help that I code in VB not C# = yes I know, blame the ZX Spectrum!!)
If anyone has tackled this before or has an idea on how to solve it, I'd be really grateful,
Thanks in advance.
Ed
I was going to suggest the multiple provider approach too.
But a lot of the plumbing is already in subsonic for ownership.
If you edit a couple of lines in CS_ClassTemplate.aspx you can create a namespace for each owner profile. Change around line 58 (I'm using v2.1) to
namespace <%=provider.GeneratedNamespace%><%=owner%>
where owner is
string owner = "." + tbl.SchemaName;
if(owner == ".dbo")
owner = "";
You put that up above, around line 14. This way you can have a namespace for every owner like:
Northwind.Suppliers, Northwind.Customers, etc.
I left dbo as just Northwind so all the tests would compile without a lot of editing.
I ran a simple select query and I think it will work the way you want.
You could do this in 3.0 as well using our t4 templates (but it's 3.5 only). This is a really good bit of feedback - we should build this in by default perhaps!
Glad you got some help here.
Just to let you know I have this now working - or at least, compiling! :-) To get the owner solution to work fully though you'll need to make more changes to the Class Template as otherwise the table/key functions sit within the wrong namespace.
I've also hacked around with the stored procedure template. I couldn't (in the short time I have) work out how to split into separate files/namespaces for each owner so instead i've prefixed each sp function with the owner and an underscore.
However, just in case you have the same problem you'll know its possible to fix.
Ed
You could try doing separate providers that have the same underlying database connection, like so:
<SubSonicService defaultProvider="DBData">
<providers>
<clear/>
<add name="DBData" type="Subsonic.SqlDataProvider, SubSonic" connectionStringName="LocalSqlServer" generatedNamespace="DBData" includeTableList="table_a,table_b" spStartsWith="app,get,set" viewStartsWith="v_" />
<!--CMS Provider-->
<add name="CMS" type="SubSonic.SqlDataProvider, SubSonic" connectionStringName="LocalSqlServer" generatedNamespace="CMS" stripTableText="CMS_" includeTableList="CMS_Content,CMS_Page" useSPs="false"/>
</providers>
</SubSonicService>
I don't think you can use the schema itself as a key in this way, but you could at least work around the issue with a combination of includeTableList and generatedNamespace. You said that you don't have duplicate table names across the different schemas, so it just might work.