function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RajashriRajashri 

How to write formula(If -else) condition if checkbox is checked.

Hi,

 

I have a requirement if checkbox is checked then write N/A else TBD if there is nothing yet in the  Doc field. Otherwise it will contain the same name filled into the  Doc field.

 

I have written the below code,but eventhough checkbox is check it is not displaying N/A it is displaying TBD Only.

 

Can anyone please guide how can i modify the below formula so that it will display N/A if checkbox is checked.

if( checkboxreq__c,"N/A", BLANKVALUE( Doc__r.Name , "TBD" ))

 

Thanks in advance.

kriskkrisk

Whatever you wrote is correct and works. Please let me know what issue you are facing

RajashriRajashri

 

While loading the page it is showing correctly but it is not displaying properly on the summary page where i am trying to display this field(In short,At the time of  Saving checkbox field it's causing an issue)

 

Do you have any idea how can we set it?

 

 

 

 

 

 

 

 

kriskkrisk

Create that new field as Formula field and in the formula return type make sure you select "TEXT".  You should be fine. 

 

Otherwise please explain using screen shots what issue you are facing.

RajashriRajashri

Thanks for the reply.

 

I can't send u the snapshot due to limitations but below is my requirement.

 

 i have setup the value of checkbox to true in my page but it is not getting save as i m redirecting page to other URL.

 

URL.getSalesforceBaseUrl().toExternalForm() and checkbox value is not getting save while redirecting to new Page Url.

 

Is there any way to save that value.

Can you please guide?

 

 

 

 

kriskkrisk

So by checking the checkbox, are you redirecting the user to a different page? If so can you copy and paste the controller code?

RajashriRajashri

Hi,

Below is the complete scenario with Code.

 

I have created the object App__c. This Object has the field App_By__c as Formula     if( App_Not_Required__c,"N/A", BLANKVALUE( App_Done_By__r.Email , "TBD" )) and App_Not_Required__c as checkbox.

 

I am setting the checkbox value using below Helper method

 

public static List<App__c> getSECApp(String pDetailId) {  
            
        List<App__c> approvals = [SELECT ID, NAME, App_Date__c, App_Done_By__c, App_By__c,
                App_Role__c, App_Not_Required__c,
                SF_Record_Link__c
                FROM App__c
                WHERE Checklist_Detail__c = :pProjectDetailId AND App_Role__c != null
              ];
                
       
                for(App__c app :appr){
                if(app.App_Role__c == 'User Experience Lead')
            )
                if(app.App_Done_By__c == null)
                {
                  app.App_Not_Required__c=true;
                }
                else {
                app.App_Not_Required__c=false;
                
                }
                }
                return appr;
   }

   public static boolean hasAppChanged(App__c pOld, App__c pNew) {  
        if(pOld.App_Done_By__c != pNew.App_Done_By__c ||
           pOld.App_Not_Required__c != pNew.App_Not_Required__c ||
             pOld.I_Approve__c != pNew.I_Approve__c ||
          
            return true;
         }  
       
        return false;
    }

 

Now I am opening the new page and my checkbox and other fields are getting loaded properly.

 

and i add save button on my page. I am calling{!saveApp} method after click on save button but checkbox value is nt getting save and it is displaying TBD instead of N/A.

 

public PageReference saveApp() {
        executesaveApp();
        PageReference returnPage = new ApexPages.StandardController(Detail).view();
        returnPage.setRedirect(true);
        return returnPage;
    }
    public void executesaveApp() {
        String msg = '' ;

        List<App__c> toBeUpdated = new List<App__c>();
        List<App__c> dbAppr = Helper.getSECApp(Detail.Id);

        for(App__c newA: appr){
                for(App__c oldA: dbAppr){
                        if(newA.Id == oldA.Id){
                                if(oldA.I_Approve__c == false && newA.I_Approve__c == true){
                                   newA.App_Date__c = date.today();
                                }  
                                boolean hasChanged = Helper.hasAppChanged(oldA, newA);
                                if(hasChanged){
                                        NewA.SF_Record_Link__c = URL.getSalesforceBaseUrl().toExternalForm() + '/' + NewA.id;
                                        toBeUpdated.add(newA);
                                }
                        }
           }
        }
        if(toBeUpdated.size() > 0){
                update toBeUpdated;
        }
        msg = 'Save Completed';
        
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.CONFIRM,
                                             msg);
        ApexPages.addMessage(myMsg);
                
        return;

    }