• George thomas
  • NEWBIE
  • 5 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
Hi All,

I'm trying to utilze the standard set controller setSelectedRecord() function to capture the selected records from the screen while paginating from one page to another. But when i add the records from the 2nd page into the standardsetcontroller variable the records which i have already added to it become lost.

Any idea why its happening so?
 
VF Page:
<apex:page standardController="Account" Extensions="accountCon" >
<apex:form id="form1" >
<apex:pageBlock >
<apex:pagebLockTable value="{!accList}" var="a">
    <apex:column >
        <apex:inputCheckbox value="{!a.selected}" onclick="updateSel()"/>
    </apex:column>
    <apex:column value="{!a.Acc['Name']}"/>
    
    
</apex:pagebLockTable>  

<apex:commandButton action="{!next}" value="Next"/>


<apex:pageBlockTable value="{!selAcc}" var="acc" id="pgblock2">

    <apex:column value="{!acc['Name']}"/>
</apex:pageBlockTable>

<apex:actionFunction name="updateSel" action="{!updateSel}" reRender="pgblock2"/>

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


Controller:

public class accountCon {

public list<Sobject> selAcc{get{
    selAcc = selAcc();
    return selAcc;
}set;}
public list<accountWrapper> accList{get
{
    return accLIst;   
}

set;}
    public accountCon(ApexPages.StandardController controller) {
    selAcc = new List<Sobject>();
    getAccounts();
    }

ApexPages.standardSetController sCon;


public List<accountWrapper> getAccounts()
{
    if(sCon==null)
        sCon = new ApexPages.standardSetController(Database.getQueryLocator([select id,name,type from Account]));
    sCon.setPageSize(5);
    
    if(accLIst == null)
        accLIst = new List<accountWrapper>();
        
    for(sobject s:sCon.getRecords())
    {
        accountWrapper wrp = new accountWrapper();
        wrp.selected = false;
        wrp.acc=s;
        accLIst.add(wrp);
    }
    return accList;
}

public void updateSel()
{
    List<Sobject> s = new List<Sobject>();
    for(accountWrapper awrp :accList )
    {
        if(awrp.selected)
         s.add(awrp.acc);
    }
    system.debug('Before set selected:'+scon.getSelected());
    sCon.setSelected(s);
    system.debug('After set selected:'+scon.getSelected());
}


public list<Sobject> selAcc()
{
    return scon.getSelected();
}
public void next()
{
    accList .clear();
    sCon.Next();
    accList  = getAccounts();
}

class accountWrapper
{
    public Boolean selected{get;set;}
    public Sobject Acc{get;set;}
}
}

 
Hi All,

We have an issue in our instance where we suspect that sharing rule calcualtion for newly inserted records is taking time. The issue here is:

We have data coming from another system and it insert into salesforce, and we have set up some criteria based sharing rule on this object to make it visible to a set of users(its configured by role level). Sometimes the newly inserted data is not visible to set of users where sharing rule makes it visible to them. But after 3-4 hours these records are visible to those users. 

We assume the sharing rule calculation makes this delay and we used to reprocess alomost 80,000 records 

Please somebody suggest a workaround or solution to recover from this issue.
Hi All,

We have an issue in our instance where we suspect that sharing rule calcualtion for newly inserted records is taking time. The issue here is:

We have data coming from another system and it insert into salesforce, and we have set up some criteria based sharing rule on this object to make it visible to a set of users(its configured by role level). Sometimes the newly inserted data is not visible to set of users where sharing rule makes it visible to them. But after 3-4 hours these records are visible to those users. 

We assume the sharing rule calculation makes this delay and we used to reprocess alomost 80,000 records 

Please somebody suggest a workaround or solution to recover from this issue.
Hi All,

I'm trying to utilze the standard set controller setSelectedRecord() function to capture the selected records from the screen while paginating from one page to another. But when i add the records from the 2nd page into the standardsetcontroller variable the records which i have already added to it become lost.

Any idea why its happening so?
 
VF Page:
<apex:page standardController="Account" Extensions="accountCon" >
<apex:form id="form1" >
<apex:pageBlock >
<apex:pagebLockTable value="{!accList}" var="a">
    <apex:column >
        <apex:inputCheckbox value="{!a.selected}" onclick="updateSel()"/>
    </apex:column>
    <apex:column value="{!a.Acc['Name']}"/>
    
    
</apex:pagebLockTable>  

<apex:commandButton action="{!next}" value="Next"/>


<apex:pageBlockTable value="{!selAcc}" var="acc" id="pgblock2">

    <apex:column value="{!acc['Name']}"/>
</apex:pageBlockTable>

<apex:actionFunction name="updateSel" action="{!updateSel}" reRender="pgblock2"/>

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


