Created custom button for url hack in lightning and added on opportunity page layout. IF opportunity lookup field Account have value then it is working but if it not there then show blank. so i have added if condition but it is throwing weird error on UI showing random id and contact your system admin.

   AccountId={! IF( ISBLANK( Opportunity.AccountId ) , '', Opportunity.AccountId  ) }

enter image description here

4 Answers 4


I have tried '' it's not worked then tried null again its not worked then After so much struggle, problem is resolved. so instead of null, we have to use NULL.

 AccountId={! IF( ISBLANK( Opportunity.AccountId ) , NULL, Opportunity.AccountId  ) }

Use URLFOR() expression in formula to pass the lookup value in the parameter only if lookup value exists using ISBLANK(). Above formula will not populate account lookup field.

Try below:

{!URLFOR('/lightning/o/Opportunity/new?defaultFieldValues=Name=' +(Opportunity.Name) + IF(ISBLANK(Opportunity.AccountId),'', ',AccountId='+Opportunity.AccountId))}


  • but if user will include multi select picklist and want to prepopulate value on cloning, it will break Commented Sep 5, 2020 at 20:59
  • I have tested the scenario based on above formula using Opportunity name, Account name.. Thanks!
    – Vinay
    Commented Sep 8, 2020 at 7:53
Just to add to Vinay's response, as it took me some time to edit it (And it works!)

 {!URLFOR('/lightning/o/Case/new?useRecordTypeCheck=1&defaultFieldValues=Cloned_from_Case_c='+(Case.Id) //lookup
         +',Labels_Text__c='+(Case.Labels_Text__c) //text
         +',Tier__c='+(text(Case.Tier__c)) //picklist
         +',Time_Zone__c='+(text(Case.Time_Zone__c)) //Picklist
         +',Origin='+'Support' //this one is for simple static text
         +IF(ISBLANK(Case.ContactId),'',',ContactId='+Case.ContactId) //lookup
         +IF(ISBLANK(Case.SuccessId__c),'',',Success__c='+Case.SuccessId__c) //lookup
      +IF(ISBLANK(Case.AccountId),'',',AccountId='+Case.AccountId) //lookup

Vinay then how to use URLENCODE if my description field has special characters within the above url you have provided. In the below url IF case lookup field Account have value then it is working but if it not there then show blank and description,subject field should also include special characters if any.

{!URLFOR('/lightning/o/Case/new?useRecordTypeCheck=1&defaultFieldValues=Subject=' +(URLENCODE(Case.Subject)) +',Description=' +(URLENCODE(Case.Description))+',ParentId='+(Case.Id)+ IF(ISBLANK(Case.AccountId),'', ',AccountId='+Case.AccountId)+ IF(ISBLANK(Case.ContactId),'', ',ContactId='+Case.ContactId))}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .