• Deekshant Sharma
  • NEWBIE
  • 25 Points
  • Member since 2019

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 1
    Questions
  • 1
    Replies
I have a json array as follows in lightning component controller.

  var providerObj = [];
      providerObj=[{
                            "specialties": [
                                 {
                                      "type": "specialty",
                                      "name": "Cardiology",
                                      "id": "839"
                                 },
                                    {                            
                                      "type": "specialty",
                                        "name": "Pediatric Cardiology",
                                     "id": "824"
                                    },
                                  
                                 {
                                      "type": "specialty",
                                       "name": "Pediatric Cardiothoracic Surgery",
                                      "id": "707"
                                  }
                          ],
                               "procedures": [
                                                {
                                                  "type": "procedure",
                                                 "name": "Established Patient Office Visit (Interventional Cardiology)",
                                                 "id": "1735"
                                                },
                                             {
                                                 "type": "procedure",
                                                 "name": "Established Patient Office Visit (Pediatric Cardiology)",
                                                  "id": "1768"
                                                },
                                             
                                             {
                                                  "type": "procedure",
                                                   "name": "Office Consultation ONLY for new or established patients, no testing (Cardiology)",
                                                   "id": "1499"
                                                }
                                            ],
                                          "providers": [
                                    {
      "type": "facility",
      "name": "Eastern CT Cardiology Diagnostic",
      "id": "0007302322",
      "default_procedure": null
    },
    {
      "type": "facility",
      "name": "NY Comprehensive Cardiology, LLC",
      "id": "0007816766",
      "default_procedure": null
    },
    
   
  ]
        }];
     
        component.set("v.allResults",providerObj);
Here allResults attribute is of the following type
<aura:atttrbute name="allResults" type="Object"/>

I want to get the length of specialities , procedures and providers and also the total number of JSON records.

I am doing like this in controller

var arrayCount = providerObj.length;
var specCount = providerObj.specialities.length;

But whatever I do I am not getting the count of records.

Please help me regarding this

tina
        
Hi, I am trying to maintain the viewstate of my Page after reload. My VF page uses pagination to reduce the data held by the viewstate. I want to stay on the same page number after my page reloads but it wouldn't work and refreshes the page back to page number 1.
Here's my Controller and Page.
  • Controller:
public class CustomPagination2 {
	private Integer currentPage;
    private Integer recPerPage, offsetValue, totalPages, totalRecords;
    private String query, sortHow;
    List<Contact> tempLst;
    public String sortByWhat {get; set;}
    public List<Integer> itrInt {get; set;}
    public List<Contact> retList {
        get{
            return Database.query(query) ;
        }
        set;}
    public Integer pageFromVf{get; set;}
    
    public CustomPagination2(){
        sortByWhat = 'FirstName';
        sortHow = 'asc';
        query = 'SELECT FirstName, LastName FROM Contact order by '+sortByWhat+' '+sortHow+' LIMIT :recPerPage OFFSET :offsetValue';
        if(currentPage == null) currentPage = 1;
        recPerPage = 7;
        offsetValue = (currentPage - 1) * recPerPage;
        totalPages = 0;
        totalRecords = 0;
        itrInt = new List<Integer>();
        for(Contact con : [SELECT FirstName, LastName FROM Contact]){
            if(math.mod(totalRecords, recPerPage) == 0){
                itrInt.add(totalPages+1);
                totalPages++;
            }
            totalRecords++;
        }
    }
    
    public void changeOrder(){
        tempLst = retList;
        if(sortHow=='asc') sortHow='desc';
        else sortHow = 'asc';
        query = 'SELECT FirstName, LastName FROM Contact WHERE id IN :tempLst order by '+sortByWhat+' '+sortHow;
    }
    
    public void changeOrder2(){
        if(sortHow=='asc') sortHow='desc';
        else sortHow = 'asc';
        query = 'SELECT FirstName, LastName FROM Contact order by '+sortByWhat+' '+sortHow+' LIMIT :recPerPage OFFSET :offsetValue'; 
    }
    
