• KRISHNAMURTHY ANANTHARAMAKRISHNAN
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 3
    Replies
I am trying to learn Apex and a newbie at this. I am trying to do the following trailhead:

https://trailhead.salesforce.com/trails/force_com_dev_beginner/modules/apex_triggers/units/apex_triggers_intro

In the example, they provide the following code:
// Get the related opportunities for the accounts in this trigger
Map<Id,Account> acctsWithOpps = new Map<Id,Account>( [SELECT Id,(SELECT Id FROM Opportunities) FROM Account WHERE Id IN :Trigger.New]);

I don't understand why map is declared of type Account but then the subquery (SELECT Id FROM Opportunities) returns IDs of type opportunities?

Second question:
System.debug('acctsWithOpps.get(a.Id).Opportunities.size()=' + acctsWithOpps.get(a.Id).Opportunities.size());


Since opportunities is a child object to account, why do we use get(a.id).opportunities because I thought the dot notation was to traverse from child to parent?
My visualforce site was working fine without any issues but now I am getting an error when I try to open the site. Can you check the below code? Previously the site was working fine.

VF Code:
<apex:page controller="i2"  sidebar="false" lightningStylesheets="true"  > 
    
    
    <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" lang="en">
        <head>
            <meta charset="utf-8" />
            <meta http-equiv="x-ua-compatible" content="ie=edge" />
            <title>SLDS ResponsiveDesign Visualforce Page in Salesforce Mobile</title>
            <meta name="viewport" content="width=device-width, initial-scale=1" />
            <apex:slds />
        </head>
        <body>
            
            <div class="slds-scope">
                
                <style>
                    .mystyle {
                    
                    color: black;
                    font-size: 18px;
                    font-weight: bold;
                    }
                    body .bPageBlock .pbBody .red .pbSubheader{
                    background-color:#585858;
                    
                    }
                    body .bPageBlock .pbBody .grey .pbSubheader{
                    background-color:#585858;
                    
                    }
                    body .bPageBlock .pbBody .grey .pbSubheader h3{
                    color:#FFFFFF;
                    
                    }
                    
                    .grey
                    {
                    background-color:white;
                    }
                    
                  
                    
                </style>
                
                
                <apex:form id="theform" >
                    
                    <apex:pageBlock id="section1"  >
                        
                        <apex:outputPanel id="errmsg">
                            <apex:pageMessages />
                        </apex:outputPanel>
                        
                        
                        
                        
                        <div class = "mystyle">
                            Cleaning Activities
                        </div>
                        
                        
                        <apex:outputPanel styleClass="grey" layout="block">
                            <apex:pageBlockSection title="Login" collapsible="false"> 
                                <apex:inputField value="{!cle.Password__c}"/>
                            </apex:pageBlockSection>
                        </apex:outputPanel>
                        
                        
                        
                        
                        <div align = "center">
                            <apex:commandButton styleClass="slds-button slds-button--brand" value="Retrieve Cleaning Activities" action="{!retrieve}"  /> 
                        </div>
                        
                        
                        <apex:outputPanel id="CleaningSection" styleClass="grey" layout="block">
                            <apex:pageBlockSection columns="2" title="Cleaning Activity" id="section1" collapsible="false">
                                <apex:inputField value="{!cle.Operation__c}" required="false"/>
                                <apex:inputField value="{!cle.Cleaning_Company__c}"/>
                                <apex:inputField value="{!cle.PTW_Number__c}"/> 
                                <apex:inputField value="{!cle.Cleaning_Start_Date__c}"/>
                                <apex:inputField value="{!cle.Cleaning_End_Date__c}"/>
                                <apex:inputField value="{!cle.Full_Site_Cleaning__c}"/>
                                <apex:inputField value="{!cle.Specific_Size_Cleaned_kWp__c}"/> 
                                <apex:inputField value="{!cle.Status__c}"/>
                                <apex:inputField value="{!cle.URL_of_Photos_folder__c}"/>  
                            </apex:pageBlockSection> 
                        </apex:outputPanel>
                        
                        
                        <div align="center">
                            <apex:commandButton styleClass="slds-button slds-button--brand" value="Save Cleaning Activity" action="{!save1}"  >
                                <apex:param name="buttonId1" value="button1" assignTo="{!paramValue}"/>
                            </apex:commandButton>
                        </div>
                        
                        
                    </apex:pageBlock>
                    
                    <apex:pageBlock id="section2">
                        
                        <apex:outputPanel styleClass="grey" layout="block">
                            <apex:pageBlockSection columns="2" title="Permit to Work Number"  collapsible="false">
                                <apex:inputField value="{!ptw.PTW_Number1__c}" required="false" />
                                <apex:inputField value="{!ptw.Number_of_Workers__c}"/>
                                <apex:inputField value="{!ptw.Date__c}"/>
                                <apex:inputField value="{!ptw.Cleaning_Activity__c}" />
                            </apex:pageBlockSection> 
                        </apex:outputPanel>
                        
                        <div align="center">
                            <apex:commandButton styleClass="slds-button slds-button--brand" value="Save Permit to Work Number" action="{!save1}" reRender="errmsg">
                                
                                <apex:param name="buttonId2" value="button2" assignTo="{!paramValue}"/>
                            </apex:commandButton>
                            
                            <apex:commandButton styleClass="slds-button slds-button--brand" value="Reset PTW" action="{!refresh}" />
                            
                        </div>
                        
                    </apex:pageBlock>
                    
                    
                    <apex:pageBlock > 
                        <apex:pageBlockSection >
                            
                            <apex:pageBlockTable value="{!clelist}" var="a" id="tableBlock" style="width:130%" >
                                <apex:column headerValue="Ticket Number">
                                    <apex:outputLink value="https://c.ap2.visual.force.com/apex/Record_detail_Vf_Page?id = {a.Cleaning_Activity__c}">{!a.Name}</apex:outputLink>
                                </apex:column>
                                <apex:column headerValue="Contractor" value="{!a.Password__c}"/>
                                <apex:column headerValue="Number of Workers" value="{!a.Number_of_Workers__c}"/>
                                <apex:column headerValue="Start Date" value="{!a.Cleaning_Start_Date__c}"/>
                                <apex:column headerValue="End Date" value="{!a.Cleaning_End_Date__c}"/>
                                <apex:column headerValue="PTW Number" value="{!a.Permit_to_Work_Number__c}"/>
                            </apex:pageBlockTable> 
                            
                        </apex:pageBlockSection>
                    </apex:pageBlock> 
                    
                    
                    
                </apex:form>   
                
            </div>
        </body>
    </html>
   
