0

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.

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

enter image description here

4 Answers 4

0

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.

  /lightning/o/Opportunity/new?defaultFieldValues=Name={!Opportunity.Name},
 AccountId={! IF( ISBLANK( Opportunity.AccountId ) , NULL, Opportunity.AccountId  ) }
0

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))}

Thanks,

2
  • but if user will include multi select picklist and want to prepopulate value on cloning, it will break Sep 5, 2020 at 20:59
  • I have tested the scenario based on above formula using Opportunity name, Account name.. Thanks!
    – Vinay
    Sep 8, 2020 at 7:53
0
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
    )}
0

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))}

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.