+ Start a Discussion
Shruti NigamShruti Nigam 

How to set user id in json ?

Hi ,
 I need help in json.
When i try to create record using json i am getting error in $User.Id
[
	{
		"attributes": {
			"type": "Activity_Template__c"
		},
		"Name": "Expense test",
		"Assigned_To__c": $User.Id,
	}
]

I want to dynmically set the Assigned_To__c i.e whoever runs this json Assigned_To__c will contain there user id.

Thanks in advance
Rishabh Bansal 23Rishabh Bansal 23
Hi Shruti,
Did you try this:-
UserInfo.getUserId()
Thanks,
Rishabh
Shruti NigamShruti Nigam
Thanks rishabh for Answering but it is not working
Prafull G.Prafull G.
If you are generating this JSON dynamically, then @Rishab's suggestion should work.
However if this is sting then you have to tweak this a bit. Try following -
String jsonString = '[{"attributes": {"type": "Activity_Template__c"},"Name": "Expense test","Assigned_To__c":\'' + UserInfo.getUserId() + '\'}]';