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
Adila Hilal 15Adila Hilal 15 

i have to call a apex code from Flow which will update a user profile and role based on anther object in salesforce

i am trying to write a basica Apex code for updating user profile and role id base off  two text fields on user , last profile Id and last role Id.its a part of approval process process where a user submits request to get temprory admin access.after end time passes the user profile reverts back

tried to user Flow with process builder but its thrwing error.so I thought because updates involve two different objects, calling apex from process builder can makes updates easy.
EranVEranV
Not sure I understand - what should the new profile selection base on? Which profile should be selected per which parameter?
Adila Hilal 15Adila Hilal 15
we are automating a process where a salesforce user can have sytem admin permission for a time period.We are following approval process automation.user has to create a request in an admin request object.here ita look up to user .as sson as admin access startrday & time starts , the user profile changes ti system ad,in as well as role to a specefic role.once adminaccesse end date passed , it will revert back to user original profile.

here two different objrcts are involved, user & Admin access.i have created two custom fields on user object witl Last profile Id & last role Id that populates user last role & profile Ids.

I have used process buildet to change user profile to system admin & saving last role & profile Id values in custom fields on user object.I tried to use flow are call from apex to revert the profile back to original , but its not working.here if I call Apex from PB , it may work.
EranVEranV
You can probably achieve this without Apex at all. How about adding an additional datetime field to indicate the time when the admin access should expire, then when populate this field when assigning the admin profile, which in turn invokes a time based process to reassign the old profile and role when the date has come.
Adila Hilal 15Adila Hilal 15
Hi,

I am trying to add screen shot here. but unable to.any idea why I can not add screen shot