0

I need to fetch email of the user which they place under personal information but I seem to be getting back all the contact's emails of the user.

enter image description here

So for the above example, I need [email protected]. My code and query is as follows:

const conn = new jsforce.Connection({
        instanceUrl: ...,
        accessToken:...,
        refreshToken: ...,
        oauth2: {
            "clientId": ...,
            "clientSecret": ...,
            "redirectUri": ...
        },
    });

const query = "Select  Email FROM User";
const result = await conn.query(query);

But I do not get this email, I get all the contacts email in an array which is like 100+ in length.

1
  • You need a WHERE clause
    – identigral
    Commented Nov 30, 2020 at 5:49

1 Answer 1

0

Your query is returning every user in the database. You need to limit the query to just the current user.

You should call the identity() method, and then you can query the user:

con.identity((err, res) => {
  if(res) {
    let result = conn.query(`select email from user where id = '${res.user_id}'`);
  }
});

Or, you can use Chatter:

conn.chatter.resource('/users/me').retrieve((err, res) => {
  let email = res.email;
});

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .