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
Ekta Gupta 23Ekta Gupta 23 

Need help with Vf page

I need to expose a visualforce page on a custom object( Support Request) when SLA is breached for that support Request.
When Today date>= SLA Due Details, visualforce component on the Support Request page should show below message
"SLA Breached, please treat this on priority"

I have created below VF page and trying to expose on the page layout:

<apex:page standardController="Support_Request__c"> if (SLA_Details__c == null) { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'SLA Breached')); return null; } </apex:page>

But its not working fine, Kindly suggest
Best Answer chosen by Ekta Gupta 23
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi Ekta,
You have to use standard controller and also extension in vf page for this scenario.
try this code
<apex:page standardController="support_request__c" extensions="slaCheckcontroller">
          <apex:pageMessages id="showmsg"></apex:pageMessages>

</apex:page>

controller
public class slaCheckcontroller {
    public boolean slaBreach{get;set;}
    
 	public slaCheckcontroller(ApexPages.StandardController controller) {
       id  rcdId  = ApexPages.CurrentPage().getparameters().get('id');
       support_request__c sr = [select id ,sla_details__C  from support_request__c where id =: rcdId ];
            if(system.today()>=sr.sla__C)
            {
                       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'SLA Breached'));
            }
            
    }
}

Hope this helps you
Let me know if this helps you. Kindly mark it as solved so that it may help others in future.

Thanks and Regards

All Answers

Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi Ekta,
You have to use standard controller and also extension in vf page for this scenario.
try this code
<apex:page standardController="support_request__c" extensions="slaCheckcontroller">
          <apex:pageMessages id="showmsg"></apex:pageMessages>

</apex:page>

controller
public class slaCheckcontroller {
    public boolean slaBreach{get;set;}
    
 	public slaCheckcontroller(ApexPages.StandardController controller) {
       id  rcdId  = ApexPages.CurrentPage().getparameters().get('id');
       support_request__c sr = [select id ,sla_details__C  from support_request__c where id =: rcdId ];
            if(system.today()>=sr.sla__C)
            {
                       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'SLA Breached'));
            }
            
    }
}

Hope this helps you
Let me know if this helps you. Kindly mark it as solved so that it may help others in future.

Thanks and Regards
This was selected as the best answer
Ekta Gupta 23Ekta Gupta 23
@Chandria: Thanks , I just realized that when I expose this visualforce page on lighting layout, It doesnt work. It is working only in classic. Can you please advise how can I enable it in lightning.
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi ekta,
Please include lightingstylesheets  attribute in your apex:page tag
<apex:page lightningStylesheets="true" standardController="case" extensions="slaCheckcontroller">

I think page message wont work in lightning experience.You have to write some custom code.
Please refer below link which might help you in this
https://salesforce.stackexchange.com/questions/149797/how-to-convert-a-visualforce-apexpagemessages-to-be-lightning-style

Hope this helps you!
Ekta Gupta 23Ekta Gupta 23
Hi Chandrika, Can you please help me with the code, sorry I am quite new into coding so need help.