• Kumar__Mayank
  • NEWBIE
  • 15 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 8
    Replies
Hi All..

I am new to development So I need help. i have one requirement where I have to select record type for Acoount from drop down and based on record type it should return accounts created under same record type in table without refreshing complete page. Morever I should have pagination for those returned account records.

Visualforce Page:

<apex:page controller="RecordTypeAccounts" title="Find the Accounts of corresponding record type" sidebar="False">

    <apex:form >

          <apex:pageBlock >

            <apex:pageBlockSection id="selectedRecordType" columns="1">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Choose Record Type for Account" for="rt" />         
                    <apex:panelGrid columns="2">
                    <apex:selectList value="{!RecordType}" multiselect="false"  size="1">
                        <apex:selectOptions value="{!rectypes}"/>
                        <apex:actionSupport event="onchange" action="{!getAccList}" reRender="Account_list"/>
                    </apex:selectList>              
                    </apex:panelGrid>       
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection> 
        <apex:pageBlockTable value="{!AccList}" var="item" id="Account_list">

            <apex:column value="{!item.name}"/>
            
            <apex:column value="{!item.rating}"/>
            
            <apex:column value="{!item.phone}"/>
            
            <apex:column >
                <apex:commandLink value="Click here" action="{!detailPage}">
                    <apex:param name="abc" value="{!item.id}" />
                </apex:commandLink>                              
            </apex:column>
            
                   <apex:panelGrid columns="8" id="PanelId">

         <apex:commandLink action="{!AccPagination.previous}" rerender="Account_list">

                <apex:outputLabel value="<<Previous" style="font-weight: bold;"/>

                </apex:commandlink>

                <apex:commandLink action="{!AccPagination.next}" rerender="Account_list">

                     <apex:outputLabel value="Next>>" style="font-weight: bold;"/>

                  </apex:commandlink>

          </apex:panelGrid> 

        </apex:pageBlockTable>
        

    </apex:pageBlock>
                     
            
    </apex:form>


</apex:page>

Controller :

public class RecordTypeAccounts {

    public string showaccid { get; set; }

    String recType;    
    
    public List<Account> AccList {get;set;}
    
    public List<SelectOption> getrectypes() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('','--Select Record Type --'));
        for(RecordType rt:[select id,name from RecordType where sobjecttype='Account']){
            options.add(new SelectOption(rt.id,rt.name));    
    }
        return options;
    }
    
    public String getRecordType() {
        return recType;
    }
    
    public void setRecordType(String recType) {
        this.recType= recType;
    }
  
public ApexPages.StandardSetController AccPagination
{        
        get{            
            if(AccPagination== null)
            {          
                AccPagination= new ApexPages.StandardSetController(Database.getQueryLocator([select name,rating,phone from account where recordtypeid =: recType]));            
            }           
        return AccPagination;        
            }        
        set;    
}    

   Public List<Account> getAcclist()
    {
     AccPagination.setPageSize(5);
     return (List<Account>) AccPagination.getRecords();
    
    }
   
 public PageReference detailPage() {
   
        showaccid  = System.currentPageReference().getParameters().get('abc');
        PageReference nextPage = new PageReference('/' + showaccid);
        nextPage.setRedirect(true);
        return nextPage;
}
}

 
integer i=0;
integer num=0;

while( i <= 100)

    //system.debug('here' + i);
    integer counter=0;
    for (num = i ;num >= 1; num--)
    {
        if(math.mod(i,num)==0)
        {
            counter=counter+1;
        }
    }
    if (counter == 2)
    {
        system.debug(i);
    }
   i++;     
}

Above code I am running in anonymous window to get prime numbers between 1 to 100. But when I go for Debug Only it shows like this:
User-added image

Any body can tell me how to get complete prime numbers here?
 
Hi All..

I am new to development So I need help. i have one requirement where I have to select record type for Acoount from drop down and based on record type it should return accounts created under same record type in table without refreshing complete page. Morever I should have pagination for those returned account records.

Visualforce Page:

