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
Venkata Sumedha singanamalaVenkata Sumedha singanamala 

Displaying custome Confirm Messages

Firstly apologise for a lengthy querie
I have a small query ever I have a piece of code which will display the records of a user which are existing in Account and Emp. And I have a written a method “m1” which would diplay the “Confirm” messgae with the count of records available if not a message”No Customers found”.
My question is I have one record present in Account tab but not in Emp tab and when I click the search button I want the browser to be displayed with the Acount records and there should be a message
“No records found ” in EMP tab how can I do it ??
For the reference here I am attaching the code.

Visual Force program:
<apex:page controller="APtest9">
    <apex:form>
    <apex:pageBlock title="User Records">
        <apex:pageBlockSection title="Search Section">
        <apex:outputLabel value="Enter the User name"></apex:outputLabel>
        <apex:inputText value="{!Na}"/>
            <apex:commandButton value="Search" action="{!m1}" />
            <apex:pageMessages></apex:pageMessages>
            <apex:pageBlockSection title="Account Records">
                <apex:pageBlockTable value="{!arecs}" var="items">
                    <apex:column value="{!items.id}"/>
                    <apex:column value="{!items.name}"/>
                    <apex:column value="{!items.billingcity}"/>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlockSection>
       
        <apex:pageBlockSection title="Employee Records">
        <apex:pageBlockTable value="{!erecs}" var="items">
            <apex:column value="{!items.name}"/>
            <apex:column value="{!items.ID_no__c}"/>
            <apex:column value="{!items.Client__c}"/>
            <apex:column value="{!items.Basic_Salary__c}"/>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Apex class:
public class Aptest9 {
    public string Na{set;get;}
    public list<account> arecs{set;get;}
    public list<EMP__c> erecs{set;get;}
   
    public void m1(){
       
        arecs=[select id,name,billingcity from account where name=:Na];
        erecs=[select name,ID_no__c,Client__c,Basic_Salary__c from EMP__c where name=:Na];
     integer cnt=[select count() from account where name=:Na];          
        if(cnt>0)
        {
            apexpages.addMessage(new apexpages.Message(apexpages.Severity.CONFIRM,cnt+ 'Record Found'));
        }else{
            apexpages.addMessage(new apexpages.Message(apexpages.Severity.CONFIRM,+ 'No Record Found'));
        }
    }
}
Vatsal KothariVatsal Kothari
Hi Venkata,

You can try this:-

<apex:pageBlockSection title="Employee Records" rendered="{!erecs != null}">
    <apex:pageBlockTable value="{!erecs}" var="items">
            <apex:column value="{!items.name}"/>
            <apex:column value="{!items.ID_no__c}"/>
            <apex:column value="{!items.Client__c}"/>
            <apex:column value="{!items.Basic_Salary__c}"/>
     </apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockSection title="Employee Records" rendered="{!erecs == null}">
No Records found
</apex:pageBlockSection>
Thanks,
Vatsal

Venkata Sumedha singanamalaVenkata Sumedha singanamala
Hi Vatsal,

Thanks for the help I have tried your code it is showin the below message what i exactly want is which ever block either the Account block or the Emp block doesnt have the respective persons record that specific block should show up the message as No records found will this be possible using apex code?

Please find the image for your reference.

thank you once again...

Regards,
Seshagiri

User-added image
Vatsal KothariVatsal Kothari
This Message is displaying because there is no records of account, so it is displaying apexpages.addMessage.
you can try this:

<apex:page controller="APtest9">
    <apex:form>
    <apex:pageBlock title="User Records">
        <apex:pageBlockSection title="Search Section">
        <apex:outputLabel value="Enter the User name"></apex:outputLabel>
        <apex:inputText value="{!Na}"/>
            <apex:commandButton value="Search" action="{!m1}" />
            <apex:pageMessages></apex:pageMessages>
            <apex:pageBlockSection title="Account Records ({!accCount})" rendered="{!arecs != null}">
                <apex:pageBlockTable value="{!arecs}" var="items">
                    <apex:column value="{!items.id}"/>
                    <apex:column value="{!items.name}"/>
                    <apex:column value="{!items.billingcity}"/>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
			<apex:pageBlockSection title="Employee Records" rendered="{!erecs == null}">
				No Records found for Account
			</apex:pageBlockSection>
        </apex:pageBlockSection>
       
        <apex:pageBlockSection title="Employee Records ({!empCount})" rendered="{!erecs != null}">
			<apex:pageBlockTable value="{!erecs}" var="items">
					<apex:column value="{!items.name}"/>
					<apex:column value="{!items.ID_no__c}"/>
					<apex:column value="{!items.Client__c}"/>
					<apex:column value="{!items.Basic_Salary__c}"/>
			 </apex:pageBlockTable>
		</apex:pageBlockSection>
		<apex:pageBlockSection title="Employee Records" rendered="{!erecs == null}">
			No Records found for Employee
		</apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex class:
public class Aptest9 {
    public string Na{set;get;}
    public list<account> arecs{set;get;}
    public list<EMP__c> erecs{set;get;}
	public integer accCount{get;set;}
	public integer empCount{get;set;}
   
    public void m1(){
       
        arecs=[select id,name,billingcity from account where name=:Na];
        erecs=[select name,ID_no__c,Client__c,Basic_Salary__c from EMP__c where name=:Na];
        accCount=[select count() from account where name=:Na];
		empCount=[select count() from EMP__c where name=:Na];        
    }
}

If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal
Venkata Sumedha singanamalaVenkata Sumedha singanamala
Thanks for the code vatsal. Could you please explain me how to use the code "Rendered" and which are the best places to use. Regards, Seshagiri
Vatsal KothariVatsal Kothari
Rendered is the attribute which returns a Boolean value that specifies whether the to rendered or not. If not specified, this value defaults to true.
Here in our condition:
   rendered="{!erecs != null}"
It will return true if erecs contains something or else it will return false and pageBlocksection will not display.

kindly mark it as the best answer if this helps you..:)

Thanks,
Vatsal
Venkata Sumedha singanamalaVenkata Sumedha singanamala
very well explained thank you vatsal... :)