0

I've a list button which returns a URL & I need to add a condition based on the user id

IF(
    $User.Id = Apttus_Proposal__Proposal__c.APTS_SalesDeveloper__c,
    {!URLFOR('/apex/x?sObjectType=Apttus_Proposal__Proposal__c','sObjectId=' + Apttus_Proposal__Proposal__c.Id)},
    "javascript:alert('You must be the Sales Developer for this Account to perform this action.');"
) 

but when I try this formula, I'm getting this error -> Error: Enter a URL that is valid and well-formed.

Any suggestion about how to fix or configure the formula?

2 Answers 2

0

You can use a JavaScript button to handle the condition and URL redirection.

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}

var userId = '{!$User.Id}';
var salesDeveloperId = '{!Apttus_Proposal__Proposal__c.APTS_SalesDeveloper__c}';

if (userId === salesDeveloperId) {
   window.location.href = '/apex/x?sObjectType=Apttus_Proposal__Proposal__c&sObjectId={!Apttus_Proposal__Proposal__c.Id}';
} else {
   alert('You must be the Sales Developer for this Account to perform this action.');
}

Refer to this Construct Effective Custom URL Buttons and Links and Use Quick Actions, Custom Buttons, or Apex

1
  • Thank you for the answer but i need to use that button in a related list which requires to be list button Commented Oct 14, 2024 at 7:33
0

The error refers to the part where you're using javascript in the url button. This is not supported.

What you could do is create a very simple webpage on your org (e.g. a visualforce page) that contains that error message. Then add the url of that page to the second part of your list button url (instead of the javascript).

Now in this case, if the user is not authorized, they will be taken to that Visualforce page.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.