Type of returning data in Salesforce SELECT - select

Please, help me to understand which type of data is returned after SELECT?
For example, we've got such request: [SELECT Name FROM Account].
Have we got Account object or only String for Name? And if we get Account could we turn to other Account fields in addition to Name?

If there is only one Account in your org, you can store the result of this query in Account's instance but it is recommended to store the query result in List of Account (List).
A SOQL query returns a list of records of the Object on which you're querying, in this case it's Account. To access other fields you'll have to add them to the SELECT statement.

That query returns a list, regardless of how many records, if any, get returned. If you specified 'Limit 1' it would return an Account object. In either case, only the Name field would be populated. If issued from Apex, any attempt to reference other fields on the result Account would throw an error.

Related

Cloud Firestore and Ionic

How can I get the document id of a collection present in the cloud Firestore?
I tried to get it by using the
firebase.firestore().collection("collectionName").doc().id
but I didn't get the appropriate result.
firebase.firestore().collection("societies").doc().id and it returns a id which is not equivalent to society documentId
That's correct because everytime when you are using the above line of code, you are generating a new document id which will never be the same with one that already exist in your database.
In order to use a new document id, first you need to generate it (as you already do) and then store it in a variable. Having that varaible which holds that id, you can use it to get that particular document from the database by passing this id as an argument to the doc(id) function:
firebase.firestore().collection("societies").doc(this.myId)

How to get the particular row by column in smartsheet api

I am using smartsheet as a database and I want to query the smartsheet by column name equals value like in sql db for example: To get the particular row of Employee sheet where salary equal to 10000. But documentation describes only how to get list of rows and how to update and delete rows by row id.
https://smartsheet-platform.github.io/api-docs/?java
What i want is to achieve without knowing id of the row. But I can do by search function by searching the salary of the employee
https://api.smartsheet.com/2.0/search?query=10000
and the response of above call will have row id and again i should make a call with rowid to get that row by below call which I don't want.
GET /sheets/{sheetId}/rows/{rowId}
Can anyone help me out?
Although some folks do try to use Smartsheet like a database, it's not really designed to be queried via API in the same way that you'd use transact SQL to query a SQL database.
I don't believe the scenario that you've described (i.e., using the Smartsheet API to retrieve row(s) in a sheet where [column value] = [specified value]) is possible. Instead, you'll have to use the API to get the data in the sheet (Get Sheet) and then in your code, query the data that you received in the API response (to identify the row(s) that match your query criteria).

VSTS Get ID of Stored Queries

I am trying to execute a VSTS stored query using WorkItemTrackingHttpClient
The stored query is identified by it's ID and there are code samples to programmatically get this ID. However, I can't seem to figure out how I can get this ID within VSTS online view. Clicking on the query lists the workitems returned bye this query but the query ID isn't listed anywhere. Is this due to privileges of my authentication or I am overlooking something.
You can get the query ID in the URL:
Select a query
The URL format will be like: https://[xxx].visualstudio.com/[project]/_queries?id=effb4d62-1b9b-42e9-af7c-dbef725fca4a&_a=query.
The id is the value of id parameter.

How to update record in DB using namedqueries

I would like to know how to create an update named query to update a record in a derby db.
Here is my scenario, i have a table called account in a database named bank.
In the account table there are 2 columns, account id and balance.
I want to type an update query which will update the balance of a record using the account id.
I am familiar with sql queries but not with named queries.
Here is what I have created
#NamedQuery(name="Accountcb004415.updateBalance",
query="UPDATE Accountcb004415
set a.balance = :balance WHERE a.accountid= :accountid")
However the above query doesn't work.
What seems to be wrong here ?
I guess you have missed identification variable a in the query definition. In other words entity name needs to be aliased with value a. Try this:
UPDATE Accountcb004415 a
set a.balance = :balance WHERE a.accountid= :accountid

Salesforce: trigger on related list

Suppose I have two objects
1.Account- standard object[it has a field name Status_c which is a picklist having value inprogress and closed]
2.Client_c - custom object[it also have same field name Status__c which is a picklist having value inprogress and closed]
and Client__c has lookup to Account name which means Account has a related list of client object .
My question is :
I want to write a trigger where if I put account status to "closed" I can not put client status to "closed",it should throw an error message on client object or if I put client status to closed I can not put account status to closed vice versa.
Can any one please help me to write a trigger on this??
Conceptually, I think what you are looking to do is set up Validation Rules on both of those objects. Your validation rule on Client_c should be pretty simple: TEXT(Status_c) == 'Closed' && TEXT(Account_c.Status_c) == 'Closed'
The more interesting piece is how you handle making sure none of your related items are Closed when you move the Account to Closed. I tend to prefer creating a field on the Account that keeps track of the status of the related items (checkbox) that basically tells me whether it is valid for me to change my status or not. In this case, the validation rule becomes pretty simple. In order to set that boolean value, I end up using a Trigger on Client__c that basically just grabs all the Accounts when a Client is being modified in the batch (taking into account both inserts, upserts, and deletes):
SELECT Account__c.Id FROM Client__c WHERE Id =: Trigger.new OR Id =: Trigger.old
Then create a Set of all the Account Ids (in this example, named accounts), and run a query to retrieve ALL Clients related to those Ids (in a single query to ensure you don't hit SOQL limits).
SELECT Account__c.Id, Status__c FROM Client__c WHERE Account__c.Id =: accounts
From the results of this, you will iterate over all of the entries, tossing them into a Map keyed by the Account Id where the value is a List of Clients. When you are done, run a query to get all accounts based on the "accounts" list from earlier (which was just a list of strings, not actual Accounts), subsequently iterate over all the Clients associated with that Account, and if a Client is marked as Closed, you will update the metadata of that Account accordingly. If no Clients are closed, the Account will be marked as such. Once you are finished, run an update statement to update the list of Accounts that you have modified.