</apex:page>
Controller:
public class i2{
    public Cleaning_Activity__c cle{get;set;}
    public Permit_to_Work_Number__c ptw{get;set;}
    public List<Cleaning_Activity__c> clelist{get;set;}
    public String paramValue{get;set;}
    
    
    //constructor to create a new record
    public i2(){
        cle = new Cleaning_Activity__c();
        ptw = new Permit_to_Work_Number__c();  
        
    }

    public void refresh(){
        ptw = new Permit_to_Work_Number__c(); 
    }
    
    //Assigning password to Cleaning Company
    /* public void assignPassword(){
          system.debug(cle.Password__c);
         if(cle.Password__c != null){
       cle.Cleaning_Company__c = cle.Password__c;
         }}*/
    
    public void retrieve()
    {
        if(cle.Password__c == 'pv' || cle.Password__c == 'sunsure')
        {
            clelist = [SELECT Name, Password__c, Cleaning_Company__c, Number_of_Workers__c, Cleaning_Start_Date__c, 
					Cleaning_End_Date__c, Permit_to_Work_Number__c,PTW_Number__c FROM Cleaning_Activity__c where Password__c =: cle.Password__c];
            system.debug(clelist);   
        }
        else if(cle.Password__c == NULL)
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please key in the password to retreive the details'));
        else
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Password is incorrect'));
    }
    
    
    