    public void next(){
        if(currentPage!=totalPages){
            currentPage++;
            setQuery();
        }
        else{
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'No page after this one!'));
        }
    }
    
    public void last(){
        currentPage = totalPages;
        setQuery();
    }
    
    public void previous(){
        if(currentPage!=1){
        	currentPage--;
            setQuery();
        }
        else{
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR,'No page before this!'));
        }
    }
    
    public void first(){
        currentPage = 1;
        
        setQuery();
    }
    
    public Integer getPageno(){
        return currentPage;
    }
    
    public String getRecords(){
        String str = 'Showing records '+(offsetValue+1)+'-';
        if(offsetValue+recPerPage <= totalRecords) str+= (offsetValue+recPerPage)+' out of '+totalRecords;
        else str += totalRecords+' out of '+totalRecords;
        return str;
    }
    
    public void goByPageNo(){
        if(pageFromVf>0 && pageFromVf<=totalPages){
            currentPage = pageFromVf;
            setQuery();
        }
        else{
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR,'This page does not exist!'));
        }
    }
    
    public void setQuery(){
        sortHow = 'asc';
        sortByWhat = 'FirstName';
        offsetValue = (currentPage - 1) * recPerPage;
        query = 'SELECT FirstName, LastName FROM Contact order by '+sortByWhat+' '+sortHow+' LIMIT :recPerPage OFFSET :offsetValue';
    }
}
  • VF Page
<apex:page controller="CustomPagination2">
	<apex:pageBlock >
        <apex:pageMessages id="msg"></apex:pageMessages>
        <apex:outputPanel id="pageNo">
            <div style="font-size:20px; font-weight:bold;">{!pageno}</div> 
            <apex:outputPanel id="records"><p style="text-align:center">{!records}</p></apex:outputPanel>
        </apex:outputPanel><br/><br/>
        <apex:pageBlockSection id="conTable">
                <tr>
                	<th><a href="javascript:void(0)" onclick="changeOrderAF('FirstName')">First Name</a></th>
                    <th><a href="javascript:void(0)" onclick="changeOrderAF('LastName')">Last Name</a></th>
                </tr>
                <apex:repeat value="{!retList}" var="conn">
                <tr>
                	<td>{!conn.FirstName}</td>
                    <td>{!conn.LastName}</td>
                </tr>
                </apex:repeat>
        </apex:pageBlockSection><br/><br/>
   
  	  <apex:outputPanel onclick="firstAF()" styleClass="btn">&lt;&lt; First</apex:outputPanel>
        <apex:outputPanel onclick="previousAF()" styleClass="btn">&lt; Previous</apex:outputPanel>
        <apex:outputPanel id="pageLinks">
            <apex:repeat value="{!itrInt}" var="page">
                <apex:outputLink disabled="{!pageno == page}" onclick="gotoAF({!page})" value="javascript:void(0)" > {!page} &nbsp; </apex:outputLink>
            </apex:repeat>
        </apex:outputPanel>
        <apex:outputPanel onclick="nextAF()" styleClass="btn">Next &gt;	</apex:outputPanel>
        <apex:outputPanel onclick="lastAF()" styleClass="btn">Last &gt;&gt;</apex:outputPanel><br/><br/>
        Go to page: <input type="text" id="gotoId"/> <apex:outputPanel onclick="gotoJS()" styleClass="btn">GO!</apex:outputPanel>
    </apex:pageBlock>
    
    <apex:form >
    	<apex:actionFunction action="{!next}" reRender="conTable, msg, pageNo, pageLinks, records" name="nextAF"/>
        <apex:actionFunction action="{!previous}" reRender="conTable, msg, pageNo, pageLinks, records" name="previousAF" />
        <apex:actionFunction action="{!last}" reRender="conTable, pageNo, pageLinks, records, msg" name="lastAF"/>
        <apex:actionFunction action="{!first}" reRender="conTable, pageNo, pageLinks, records, msg" name="firstAF"/>
        <apex:actionFunction action="{!goByPageNo}" reRender="conTable, msg, pageNo, pageLinks, records" name="gotoAF"> 
        	<apex:param value="" assignTo="{!pageFromVf}" name="firstParam"/>
        </apex:actionFunction> 
        <apex:actionFunction name="changeOrderAF" action="{!changeOrder}" reRender="conTable">
        	<apex:param assignTo="{!sortByWhat}" name="firstParam" value=""/>
        </apex:actionFunction>
        <apex:actionFunction name="changeOrderAF2" action="{!changeOrder2}" reRender="conTable">
        	<apex:param assignTo="{!sortByWhat}" name="firstParam" value=""/>
        </apex:actionFunction>
    </apex:form>
    <script>
    	function gotoJS(){
        	gotoAF(document.getElementById("gotoId").value);
        }
    </script>
