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
shoukat hussainshoukat hussain 

How to use $User.Username in sharing rules in criteria base

Hi,

I am facing a problem in a scenario that i have one object "Ob1" and this object have one field "my user name", i have made 3 transaction by shoukat003@training.com user, three transaction are below:
1. shoukat.sales@training.com
2. shoukat.manager@training.com
3. xyz@training.com

I have further 2 user shoukat.sales@training and shoukat.manager@training.com, now i want to make a security that when shoukat.sales@training.com user will login then he can access only those transaction which's "my user name" column have "shoukat.sales@training.com" value . Summary of question is
 
"Can i use $User.Username function in "value" column when i use criteria base sharing rule." OR can we apply this security in other way.

Thanks in advance.

Regards, 
Shoukat Hussain
Suneel#8Suneel#8
It seems like you are trying to replicate Owner functionality manually.Owner field does the same job.Is there any issue with it?
Suneel#8Suneel#8
You cannot do it through Sharing Rules I guess.Instead you can add a row in Share object -MyCustomObject__Share- available to you.I think this can be done upon the updation of the particular field in trigger 
shoukat hussainshoukat hussain
Thanks Suneel#8,
Yes -  there is an issue that when i login by shoukat.sales@training.com then user could not seen 1st transaction which have "shoukat.sales@training.com" value in "my user name" field.

Regards,
Shoukat Hussain
shoukat hussainshoukat hussain
Hi Suneel,
"my user name" is actually "Assign to" column, when i assign a transaction to "shoukat.sales@training.com" user then it can be view by shoukat.sales@training.com user.

Regards,
Shoukat Hussain
shoukat hussainshoukat hussain
Thanks Suneel,

Let me check your 2nd reply.

Regards,
Shoukat Hussain
Suneel#8Suneel#8
You can try below link for more details

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_bulk_sharing_creating_with_apex.htm