    public void save1(){  
        system.debug('paramValue ' + paramValue);
        if(paramValue == 'button2')
        {
            system.debug('Password is ' + cle.Password__c);
            if(cle.Password__c == 'pv' || cle.Password__c == 'sunsure') 
            {
                System.debug('I am here');
                upsert ptw;
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'PTW Inserted Successfully'));
                ptw = new Permit_to_Work_Number__c();
            }
            else
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Wrong Password'));
            }
        }
        else
        {
            
            if(cle.Password__c == 'pv' || cle.Password__c == 'sunsure')
            { 
                if(cle.Operation__c != NULL)
                {
                    upsert cle;
                    clelist = [SELECT Name, Password__c, Cleaning_Start_Date__c,
                                Cleaning_End_Date__c,Number_of_Workers__c,
                               Permit_to_Work_Number__c FROM Cleaning_Activity__c where Password__c =: cle.Password__c];
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Cleaning Activity Inserted Successfully'));
                    system.debug(clelist);
                    cle = new Cleaning_Activity__c();
                }
                else
                {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please input the Operation Name'));  
                }
            }
            else
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Wrong Password'));
            }
        }
        
        
        
    }
    
    
    
}

 
I have a VF Page wherein I have a form that the user inputs. The issue is when I click on Save1 only the "Cleaning_Activity__c" should get saved but VF page executes the whole page and because of that the required fields are throwing error in other sections. See the below image.
User-added image

How to separate the two sections such that when I click Save1 the Cleaning activity gets inserted and record gets saved?

VF Code:
<apex:page controller="i2"  sidebar="false" lightningStylesheets="true" >
    
    <script >
    function mysave1(Clicked_Id){
        var id = Clicked_Id.id;
        if(id='1')
        {
            save1();
        }
        else{
            save2();
        }
    }
    </script>

    <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" lang="en">
        <head>
            <meta charset="utf-8" />
            <meta http-equiv="x-ua-compatible" content="ie=edge" />
            <title>SLDS ResponsiveDesign Visualforce Page in Salesforce Mobile</title>
            <meta name="viewport" content="width=device-width, initial-scale=1" />
            
            <!-- Import the Design System style sheet -->
            <apex:slds />
        </head>
        <body>
            
            <!-- REQUIRED SLDS WRAPPER -->
            <div class="slds-scope">
                
                <!-- PRIMARY CONTENT WRAPPER -->
                
                <!-- RESPONSIVE GRID EXAMPLE -->
                
                
                
                <style>
                    .mystyle {
                    
                    color: black;
                    font-size: 18px;
                    font-weight: bold;
                    }
                </style>
                
                <style>
                    body .bPageBlock .pbBody .grey .pbSubheader{
                    background-color:#585858;
                    
                    color:white;
                    font-size:100}
                    }
                    
                    }
                </style>
                
                <apex:form id="theform" >
                    
                    
                    <apex:pageBlock id="thePageBlock" >
                        <div class = "mystyle">
                            Maintenance Activities
                        </div>

                        <apex:pageMessages id="showmsg"></apex:pageMessages>
                        
                        <apex:pageBlockSection columns="1" >
                            <apex:outputPanel styleClass="grey" layout="block">
                                <apex:pageBlockSection columns="2" title="Cleaning Activity" id="section1" collapsible="false">
                                    <apex:inputField value="{!cle.Operation__c}"/>
                                    <apex:inputField value="{!cle.Cleaning_Company__c}"/>
                                    <apex:inputField value="{!cle.Cleaning_Start_Date__c}"/>
                                    <apex:inputField value="{!cle.Cleaning_End_Date__c}"/>
                                    <apex:inputField value="{!cle.Date_of_Cleaning__c}"/>
                                    <apex:inputField value="{!cle.Full_Site_Cleaning__c}"/>
                                    <apex:inputField value="{!cle.Qualtiy_of_Cleaning__c}"/>
                                    <apex:inputField value="{!cle.Specific_Size_Cleaned_kWp__c}"/>
                                    <apex:inputField value="{!cle.Status__c}"/>
                                    <apex:inputField value="{!cle.URL_of_Photos_folder__c}"/>
                                    <apex:inputField value="{!cle.Password__c}"/>
                                </apex:pageBlockSection> 
                            </apex:outputPanel>
                            
                            
                            <apex:actionFunction name="save1" action="{!save1}"  />
                            <input type = "button" id="1" value="Save1" onclick = "mysave1(this.id)"  />   
                     
                            <apex:outputPanel styleClass="grey" layout="block">
                                <apex:pageBlockSection columns="1" title="Permit to Work Number"  collapsible="false">
                                    <apex:inputField value="{!ptw.PTW_Number__c}"/>
                                    <apex:inputField value="{!ptw.Number_of_Workers__c}"/>
                                    <apex:inputField value="{!ptw.Date__c}"/>
                                    <apex:inputField value="{!ptw.Maintenance_Ticket__c}"/>
                                </apex:pageBlockSection> 
                            </apex:outputPanel>
                            
                            <apex:actionFunction name="save2" action="{!save2}"  />
                            <input type = "button"  id ="2" value="Save2" onclick = "mysave1(this.id)" />        
                           
                        </apex:pageBlockSection>
     
                        <apex:outputPanel styleClass="grey" layout="block">
                            <apex:pageBlockTable value="{!clelist}" var="a">
                                <apex:column headerValue="Cleaning Ticket Number">
                                    <apex:outputLink value="https://c.ap2.visual.force.com/apex/Record_detail_Vf_Page?id = {a.Cleaning_Activity__c}">{!a.Name}</apex:outputLink>
                                </apex:column>
                                <apex:column value="{!a.Password__c}"/>
                                
                                
                            </apex:pageBlockTable> 
                        </apex:outputPanel>
                    </apex:pageBlock>
                    
                </apex:form>
                <!-- / RESPONSIVE GRID EXAMPLE -->
            </div>
        </body>
    </html>