<apex:page controller="RecordTypeAccounts" title="Find the Accounts of corresponding record type" sidebar="False">

    <apex:form >

          <apex:pageBlock >

            <apex:pageBlockSection id="selectedRecordType" columns="1">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Choose Record Type for Account" for="rt" />         
                    <apex:panelGrid columns="2">
                    <apex:selectList value="{!RecordType}" multiselect="false"  size="1">
                        <apex:selectOptions value="{!rectypes}"/>
                        <apex:actionSupport event="onchange" action="{!getAccList}" reRender="Account_list"/>
                    </apex:selectList>              
                    </apex:panelGrid>       
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection> 
        <apex:pageBlockTable value="{!AccList}" var="item" id="Account_list">

            <apex:column value="{!item.name}"/>
            
            <apex:column value="{!item.rating}"/>
            
            <apex:column value="{!item.phone}"/>
            
            <apex:column >
                <apex:commandLink value="Click here" action="{!detailPage}">
                    <apex:param name="abc" value="{!item.id}" />
                </apex:commandLink>                              
            </apex:column>
            
                   <apex:panelGrid columns="8" id="PanelId">

         <apex:commandLink action="{!AccPagination.previous}" rerender="Account_list">

                <apex:outputLabel value="<<Previous" style="font-weight: bold;"/>

                </apex:commandlink>

                <apex:commandLink action="{!AccPagination.next}" rerender="Account_list">

                     <apex:outputLabel value="Next>>" style="font-weight: bold;"/>

                  </apex:commandlink>

          </apex:panelGrid> 

        </apex:pageBlockTable>
        

    </apex:pageBlock>
                     
            
    </apex:form>


</apex:page>

Controller :

public class RecordTypeAccounts {

    public string showaccid { get; set; }

    String recType;    
    
    public List<Account> AccList {get;set;}
    
    public List<SelectOption> getrectypes() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('','--Select Record Type --'));
        for(RecordType rt:[select id,name from RecordType where sobjecttype='Account']){
            options.add(new SelectOption(rt.id,rt.name));    
    }
        return options;
    }
    
    public String getRecordType() {
        return recType;
    }
    
    public void setRecordType(String recType) {
        this.recType= recType;
    }
  
public ApexPages.StandardSetController AccPagination
{        
        get{            
            if(AccPagination== null)
            {          
                AccPagination= new ApexPages.StandardSetController(Database.getQueryLocator([select name,rating,phone from account where recordtypeid =: recType]));            
            }           
        return AccPagination;        
            }        
        set;    
}    

   Public List<Account> getAcclist()
    {
     AccPagination.setPageSize(5);
     return (List<Account>) AccPagination.getRecords();
    
    }
   
 public PageReference detailPage() {
   
        showaccid  = System.currentPageReference().getParameters().get('abc');
        PageReference nextPage = new PageReference('/' + showaccid);
        nextPage.setRedirect(true);
        return nextPage;
}
}

 
integer i=0;
integer num=0;

while( i <= 100)

    //system.debug('here' + i);
    integer counter=0;
    for (num = i ;num >= 1; num--)
    {
        if(math.mod(i,num)==0)
        {
            counter=counter+1;
        }
    }
    if (counter == 2)
    {
        system.debug(i);
    }
   i++;     
}

Above code I am running in anonymous window to get prime numbers between 1 to 100. But when I go for Debug Only it shows like this:
User-added image

Any body can tell me how to get complete prime numbers here?
 
Trailhead Module 3:  Create a formula field that determines the number of days between today and the last activity date for a case's account.
Your support team has asked for improved visibility on account activity level at the time they’re helping with customer issues. Specifically, when they’re looking at a case, they’d like to see an at-a-glance view of the number of days since the case’s related account was last active. Create the formula using these requirements.The formula should be on the Case object.
The formula should be of return type Number.
The formula should be named 'Days Since Last Update' and have a resulting API Name of 'Days_Since_Last_Update__c'.
The formula should return the number of days between the account’s Last Activity Date and today.

I created the following:

I created a new custom formula field with return type number and called Days Since Last Update.
I created this formula: Account.LastActivityDate - TODAY()

I get this error message:

Challenge not yet complete... here's what's wrong: 
The 'Days_Since_Last_Update__c' formula field did not return the correct number of days between an Account’s Last Activity Date and today

Can you please assist what I did wrong?  I'm not sure if my formula is even correct with the challenge.  Please help!

Thank you.