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
Deepika Gupta 26Deepika Gupta 26 

Login Name comapration with the field of the account

Hi All,
I have a requirement that on the click of account save button it has to check whether loginName and Keymanagername(Field on account which has lookup with user) are same or not if yes then assign it to one permission set.
As per my understanding i have Wriiten this in Account Handler Class 
Id userId=UserInfo.getUserId();
String userName=[Select Id, Name From User Where Id =:userId].Name;
and Created a list object on handler class like private List<KeyAccountManager__c> keymanagersFromAccounts = new List<KeyAccountManager__c>();
But i am not sure how can i compare this both because one is string and another is list object.Could any one that what would be the right approach for it.should i need to find all accounts keymanagers in a field and have to put a loop to check its matching with usename or not.I dont have a clear understaning that how to achieve this.
Nirmal ChristopherNirmal Christopher
As per my understanding you are comparing the two look up fields and if they are equal you are assigning the user to the permission sets. If im not wrong do the following
create  a trigger in the accounts object and extract the value from trigger context variable
then compare the two field values in side the loop
if tru then follow the link to update the permission sets. Hit best solution of it helps.