function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sihmeieossihmeieos 

Get UserInformation on Customer Portal

Hello,

 

I'm trying to get user information(customer portal user= contact)  in Apex class and trigger.

but I don't know how to get customer portal user infomation on Apex.

 

I want to add accountId to customObjectA when customObjectA created by custom portal user.

 

trigger instAccount on ProductNS__c (before insert) {
ProductNS__c[] pns = Trigger.new;
putAccountData.addDeleverCustomer(a)}
}
public with sharing class putAccountData {
public static void addDeleverCustomer(CustomObj A){
ID uid = UserID;//I get logined user's userId,contactId,accountId, here.
If (A.AccountId == null){
ID cid = [select ContactId from User where Id = uid];
ID aid = [select AccountId from Contact where Id = cid];
A.AccountId = aid;
}
}
}
 

 

Please help, how to get userId.

Thank you.

 

sihmeieos

Best Answer chosen by Admin (Salesforce Developers) 
Sam.arjSam.arj

You can use the UserInfo class in Visualforce page controllers:

 

 

ID uid = UserInfo.getUserId();

 

 

Cheers

 

 

All Answers

Sam.arjSam.arj

You can use the UserInfo class in Visualforce page controllers:

 

 

ID uid = UserInfo.getUserId();

 

 

Cheers

 

 

This was selected as the best answer
sihmeieossihmeieos

Thanks for quick response.

I confirm "Apex Code Develper's Guide",and edit below.

String uid = UserInfo.getUserId();

Thank you.

 

 

sihmeieos