Controller:

public class accountCon {

public list<Sobject> selAcc{get{
    selAcc = selAcc();
    return selAcc;
}set;}
public list<accountWrapper> accList{get
{
    return accLIst;   
}

set;}
    public accountCon(ApexPages.StandardController controller) {
    selAcc = new List<Sobject>();
    getAccounts();
    }

ApexPages.standardSetController sCon;


public List<accountWrapper> getAccounts()
{
    if(sCon==null)
        sCon = new ApexPages.standardSetController(Database.getQueryLocator([select id,name,type from Account]));
    sCon.setPageSize(5);
    
    if(accLIst == null)
        accLIst = new List<accountWrapper>();
        
    for(sobject s:sCon.getRecords())
    {
        accountWrapper wrp = new accountWrapper();
        wrp.selected = false;
        wrp.acc=s;
        accLIst.add(wrp);
    }
    return accList;
}

public void updateSel()
{
    List<Sobject> s = new List<Sobject>();
    for(accountWrapper awrp :accList )
    {
        if(awrp.selected)
         s.add(awrp.acc);
    }
    system.debug('Before set selected:'+scon.getSelected());
    sCon.setSelected(s);
    system.debug('After set selected:'+scon.getSelected());
}


public list<Sobject> selAcc()
{
    return scon.getSelected();
}
public void next()
{
    accList .clear();
    sCon.Next();
    accList  = getAccounts();
}

class accountWrapper
{
    public Boolean selected{get;set;}
    public Sobject Acc{get;set;}
}
}

 
Hello Salesforce community! I keep receiving the "Apex CPU Time Limit" error when adding many products to an opportunity after saving / adding more and then resaving.

I know that  my Apex execution time is too long, and that the Salesforce limit is exceeded. I read that the Maximum CPU time on the salesforce servers is 10,000 milliseconds (Synchronous limit) 60,000 milliseconds (Asynchronous limit). The answer to fix this issue is to refine my code by removing unnecessary loop for better efficiency. (Ex: Inserting a "Map" field to bypass some things)... etc. Can anyone assist me when time permits? Please see my "opportunityProductEntry" visualforce page code below:

<apex:page standardController="Opportunity" extensions="opportunityProductEntryExtension" action="{!priceBookCheck}" >
<apex:sectionHeader Title="Manage {!$ObjectType.Product2.LabelPlural}" subtitle="{!opportunity.Name}"/>
<apex:messages style="color:red"/>
<style type="text/css">
.search{
font-size:14pt;
margin-right: 20px;}
.fyi{
color:red;
font-style:italic;}
.label{
margin-right:10px;
font-weight:bold;
}
        .custPopup{
           background-color: white;
            border-width: 2px;
            border-style: solid;
            z-index: 9999;
            left: 50%;
            padding:10px;
            position: absolute;
            /* These are the 3 css properties you will need to change so the popup
            displays in the center of the screen. First set the width. Then set
            margin-left to negative half of what the width is. You can add
            the height property for a fixed size pop up if you want.*/
            width: 500px;
            margin-left: -250px;
            top:100px;
        }
        .popupBackground{
            background-color:green;
            opacity: 0.20;
            filter: alpha(opacity = 20);
            position: absolute;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            z-index: 9998;
        }
</style>
<script type='text/javascript'>
var waitTime = 1;
var countDown = waitTime+1;
var started = false;   
function resetTimer(){
countDown=waitTime+1;
if(started==false){
started=true;
                runCountDown();
            }
        }
function runCountDown(){
countDown--;
if(countDown<=0){
fetchResults();
started=false;
            }
else{
window.setTimeout(runCountDown,1000);
            }
        }
function checkBoxChecked(isChecked, obj)
        {
            if(isChecked.checked)
            {         
                recs +=  obj + ',';
                ShowPopup(obj);
            }
        }
      
        function selRelatedRecs(isChecked, obj)
        {
            if(isChecked.checked)
                recs += obj + ',';
            else
            {
                var str = obj + ',';
                recs = recs.replace(str, ''); 
            }
        }
      
        function addRecs()
        {
            addSelectedRecs(recs);
            return false;
        }
    </script>

    <apex:form >
  
        <apex:outputPanel id="mainBody">
      
            <apex:outputLabel styleClass="label">PriceBook: </apex:outputLabel>
            <apex:outputText value="{!theBook.Name}"/>&nbsp;
            <apex:commandLink action="{!changePricebook}" value="change" immediate="true"/>
            <br/>
            <!-- not everyone is using multi-currency, so this section may or may not show -->
            <apex:outputPanel rendered="{!multipleCurrencies}">
                <apex:outputLabel styleClass="label">Currency: </apex:outputLabel>
                <apex:outputText value="{!chosenCurrency}"/>
                <br/>
            </apex:outputPanel>
            <br/>
          
