I am facing the error **

"A problem with the OnClick JavaScript for this button or link was encountered: {faultcode:'MALFORMED_ID', faultstring:'malformed id {Assessment__c.Id}', }

** " on clicking a custom Submit button on Assessment__c object. My purpose is, after clicking that submit button for a particular user profile the record will be opened using a read non-editable record type. Kindly advice.

Java Script code on Button Click

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

Controller :

   global class FinalAssesmentClass{

webservice static asResult submitMethod(ID asID){

    asResult res = new asResult();
    Assessment__c o=new Assessment__c(Id=asID);      

    String usrProfileName = [select u.Profile.Name from User u where u.id = :Userinfo.getUserId()].Profile.Id; 
    If(usrProfileName =='00eU0000000daQg')  
        o.RecordTypeId='012J00000008pwl';// Read only Record type  
        o.RecordTypeId='01IU0000000brV9'; //Normal record type    

    res.assId= asID;

    return res;

global class asResult {
    webservice String errorMsg;
    webservice Id assId;


1 Answer 1


Easy :)

Your code tells it to pass a JavaScript string '{Assessment__c.Id}'. Which is not a valid Id.

The ! is missing, try with {!Assessment__c.Id}

Whether this will do what you're after is another story. It will return to your JS code the "asResult" object (consisting of only the error message and same Id that was passed in) but won't actually do anything... And you don't use this result for anything (you don't have var callResult = sforce.apex.execute(...);)

Do you intend to flip the recordtypes back & forth depending on who's looking? That'd need an update o; line before return res;. And it looks messy, you might run into conflict when 2 people click the link at same time, it screws up the "last modified by", it might run into a validation rule that will cause a failure...

But why don't you use the more natural place - the page layout assignment section? If certain profile should always see this record in readonly mode - either do it by removing the right to Edit or change the page layout assignments.

I'm really bit confused what you want to achieve and not sure whether there's a clean way to do it. Consider building a readonly VF page for this maybe? Or send the user to VF page that has renderAs="pdf" attribute set, that'll be readonly all right ;)

  • Changed the code with {!Assessment__c.Id}..the java script error is not coming..but I am not getting any result...Can you suggest me some fix for this..thanks.
    – user4644
    Dec 13, 2013 at 12:17
  • The scenario is ..after completing the assessment when normal user hits teh submit button the record should go in read only mode. whereas when his manager higher up in level opens this record should always get it in a editable format.
    – user4644
    Dec 13, 2013 at 14:17
  • 1
    Just perform a real record type change (for everyone), in the submission button. And in page lay. assignment use "open" and "locked" layouts for normal people but "open" and again "open" for the managers. Ideally you'd add a validation rule that prevents changes if record type = "locked" and Profile is not one of allowed ones... because sneaky user could easily bypass this "locking by page layout" you're trying to do
    – eyescream
    Dec 13, 2013 at 14:23

You must log in to answer this question.