1 resposta
Hi,This is one way to get the user Id./** Author: Prakash Jada* Created Date: March 29, 2020*/global class FOBCallouts1{ // Global variable declaration Private static final String TAG = 'TAG-FOBCallouts1 :: '; private static String status = 'Non-active'; //== Method to validate the Tenant status public static void tenantUpdate(list<tenant__c> TenList, map <id,tenant__c> oldMap) { Set<String> nameSet = new Set<String>(); Set<Id> userIdSet = new Set<Id>(); // Loop to iterate over the list of tenants for(tenant__c objten : tenList) { // Condition to verify the Status of the tenant if(oldMap.get(objten.Id).Status__c != objten.Status__c && status.equalsIgnoreCase(objten.Status__c)) { nameSet.add(objten.Name__c); } }// END FOR System.debug(TAG + 'Name Set size : ' +nameSet.size()); // Condition to check for the name set if(nameSet != null && nameSet.size() > 0) { // Query to fetch the User details List<User> users = [SELECT ID, Name FROM User WHERE Name = : nameSet]; System.debug(TAG + 'User List size : ' +users.size()); // Condition to check for the user details if(users != null && users.size() > 0) { // Loop to iterate over the List of users for(User user : users) { userIdSet.add(user.Id); }// END FOR System.debug(TAG + 'User Id Set Size : ' +userIdSet.size()); }// END IF // Condition to check for the User Id set if(userIdSet != null && userIdSet.size() > 0) { FOBCallouts1.doCallout(userIdSet); } } } @future(callout = true) private static void doCallout(Set<Id> userIds) { // Loop to iterate over the User Id's for(Id userId : userIds) { // Callouts Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals'); request.setMethod('POST'); String JsonString=JSON.serialize(userId); String body = 'Please deactivate FOB for following tenants(ID)'; request.setBody(body+JsonString); System.debug(TAG + 'Verifying the request body : ' +request.getBody()); }// END FOR }}1. I created a name custom field and used it against the User object to get the User Id. I hope this helps.Thanks,Prakash. J