<!-- this is the upper table... a.k.a. the "Shopping Cart"-->

            <!-- notice we use a lot of $ObjectType merge fields... I did that because if you have changed the labels of fields or objects it will reflect your own lingo -->
            <apex:pageBlock title="Selected {!$ObjectType.Product2.LabelPlural}" id="selected" >
                <apex:pageMessages id="pgMsg" />       
                <apex:pageblockTable value="{!shoppingCart}" var="s">
                    <apex:column >
                        <apex:commandLink value="Remove" action="{!removeFromShoppingCart}" reRender="selected,searchResults" immediate="true">
                            <!-- this param is how we send an argument to the controller, so it knows which row we clicked 'remove' on -->
                            <apex:param value="{!s.PriceBookEntryId}" assignTo="{!toUnselect}" name="toUnselect"/>
                        </apex:commandLink>
                    </apex:column>
                  
                    <apex:column headerValue="{!$ObjectType.Product2.LabelPlural}" value="{!s.PriceBookEntry.Product2.Name}"/>
                    <apex:column headerValue="{!$ObjectType.OpportunityLineItem.Fields.Quantity.Label}">
                        <apex:inputField value="{!s.Quantity}" style="width:70px" required="true" onkeyup="refreshTotals();"/>
                    </apex:column>
                  
                    <apex:column headerValue="{!$ObjectType.OpportunityLineItem.Fields.Hours_Needed__c.Label}">
                        <apex:inputField value="{!s.Hours_Needed__c}" style="width:70px" required="false" onkeyup="refreshTotals();"/>
                    </apex:column>
                  
                    <apex:column headerValue="{!$ObjectType.OpportunityLineItem.Fields.Feet_Needed__c.Label}">
                        <apex:inputField value="{!s.Feet_Needed__c}" style="width:70px" required="false" onkeyup="refreshTotals();"/>
                    </apex:column>
                  
                    <apex:column headerValue="{!$ObjectType.OpportunityLineItem.Fields.ListPrice.Label}">
                        <apex:inputField value="{!s.ListPrice}" style="width:70px" required="false" onkeyup="refreshTotals();"/>
                    </apex:column>
                  
                    <apex:column headerValue="{!$ObjectType.OpportunityLineItem.Fields.UnitPrice.Label}">
                        <apex:inputField value="{!s.UnitPrice}" style="width:70px" required="true" onkeyup="refreshTotals();"/>
                    </apex:column>
                  
                    <apex:column headerValue="{!$ObjectType.OpportunityLineItem.Fields.Description.Label}">
                        <apex:inputField value="{!s.Description}" required="false"/>
                    </apex:column>
                  
                </apex:pageblockTable>
                <apex:pageBlockButtons >
                    <apex:commandButton action="{!onSave}" value="Save"/>
                    <apex:commandButton action="{!onCancel}" value="Cancel" immediate="true"/>
                </apex:pageBlockButtons>
          
            </apex:pageBlock>
  
<!-- this is the lower table: search bar and search results -->
  
            <apex:pageBlock id="pb">
          
                <apex:outputPanel styleClass="search">
                    Search for {!$ObjectType.Product2.LabelPlural}:
                </apex:outputPanel>

                <apex:actionRegion renderRegionOnly="false" immediate="true">
               
                    <apex:actionFunction name="fetchResults" action="{!updateAvailableList}"  reRender="searchResults" status="searchStatus"/>
                  
                    <!-- here we invoke the scripting to get out fancy 'no button' search bar to work -->
                    <apex:inputText value="{!searchString}" onkeydown="if(event.keyCode==13){this.blur();}else{resetTimer();}" style="width:300px"/>
                    &nbsp;&nbsp;
                    <i>
                        <!-- actionStatus component makes it easy to let the user know when a search is underway -->
                        <apex:actionStatus id="searchStatus" startText="searching..." stopText=" "/>
                    </i>
                  
                </apex:actionRegion>
          
                <br/>
                <br/>
            
                <apex:pageBlockButtons >
                        <apex:commandButton onclick="return addRecs();" value="Add Selected Records" />
                        <apex:commandButton action="{!reset}" value="Reset Selection" immediate="true" />
                </apex:pageBlockButtons>  
                <apex:actionFunction name="addSelectedRecs" action="{!addSelectedRecords}"  immediate="true" rerender="selected">
                    <apex:param value="" assignTo="{!selectedRelatedProds}" name="selectedRelatedProds"/>