</apex:page>

Class:
public class i2{
    public Cleaning_Activity__c cle{get;set;}
    public Permit_to_Work_Number__c ptw{get;set;}
    public List<Cleaning_Activity__c> clelist{get;set;}
    
    //constructor to create a new record
    public i2(){
        cle = new Cleaning_Activity__c();
        ptw = new Permit_to_Work_Number__c();  
    }
    
    public void save1(){  
        if(cle.Password__c == 'pv' || cle.Password__c == 'sunsure')
        {
            
            insert cle;
            clelist = [SELECT Name, Password__c FROM Cleaning_Activity__c where Password__c =: cle.Password__c];
            
            /*if(cle.Id != null)
            {
                ptw.Cleaning_Activity__c = cle.Id;
            }
            if(ptw.PTW_Number__c!=null)
            {
                insert ptw;
            }*/
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Record Inserted Successfully'));
            cle = new Cleaning_Activity__c();
            
        }
        else
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Password is incorrect'));    
    }
    
    
    public void save2(){  
        if(cle.Password__c == 'pv' || cle.Password__c == 'sunsure')
     {
            
            if(ptw.PTW_Number__c!=null)
            {
                insert ptw;
            }
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Record Inserted Successfully'));
            ptw = new Permit_to_Work_Number__c(); 
       }
        else
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Password is incorrect'));
        
        
        
        
    }
}

​​​​​​​
How to change the font color, size and weight (bold) of a page block title?
Below is my code:
<apex:page controller="i2" tabStyle="Invoice__c">
    
    <style>
        body .bPageBlock .pbBody .grey .pbSubheader{
        background-color:#585858;
        font-family:courier;
        color:white;
        font-size:100}
        }
       
}
        
        
    </style>
    
    <apex:form>
        
        
        <apex:pageBlock title="Invoice">
            
        
            
            
            
            <apex:pageMessages id="showmsg"></apex:pageMessages>
            <apex:pageblockButtons location="Bottom" >
                <apex:commandButton action="{!save}" value="save" >
                </apex:commandButton>
            </apex:pageblockButtons>
            
            
            
            <apex:outputPanel styleClass="grey" layout="block">
                <apex:pageBlockSection columns="1" title="Invoice Details" id="section1"  >
                    <apex:inputField value="{!acc.Name}"/>
                    <apex:inputField value="{!acc.Total_Amount__c}"/>
                    <apex:inputField value="{!acc.Password__c}"/>
                </apex:pageBlockSection> 
            </apex:outputPanel>
            
            
            <apex:outputPanel styleClass="grey" layout="block">
                <apex:pageBlockSection columns="1" title="Invoice Line Items Details" >
                    <apex:inputField value="{!abb.Name}"/>
                    <apex:inputField value="{!abb.Price__c}"/>
                    <apex:inputField value="{!abb.Invoice__c}"/>
                </apex:pageBlockSection> 
            </apex:outputPanel>
            
           
        </apex:pageBlock>
       
    </apex:form>
    
