0

I have a custom List button(Behaviour - Execute javascript) and that needs to be accessible to a user for a particular Opportunity Record type alone. For rest of the Opportunity record types, it should not perform action/show insufficient privilege. Any idea how can this permission be given?

enter image description here

3

A configuration-only way would be to use multiple page layouts, assign the layout with the custom button to the record type where it should be available, and the other layout without the custom button for other record types. That does mean handling two different layouts, however.


Alternatively, you can modify your JavaScript and Apex Code to enforce the rule.

JavaScript

try {
  var result = sforce.apex.execute(...);
  window.top.location = '/{!Opportunity.Id}';
} catch(e) {
  alert('An error occurred during processing.\nReason: '+ (e.message || e) );
}

Apex Code

webservice static void invokeSubProductUpdates(Id oppId) {
  Opportunity record = [SELECT RecordType.Name FROM Opportunity WHERE Id = :oppId];
  if(record.RecordType.Name != 'Some Type') {
    throw new InvalidParameterValueException('This action may only be performed on "Some Type" opportunities.');
  }
  ...
}
2

Option 1 -- Recomended

You can assign different layouts for different record types. That said... you can add your button on layout for a particular record type.

Option 2

In your javascript code for the button you can include follwing check even before firing any apex code

var recordType = '{!ObjectApi__c.RecordType }';
if(recordType != <RecordType expected>) alert("insufficient privilege");
//code continues ....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.