</apex:actionFunction>
<apex:outputPanel id="searchResults">
<apex:pageBlockTable value="{!AvailableProducts}" var="a">
<apex:column >
<apex:inputCheckbox id="idSelected" onclick="checkBoxChecked(this,'{!a.Id}');"/>
</apex:column>
<apex:column headerValue="{!$ObjectType.Product2.Fields.Name.Label}">
<apex:commandLink action="/{!a.Product2.Id}" value="{!a.Product2.Name}"/>
</apex:column>
<apex:column headerValue="{!$ObjectType.PricebookEntry.Fields.UnitPrice.Label}" value="{!a.UnitPrice}"/>
<!--
<apex:column headerValue="{!$ObjectType.Product2.Fields.Description.Label}" value="{!a.Product2.Description}"/>
-->
<apex:column headerValue="{!$ObjectType.Product2.Fields.Family.Label}" value="{!a.Product2.Family}"/>
<br/>
<div>
<apex:panelGroup >
<apex:commandLink action="{!First}" value="First"  immediate="true" reRender="pb" />           
&nbsp;&nbsp;
<apex:commandLink action="{!Previous}" reRender="pb" value="Previous"  immediate="true" rendered="{!hasPrevious}"/>           
&nbsp;&nbsp;
<apex:outputLabel > Page No#&nbsp;{!pageno} </apex:outputLabel>&nbsp;&nbsp;&nbsp;&nbsp;
<apex:commandLink action="{!Next}" value="Next"  immediate="true" rendered="{!hasNext}" reRender="pb"/>           
&nbsp;&nbsp;
<apex:commandLink action="{!Last}" value="Last"  immediate="true" reRender="pb"/>           
&nbsp;&nbsp;
</apex:panelGroup>
</div>
</apex:outputPanel>
<apex:outputPanel id="custompopup">
<apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayPopUp}"/>
<apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}">
<apex:pageBlock title="Related Products">
<apex:pageBlockTable value="{!RelatedProducts}" var="a">
<apex:column >
<apex:inputCheckbox id="idRelSelected" onclick="selRelatedRecs(this, '{!a.Id}');"/>
</apex:column>
<apex:column headerValue="{!$ObjectType.Product2.Fields.Name.Label}">
<apex:commandLink action="/{!a.Product2.Id}" value="{!a.Product2.Name}"/>
</apex:column>
<apex:column headerValue="{!$ObjectType.PricebookEntry.Fields.UnitPrice.Label}" value="{!a.UnitPrice}"/>
<!--
<apex:column headerValue="{!$ObjectType.Product2.Fields.Description.Label}" value="{!a.Product2.Description}"/>
-->
<apex:column headerValue="{!$ObjectType.Product2.Fields.Family.Label}" value="{!a.Product2.Family}"/>
</apex:pageBlockTable><br/>
<apex:pageBlockButtons >
<apex:commandButton value="Close" action="{!closePopup}"  immediate="true" rerender="custompopup" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:outputPanel>
</apex:outputPanel>
<apex:actionFunction name="ShowPopup" action="{!showPopup}"  immediate="true" rerender="custompopup">
<apex:param value="" assignTo="{!toSelect}" name="toSelect"/>
</apex:actionFunction>
</apex:pageBlock>
 </apex:outputPanel>
</apex:form>
</apex:page>

Thank you!

Andrew
I have a simple controller that is designed to act as a time. As so:

public class timerController {

    public static dateTime startTime {get;set;}
    public static dateTime stopTime {get;set;}
 
    public static void startTimer(){

        startTime = system.now();

        system.debug(startTime);
    }
    
    public static void stopTimer(){
        
        stopTime = system.now();

        system.debug(startTime);
        system.debug(stopTime);
    }

}

Each method is tied to a button ('Start Timer' and 'Stop Timer'). When I run the startTimer method, I can see the startTime value in my debug.
When I run the stopTimer method, I can see the stopTime value in my debug, but the startTime has been reset to null.

Why is the startTime value not being maintained in the state? I know I must be missing something small, but I can't for the life of me spot it.

Any suggestions would be greatly appreciated.

I have a VF page which retrieves a custom object data using the ajax toolkit. I am using this VF page within a community as well as in the internal org. This page loads fine in the internal org, but within the community i get the below error message.  

POST https://xxxxx.force.com/services/Soap/u/29.0 500 (Internal Server Error) connection.js:594
Uncaught {faultcode:'UNKNOWN_EXCEPTION', faultstring:'UNKNOWN_EXCEPTION: Site under construction', } connection.js:1014

To fix this i've copied the connection.js in the VF page, and added the site prefix global variable where the server url is being set in the connection.js.

Is this a bug within the toolkit? Or is there a better way to handle this, as i don't want to copy the connection.js inside the Vf?

  • April 01, 2014
  • Like
  • 0