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 Set the checkbox value redirecting Page

Hi,

 

How can we set the value of checkbox?

 

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 set.

 

Can anyone please guide?

 

prady-cmprady-cm

Do you want to pass the value of checkbox to the new url?

Does this value needs to be updated before getting redirected?

RajashriRajashri

Hi,

 

I want  to pass the value of checkbox to the new URL currently it is getting updated while redirecting

prady-cmprady-cm
URL.getSalesforceBaseUrl().toExternalForm() + '?check='+ myAccount.check__c

you can use

getParameters().get('check') to get the value stored in check

RajashriRajashri

Thanks..Below is the complete scenario of my code.Can you please tell me where to set these parameters in below 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;

    } 

prady-cmprady-cm

I think this peice of code is which is causing the problem.

 

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

               // adding changed record into empty list

              // emptylist.add(app);  / return this list instead of appr
                }
                return appr;

 

You are making changes to app and returning appr which i believe is not changed. Can you put a debug statement to check if the field has got updated?

If no then create a empty list of App__c and add the changed records into that list and return that list

 

 

prady-cmprady-cm

were you able to get it to work?

RajashriRajashri

Thanks!

 

I tried your option but i am getting an error.

 

Cannot Modify a Collection While It Is Being Iterated?

 

Why so?

 

 

RajashriRajashri

I have added the list like

 

appr.add(app) as mentioned by you

 

but getting an error

 

Cannot Modify a Collection While It Is Being Iterated?

 

Why so?

 

 

 

prady-cmprady-cm

You cannot add to the looping collection.

 

you need a create a new list collection before loop and add it to that list.

 

List<App__c> newList= new List<App__c>();

newList.add(app)

 

RajashriRajashri

Thanks a lot!

 

I created the new List but still i am facing the same problem.

 

Checkbox is not getting loaded with defaulted values.

 

Any other solution?

prady-cmprady-cm

do you want to get on skype or any other IM tool.

I am sure its some small issue..

I need to take a look at the code you have done till now

prady-cmprady-cm

Where are you populating appr ?

Can you see if its even looping by giving in some debug statements?

RajashriRajashri

I have sent you my email id from message