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
Scotty ForceScotty Force 

SOQL data type issue

Have a custom field Weight on Contact object. There is a validation rule which prevents this field from editing after Pet-ID (custom field) is saved. We have an apex controller which lets only Profile1 Team to edit it. However now, we want System Administrators to edit this field as well. If i changes SOQL to SELECT Id from Profile where Name = 'Profile1' or 'System Administrator', end up getting two results. Have to change data type which i do not want. Is there an easier way to do this? 

Initial logic was,
Id setProfileId = [SELECT Id FROM Profile WHERE Name = 'Profile1 Team' LIMIT 1].Id;

this.isSetUser = UserInfo.getProfileId() == setProfileId;
Best Answer chosen by Scotty Force
Ashish KumarAshish Kumar

Hi Scotty,

Could you please elaborate how using 

SELECT Id from Profile where Name = 'Profile1' or 'System Administrator', end up getting two results and then why it caused to change data type ?

I guess once possible solution could be like below:

Id setProfileId = [SELECT Id FROM Profile WHERE Name = 'Profile1 Team' LIMIT 1].Id;
if(UserInfo.getProfileId() == setProfileId){
	this.isSetUser = true;
}else{
	String currentUserProfileID = UserInfo.getProfileId();
	String currentUserProfileName = [SELECT Name FROM Profile WHERE Id =:currentUserProfileID].Name;
	if(currentUserProfileName == 'System Administrator'){
		this.isSetUser = true;
	}
}

Please let me  know if it helps.

Regards,
Ashish Kr.

All Answers

Ashish KumarAshish Kumar

Hi Scotty,

Could you please elaborate how using 

SELECT Id from Profile where Name = 'Profile1' or 'System Administrator', end up getting two results and then why it caused to change data type ?

I guess once possible solution could be like below:

Id setProfileId = [SELECT Id FROM Profile WHERE Name = 'Profile1 Team' LIMIT 1].Id;
if(UserInfo.getProfileId() == setProfileId){
	this.isSetUser = true;
}else{
	String currentUserProfileID = UserInfo.getProfileId();
	String currentUserProfileName = [SELECT Name FROM Profile WHERE Id =:currentUserProfileID].Name;
	if(currentUserProfileName == 'System Administrator'){
		this.isSetUser = true;
	}
}

Please let me  know if it helps.

Regards,
Ashish Kr.
This was selected as the best answer
Scotty ForceScotty Force
Thank you, the solution works fine.