+ Start a Discussion
MarionVMarionV 

Custom button to create new case

Happy holidays, all.

 

We have recently started using cases for our organization.

 

We have added a custom lookup field to opportunities from cases.

 

We are now using the related list for cases on our accounts, contacts, and opportunity layouts (detail). On accounts and contacts, we are using the standard new case button, but for opportunities this is a custom lookup and we cannot do this.

I've been attempting to create a custom button to make a new case from the cases related list on the opportunity detail screen, but it is not working. (TBH I don't know what I'm doing, I'm just trying to follow an example, so sorry if this is a silly question.)

I made a custom button on cases called new case.

Here is the formula:
URLFOR($Action.Case.New,null,[saveURL=Opportunity.Link, retURL=Opportunity.Link,CF00NG0000008hHho_lkid=Opportunity.Id,CF00NG0000008hHho=Opportunity.Name],true)

Where 00NG0000008hHho is the ID for the custom lookup field for opportunities from cases.

If I add the custom button to the related list, it just gives me a broken link message. The resulting URL that doesn't work is:

https://na11.salesforce.com/servlet/URLFOR($Action.Case.New,null,[saveURL=Opportunity.Link,retURL=Opportunity.Link,CF00NG0000008hHho_lkid=Opportunity.Id,CF00NG0000008hHho=Opportunity.Name],true)

Can you see what I am doing wrong?

Many thanks.

Best Answer chosen by Admin (Salesforce Developers) 
Rahul SharmaRahul Sharma

Hey Marion,

 

If you use URL for without merge fields, then it will append whole URLFOR string to the url.

Also one more thing, you would need to enclose all the parameters(which you are passing as inputs) as string(in quotes).

Action for creating new case is NewCase, not simply NEW (refer this Valid Values for the $Action Global Variable).

 

So correct code is below:

{!URLFOR($Action.Case.NewCase, 
null, [ "saveURL"=Opportunity.Link, "retURL"=Opportunity.Link, "CF00NG0000008hHho_lkid"=Opportunity.Id, "CF00NG0000008hHho"=Opportunity.Name ],
true)}

 

All Answers

Rahul SharmaRahul Sharma

Hey Marion,

 

If you use URL for without merge fields, then it will append whole URLFOR string to the url.

Also one more thing, you would need to enclose all the parameters(which you are passing as inputs) as string(in quotes).

Action for creating new case is NewCase, not simply NEW (refer this Valid Values for the $Action Global Variable).

 

So correct code is below:

{!URLFOR($Action.Case.NewCase, 
null, [ "saveURL"=Opportunity.Link, "retURL"=Opportunity.Link, "CF00NG0000008hHho_lkid"=Opportunity.Id, "CF00NG0000008hHho"=Opportunity.Name ],
true)}

 

This was selected as the best answer
MarionVMarionV

Thank you so much, Rahul, your reply is really appreciated.

VashnarVashnar

I am trying to make this code work in the same manner, but so far unsuccessfully. Here is the code I'm using:

 

{!URLFOR($Action.Case.NewCase,
Opportunity.Id,
[
"saveURL"=Opportunity.Link,
"retURL"=Opportunity.Link,
"00NC0000005dPjk_lkid"=Opportunity.Id,
"00NC0000005dPjk"=Opportunity.Name
],
true)}

 

I've replaced my lookup field ID in the code, but when I click the button a new case is opened but the lookup field is not populated with the related opportunity.

 

Any help is appreciated!

Brian