</apex:page>

 
I have a json array as follows in lightning component controller.

  var providerObj = [];
      providerObj=[{
                            "specialties": [
                                 {
                                      "type": "specialty",
                                      "name": "Cardiology",
                                      "id": "839"
                                 },
                                    {                            
                                      "type": "specialty",
                                        "name": "Pediatric Cardiology",
                                     "id": "824"
                                    },
                                  
                                 {
                                      "type": "specialty",
                                       "name": "Pediatric Cardiothoracic Surgery",
                                      "id": "707"
                                  }
                          ],
                               "procedures": [
                                                {
                                                  "type": "procedure",
                                                 "name": "Established Patient Office Visit (Interventional Cardiology)",
                                                 "id": "1735"
                                                },
                                             {
                                                 "type": "procedure",
                                                 "name": "Established Patient Office Visit (Pediatric Cardiology)",
                                                  "id": "1768"
                                                },
                                             
                                             {
                                                  "type": "procedure",
                                                   "name": "Office Consultation ONLY for new or established patients, no testing (Cardiology)",
                                                   "id": "1499"
                                                }
                                            ],
                                          "providers": [
                                    {
      "type": "facility",
      "name": "Eastern CT Cardiology Diagnostic",
      "id": "0007302322",
      "default_procedure": null
    },
    {
      "type": "facility",
      "name": "NY Comprehensive Cardiology, LLC",
      "id": "0007816766",
      "default_procedure": null
    },
    
   
  ]
        }];
     
        component.set("v.allResults",providerObj);
Here allResults attribute is of the following type
<aura:atttrbute name="allResults" type="Object"/>

I want to get the length of specialities , procedures and providers and also the total number of JSON records.

I am doing like this in controller

var arrayCount = providerObj.length;
var specCount = providerObj.specialities.length;

But whatever I do I am not getting the count of records.

Please help me regarding this

tina
        
Just wanted to share a problem we had that I haven't seen elsewhere.

We built a Flow Definition with the Process Builder and Added it to our Managed Package

Then we decided to Deactivate the Flow before uploading the Package as some orgs that we support may not use it.

When we tried to install our Managed Package, it failed, saying that the Flow had been Deleted.

It clearly had NOT been deleted, so we were stumped.  Salesforce Support couldn't help us and escalated the Case.

I began studying the Setup Audit Trail and noticed strange entries that happened at the same time I Activated and Deactivated the Flow:

When my Flow was "Activated",  the system was creating a 'Flow Trigger" and a "Workflow Rule" behind the scenes with the same name as my flow, though adding a long id number at the end.

The PROBLEM is that when I deactivated the Flow, the system didn't just deactivate the "backend" Workflow Rule, but THEN it DELETED both the 'Flow Trigger' and the "backend" Workflow Rule!  I don't understand why it was actually deleted? THIS deleted hidden Trigger and Workflow is what caused the package install to fail.

On a hunch I decided to Activate the Flow and build a new package again.  Sure enough, the package uploaded and installed perfectly.

Salesforce needs to put some documentation around this, or at least have a warning popup when you try to Deactivate a Flow that is already in a package.

How are we supposed to know that deactivation is deleting components that we didn't even know were there in the first place?

Hope this saves someone else some time.