I have set up a customer community for a customer of ours that stores an Account ID on the User to determine what account the User views the community for. This account ID field has to be a text field since you can't create lookup fields on a User, so we are automating filling it in and then giving admins the ability to change it afterwards.
Above works, but I ran into an issue today where we had the 18 Digit ID stored on one user and the 15 digit ID on another. I constructed a set of the Account ID assigned to a user and the child account IDs of its children, and used a string query that used AND ID IN: accIDs
. This worked for the 18 digit ID, but didn't for the 15 digit ID.
Does ayone know what the best practices/ places you should use the 18 digit ID vs. the 15 Digit one?
Here is a snippet of code-
acids.add(accSel);
set<string> nas = new set<string>();
nas.add(accSel);
for(integer i = 1; i <= 5; i++){
IF(!nas.isEmpty()){
List<Account> accs = [Select id, Name, ParentID From Account Where ParentID IN:nAs];
IF(!accs.isEmpty()){
nAs.clear();
FOR(Account a:accs){
accounts.add(a);
nas.add(a.id);
acids.add(a.id);
}
}
}
}
//--Further Down--
String query = 'Select Name, ID, etc. ';
//More filters/fields, also Source__c is lookup to Account Object
query += ' AND Source__c IN: acids ';
Above shows an example of my code where I am generating a list of child accounts and then running the query with an 'IN:' filter to see if the ID is in the list of IDs.