</apex:page>

 
I have created a VF page using a custom controller and I wanted to change background colour of the pageblocksection as it defaults to blue. The issue is it changes in the preview but when I add it to sites it defaults to blue.

Preview:
User-added image
Using Sites:

User-added image
<apex:page controller="i2" >
    <style>
.bPageBlock {
border-top: 0px;
}
</style>
    <apex:form>
        <apex:pageBlock title="Invoice" mode="maindetail">
            
            
            <apex:pageMessages id="showmsg"></apex:pageMessages>
            <apex:pageblockButtons location="Bottom" >
                <apex:commandButton action="{!save}" value="save" >
                </apex:commandButton>
            </apex:pageblockButtons>
            
            
            <apex:pageBlockSection columns="1" title="Invoice Details">
                <apex:inputField value="{!acc.Name}"/>
                <apex:inputField value="{!acc.Total_Amount__c}"/>
                <apex:inputField value="{!acc.Password__c}"/>
             	
   
            	</apex:pageBlockSection> 
            
            
            <apex:pageBlockSection columns="1" title="Invoice Line Items Details">
                <apex:inputField value="{!abb.Name}"/>
                <apex:inputField value="{!abb.Price__c}"/>
                <apex:inputField value="{!abb.Invoice__c}"/>
            </apex:pageBlockSection> 
            
        </apex:pageBlock>
    </apex:form>
    
    
    
</apex:page>

 
I am trying to learn Apex and a newbie at this. I am trying to do the following trailhead:

https://trailhead.salesforce.com/trails/force_com_dev_beginner/modules/apex_triggers/units/apex_triggers_intro

In the example, they provide the following code:
// Get the related opportunities for the accounts in this trigger
Map<Id,Account> acctsWithOpps = new Map<Id,Account>( [SELECT Id,(SELECT Id FROM Opportunities) FROM Account WHERE Id IN :Trigger.New]);

I don't understand why map is declared of type Account but then the subquery (SELECT Id FROM Opportunities) returns IDs of type opportunities?

Second question:
System.debug('acctsWithOpps.get(a.Id).Opportunities.size()=' + acctsWithOpps.get(a.Id).Opportunities.size());


Since opportunities is a child object to account, why do we use get(a.id).opportunities because I thought the dot notation was to traverse from child to parent?
My visualforce site was working fine without any issues but now I am getting an error when I try to open the site. Can you check the below code? Previously the site was working fine.

