1

I have written the query from account record to view the profile Name for the particular user (Who have created the account record)

Which user created the account record and what is his profile name for that

Query

select id,JDE_ship_to_account_no__c,RecordTypeId,CreatedById where CreatedById IN (select id,name,profileid form users where id = '005b0000001XwxnAAC) from account where id = '0015E00000BHkPB'

But it is showing error:

Unknown error parsing query

How can I fix this query?

  • I don't understand. You want to query the profile name of the user who created the account. But you want this for a particular user. If you already have the id of the particular user. Why don't you request the user instead of the accounts? – Martin Lezer Mar 21 '17 at 10:35
  • You want to query the profile name of the user who created the account @MartinLezer yes – Learning user Mar 21 '17 at 10:36
  • So that's not for a particular user. You just want the profile name of the guy who created a specific account. Am I right? – Martin Lezer Mar 21 '17 at 10:37
  • In Main user, so Many internal users created the account ,I want to know the profilename of the user by the help of created account – Learning user Mar 21 '17 at 10:38
  • So that's not for a particular user. You just want the profile name of the guy who created a specific account. Am I right? Yes you are right – Learning user Mar 21 '17 at 10:39
6

First, there is a problem in your query because your where clause is before your from clause. Second, you don't need a nested query because you can query the CreatedBy relationship directly in your master query like this:

SELECT CreatedBy.Name FROM Account WHERE Id = '0015E00000BHkPB'
  • 1
    @Learninguser Additionally, remember you can traverse up a relationship up to 5 levels (e.g. Contact.Account.Owner.Manager.Name) and down a relationship 1 level (e.g. SELECT Id, (SELECT Name, ContentType FROM Attachments) FROM Contact LIMIT 100). – Dan Jones Mar 21 '17 at 10:51
  • @Dan Jones when we use subquery like this in which criteria where CreatedById IN (select id,name,profileid form users where id = '005b0000001XwxnAAC) in which critera – Learning user Mar 21 '17 at 10:56
  • @Martin Lezer now i know the CreatedBy.Name for user,i want his profile name how we can acheive this – Learning user Mar 21 '17 at 11:06
  • As @DanJones said, you can traverse up a relantionship up to 5 levels. So if you want to have the profile name you can do: SELECT CreatedBy.Profile.Name – Martin Lezer Mar 21 '17 at 11:14
  • @MartinLezer after using this SELECT CreatedBy.Profile.Name i got see my question – Learning user Mar 21 '17 at 11:24
1

Write something like this!

[SELECT id, (SELECT UserOrGroupId FROM GroupMembers) FROM GROUP WHERE Name = 'Finance' LIMIT 1]
  • 2
    Could you also explain it ? – Samuel De Rycke Mar 21 '17 at 13:03
  • @SamuelDeRycke SELECT id, (SELECT UserOrGroupId FROM GroupMembers) FROM GROUP WHERE Name = 'Finance' LIMIT 1 Using this query we are getting data from related table with same primary key – Tariq Mar 22 '17 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.