Am new to apex development. I have worked as admin. In account there are internal contacts and external contacts, external means customer will add a contact to account by just giving name and email kind of stuff, right now this is not our concern. when it comes internal contact means customer will add a user(who as credentials to login into application) as contact for that account. This type contacts will have a special tag enabled called "ISPORTALENABLED " see following example enter image description here

Now i have extracted user information through data loader i will present it here. Now i want to know how to write query for Each Account to get contact who has ISPORTALENABLED flag true and it LastLogin Information? enter image description here

  • What are you intending to do with this data? Do you just need to export it all in bulk, or are you looking to handle it on an account by account basis? Also are you looking to do anything with this data once you've queried it? That will probably impact on the answer that is most relevant to your use case.
    – Bigears
    Mar 23, 2018 at 14:16
  • i need to send an email to an each Account primary contact i.e., who are the contacts are not logged in from last 30 days
    – Laxman rao
    Mar 29, 2018 at 12:00
  • Thank you for the response - Additionally, are you looking for the email to be sent by an apex class? Or are you planning to send these manually to the primary account owner, once you've done your SOQL query?
    – Bigears
    Apr 4, 2018 at 12:53

1 Answer 1


You can directly get all this required data by querying user object. Refer below query.

Select id , Username, Email,LastLoginDate,ContactId, AccountId, IsPortalEnabled  from User where IsPortalEnabled = true

See if this helps!

You must log in to answer this question.

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