VF Code:
<apex:page controller="i2"  sidebar="false" lightningStylesheets="true"  > 
    
    
    <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" lang="en">
        <head>
            <meta charset="utf-8" />
            <meta http-equiv="x-ua-compatible" content="ie=edge" />
            <title>SLDS ResponsiveDesign Visualforce Page in Salesforce Mobile</title>
            <meta name="viewport" content="width=device-width, initial-scale=1" />
            <apex:slds />
        </head>
        <body>
            
            <div class="slds-scope">
                
                <style>
                    .mystyle {
                    
                    color: black;
                    font-size: 18px;
                    font-weight: bold;
                    }
                    body .bPageBlock .pbBody .red .pbSubheader{
                    background-color:#585858;
                    
                    }
                    body .bPageBlock .pbBody .grey .pbSubheader{
                    background-color:#585858;
                    
                    }
                    body .bPageBlock .pbBody .grey .pbSubheader h3{
                    color:#FFFFFF;
                    
                    }
                    
                    .grey
                    {
                    background-color:white;
                    }
                    
                  
                    
                </style>
                
                
                <apex:form id="theform" >
                    
                    <apex:pageBlock id="section1"  >
                        
                        <apex:outputPanel id="errmsg">
                            <apex:pageMessages />
                        </apex:outputPanel>
                        
                        
                        
                        
                        <div class = "mystyle">
                            Cleaning Activities
                        </div>
                        
                        
                        <apex:outputPanel styleClass="grey" layout="block">
                            <apex:pageBlockSection title="Login" collapsible="false"> 
                                <apex:inputField value="{!cle.Password__c}"/>
                            </apex:pageBlockSection>
                        </apex:outputPanel>
                        
                        
                        
                        
                        <div align = "center">
                            <apex:commandButton styleClass="slds-button slds-button--brand" value="Retrieve Cleaning Activities" action="{!retrieve}"  /> 
                        </div>
                        
                        
                        <apex:outputPanel id="CleaningSection" styleClass="grey" layout="block">
                            <apex:pageBlockSection columns="2" title="Cleaning Activity" id="section1" collapsible="false">
                                <apex:inputField value="{!cle.Operation__c}" required="false"/>
                                <apex:inputField value="{!cle.Cleaning_Company__c}"/>
                                <apex:inputField value="{!cle.PTW_Number__c}"/> 
                                <apex:inputField value="{!cle.Cleaning_Start_Date__c}"/>
                                <apex:inputField value="{!cle.Cleaning_End_Date__c}"/>
                                <apex:inputField value="{!cle.Full_Site_Cleaning__c}"/>
                                <apex:inputField value="{!cle.Specific_Size_Cleaned_kWp__c}"/> 
                                <apex:inputField value="{!cle.Status__c}"/>
                                <apex:inputField value="{!cle.URL_of_Photos_folder__c}"/>  
                            </apex:pageBlockSection> 
                        </apex:outputPanel>
                        
                        
                        <div align="center">
                            <apex:commandButton styleClass="slds-button slds-button--brand" value="Save Cleaning Activity" action="{!save1}"  >
                                <apex:param name="buttonId1" value="button1" assignTo="{!paramValue}"/>
                            </apex:commandButton>
                        </div>
                        
                        
                    </apex:pageBlock>
                    
                    <apex:pageBlock id="section2">
                        
                        <apex:outputPanel styleClass="grey" layout="block">
                            <apex:pageBlockSection columns="2" title="Permit to Work Number"  collapsible="false">
                                <apex:inputField value="{!ptw.PTW_Number1__c}" required="false" />
                                <apex:inputField value="{!ptw.Number_of_Workers__c}"/>
                                <apex:inputField value="{!ptw.Date__c}"/>
                                <apex:inputField value="{!ptw.Cleaning_Activity__c}" />
                            </apex:pageBlockSection> 
                        </apex:outputPanel>
                        
                        <div align="center">
                            <apex:commandButton styleClass="slds-button slds-button--brand" value="Save Permit to Work Number" action="{!save1}" reRender="errmsg">
                                
                                <apex:param name="buttonId2" value="button2" assignTo="{!paramValue}"/>
                            </apex:commandButton>
                            
                            <apex:commandButton styleClass="slds-button slds-button--brand" value="Reset PTW" action="{!refresh}" />
                            
                        </div>
                        
                    </apex:pageBlock>
                    
                    
                    <apex:pageBlock > 
                        <apex:pageBlockSection >
                            
                            <apex:pageBlockTable value="{!clelist}" var="a" id="tableBlock" style="width:130%" >
                                <apex:column headerValue="Ticket Number">
                                    <apex:outputLink value="https://c.ap2.visual.force.com/apex/Record_detail_Vf_Page?id = {a.Cleaning_Activity__c}">{!a.Name}</apex:outputLink>
                                </apex:column>
                                <apex:column headerValue="Contractor" value="{!a.Password__c}"/>
                                <apex:column headerValue="Number of Workers" value="{!a.Number_of_Workers__c}"/>
                                <apex:column headerValue="Start Date" value="{!a.Cleaning_Start_Date__c}"/>
                                <apex:column headerValue="End Date" value="{!a.Cleaning_End_Date__c}"/>
                                <apex:column headerValue="PTW Number" value="{!a.Permit_to_Work_Number__c}"/>
                            </apex:pageBlockTable> 
                            
                        </apex:pageBlockSection>
                    </apex:pageBlock> 
                    
                    
                    
                </apex:form>   
                
            </div>
        </body>
    </html>
   
