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
parthipan francisparthipan francis 

Hide Lookup field hyperlink for particular user only

Hi,
 How to hide the lookup field hyperlink for particular user only,when they are log in into salesforce. I have create the javascript and added into homepage component but it still not working. Kindly share ur knowledge. here my code

document.write('<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>');

document.write('<script src="/soap/ajax/28.0/connection.js" type="text/javascript"></script>');

document.write('<script src="/soap/ajax/28.0/apex.js" type="text/javascript"></script>');

Sfdc.onReady(function() {

 if (document.location.href.toString().indexOf("/a0C") != -1 && document.location.href.toString().indexOf("/a0C/o") == -1) {
    var VSCID = window.location.href.substring( window.location.href.indexOf('.com/') + 5);    
    
    var getProfName = sforce.connection.query("SELECT UserRole.Name,Profile.Name FROM User WHERE Id = '" + window.UserContext.userId + "' ");
    var records = getProfName.getArray("records");
    var SelectedProf = records[0]; 
    var UserRoleName = SelectedProf.UserRole.Name;
              alert(UserRoleName);
        var result = sforce.connection.query("SELECT id,Site_Contract__c FROM Visits__c WHERE Id = '" + VSCID + "'");
            var records = result.getArray("records");
            var SelectedRecord = records[0]; 
            var SiteContract = SelectedRecord.Site_Contract__c;
            alert(SiteContract);
            
            if(UserRoleName == 'Development')
            {
            alert('Welcome'+SiteContract);
            SiteContract.style.display = '';
            alert('End'+SiteContract);
                    
            }          

    } 

  });


Thanks in advance
David ZhuDavid Zhu
You may change this line:
var getProfName = sforce.connection.query("SELECT UserRole.Name,Profile.Name FROM User WHERE Id = '" + window.UserContext.userId + "' ");

to 
 
var getProfName = sforce.connection.query("SELECT UserRole.Name,Profile.Name FROM User WHERE Id = '" + window.UserContext.userId + "' ",callback);

And Add the following lines in your javascript code:
var callback = {onSuccess: handleSuccess, onFailure: handleFailure};
function handleSuccess(result) {}
function handleFailure(error) {alert(error);}

this will tell you if there is error at query.
David ZhuDavid Zhu
I guess you might get session id error. In that case, you need to add:

    sforce.connection.sessionId = "{!$Api.Session_ID}";

before
var getProfName = sforce.connection.query("SELECT UserRole.Name,Profile.Name FROM User WHERE Id = '" + window.UserContext.userId + "' ");