</apex:page>
Controller:
public class i2{
    public Cleaning_Activity__c cle{get;set;}
    public Permit_to_Work_Number__c ptw{get;set;}
    public List<Cleaning_Activity__c> clelist{get;set;}
    public String paramValue{get;set;}
    
    
    //constructor to create a new record
    public i2(){
        cle = new Cleaning_Activity__c();
        ptw = new Permit_to_Work_Number__c();  
        
    }

    public void refresh(){
        ptw = new Permit_to_Work_Number__c(); 
    }
    
    //Assigning password to Cleaning Company
    /* public void assignPassword(){
          system.debug(cle.Password__c);
         if(cle.Password__c != null){
       cle.Cleaning_Company__c = cle.Password__c;
         }}*/
    
    public void retrieve()
    {
        if(cle.Password__c == 'pv' || cle.Password__c == 'sunsure')
        {
            clelist = [SELECT Name, Password__c, Cleaning_Company__c, Number_of_Workers__c, Cleaning_Start_Date__c, 
					Cleaning_End_Date__c, Permit_to_Work_Number__c,PTW_Number__c FROM Cleaning_Activity__c where Password__c =: cle.Password__c];
            system.debug(clelist);   
        }
        else if(cle.Password__c == NULL)
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please key in the password to retreive the details'));
        else
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Password is incorrect'));
    }
    
    
    
    public void save1(){  
        system.debug('paramValue ' + paramValue);
        if(paramValue == 'button2')
        {
            system.debug('Password is ' + cle.Password__c);
            if(cle.Password__c == 'pv' || cle.Password__c == 'sunsure') 
            {
                System.debug('I am here');
                upsert ptw;
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'PTW Inserted Successfully'));
                ptw = new Permit_to_Work_Number__c();
            }
            else
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Wrong Password'));
            }
        }
        else
        {
            
            if(cle.Password__c == 'pv' || cle.Password__c == 'sunsure')
            { 
                if(cle.Operation__c != NULL)
                {
                    upsert cle;
                    clelist = [SELECT Name, Password__c, Cleaning_Start_Date__c,
                                Cleaning_End_Date__c,Number_of_Workers__c,
                               Permit_to_Work_Number__c FROM Cleaning_Activity__c where Password__c =: cle.Password__c];
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Cleaning Activity Inserted Successfully'));
                    system.debug(clelist);
                    cle = new Cleaning_Activity__c();
                }
                else
                {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please input the Operation Name'));  
                }
            }
            else
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Wrong Password'));
            }
        }
        
        
        
    }
    
    
    
}

 
I have created a VF page using a custom controller and I wanted to change background colour of the pageblocksection as it defaults to blue. The issue is it changes in the preview but when I add it to sites it defaults to blue.

Preview:
User-added image
Using Sites:

User-added image
<apex:page controller="i2" >
    <style>
.bPageBlock {
border-top: 0px;
}
</style>
    <apex:form>
        <apex:pageBlock title="Invoice" mode="maindetail">
            
            
            <apex:pageMessages id="showmsg"></apex:pageMessages>
            <apex:pageblockButtons location="Bottom" >
                <apex:commandButton action="{!save}" value="save" >
                </apex:commandButton>
            </apex:pageblockButtons>
            
            
            <apex:pageBlockSection columns="1" title="Invoice Details">
                <apex:inputField value="{!acc.Name}"/>
                <apex:inputField value="{!acc.Total_Amount__c}"/>
                <apex:inputField value="{!acc.Password__c}"/>
             	
   
            	</apex:pageBlockSection> 
            
            
            <apex:pageBlockSection columns="1" title="Invoice Line Items Details">
                <apex:inputField value="{!abb.Name}"/>
                <apex:inputField value="{!abb.Price__c}"/>
                <apex:inputField value="{!abb.Invoice__c}"/>
            </apex:pageBlockSection> 
            
        </apex:pageBlock>
    </apex:form>
    
    
    
</apex:page>