• lrw757
  • NEWBIE
  • 80 Points
  • Member since 2012

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 12
    Replies
I have this list of lists and when I used this code I only get the last element of the list

//////////////////////////////////////////////////////////// APEX CODE ////////////////////////////////////////////////////////////////////////////////////   
private List<List<MinistrySharesSummary>> ListCollector (List<MinistrySharesSummary> suggestedAmountsList){
        List<List<MinistrySharesSummary>> classisList = new List<List<MinistrySharesSummary>>();
        List<MinistrySharesSummary> churchList = new List<MinistrySharesSummary>();
        
        String tempParent = suggestedAmountsList.get(0).parent;
        for(MinistrySharesSummary ms : suggestedAmountsList){
            
            if(ms.parent == tempParent ){
                churchList.add(ms);     
            }
            else{
                classisList.add(churchList);
                churchList.clear();
                churchList.add(ms);
                tempParent = ms.parent;
            }
        }
        
        return classisList;
    }

 
Good morning everyone,  

I have a trigger that will assign a lookup value from a custom object (data_center_location__c) to an Opportunity based on a picklist field (location__c) on the Opportunity.  The trigger works okay, but i'm having trouble with my test class.  I'm receiving the Expression error when trying to save.  I also have to state that i'm not a developer so I don't have a great understanding of basic concepts when it comes to test classes:

Trigger is:

trigger UpdateDataCenterLocation on Opportunity (before insert, before update){
      Set<String> locationSet = new Set<String>();
      Map<String,Id> mapLocationSetwithDataCntr = new Map<String,Id>();
      for (Opportunity obj: trigger.new){
          if(!String.isBlank(obj.Location__c)){
              locationSet.add(obj.Location__c);
          }
      }
      if(!locationSet.isEmpty()){
          for(Data_Center_Location__c dataCenter : [SELECT Id,Opportunity_Location_Code__c FROM Data_Center_Location__c WHERE Opportunity_Location_Code__c IN :locationSet]){
              mapLocationSetwithDataCntr.put(dataCenter.Opportunity_Location_Code__c,dataCenter.Id);//Expecting there will be one record for each location, otherwise this map will have last Data_Center_Location__c Id
          }
      }
      for (Opportunity obj: trigger.new){
          if(!String.isBlank(obj.Location__c) && mapLocationSetwithDataCntr != null && mapLocationSetwithDataCntr.get(obj.Location__c) != null){
                  obj.Data_Center_Location__c = mapLocationSetwithDataCntr.get(obj.Location__c);
        }
          else{
              obj.Data_Center_Location__c = null;
          }
      }
  }

________
Again, the trigger works as should, the test class on the other hand doesn't:

@isTest

    Private class UpdateDataCenterLocationTestClass {
        static testMethod void UpdateDataCenterLocation () {
    
        List <Opportunity> OpportunityLst = new List <Opportunity>();
        Opportunity Opp = new Opportunity ();
       Opportunity.Name = 'test Opportunity';
       Opportunity.Location__c = 'TX-DAL-03LEW' ;
       Opportunity.Stagename = 'Stage 1: Qualified Prospect';
       
       Opportunity.Closedate = '2015, 2, 26';
        OpportunityLst.add(opp);
        
        insert Opp;
    
    }
    }

--------------------------
For the test class, i'm just trying to create an Opportunity with the location__c field populated with a value, seems easy enough.  Any guidance would be much appreciated.

Thanks everyone
-d
I have a piece of code that inserts multiple records of an object, loops over the objects, and creates a queueable instance for each one that involves a DML on this object. When I perform this code for one record, the code performs successfully, but when I queue up more than one, I get an UNABLE TO LOCK ROW error.

There are no triggers, workflow rules, etc. on the SObject (it's a brand new, fresh object created by myself), and no other DML operations take place in either class on those objects. Any ideas on why this is occuring?

Here is a sample of the code:
public with sharing class QueueableTest {

    public void test() {
        List<MyObject__c> osToInsert = new List<MyObject__c>();
        for(integer i = 0; i < 10; i++) {
           osToInsert.add(new MyObject__c());
        }
        insert osToInsert;

        for(MyObject__c o : osToInsert) {
            System.enqueueJob(new MyQueueableClass(o);
        }
    }
}
 
public class MyQueueableClass implements Queueable {
   
    MyObject__c o;
    
    public MyQueueableClass(MyObject__c o){
        this.o = o;
    }
    
    public void execute(QueueableContext context) {
        o.status__c = 'Running';
        update o;
        //Do something
    }
}

 
  • March 05, 2015
  • Like
  • 0

For some reason, I can't get a custom visualforcepage to redirect. I can't see anything wrong with my code. I've debugged and it's entering the function, it's returning the right url, it just isn't redirecting. The page doesn't even reload. I am calling the function conditionally from a constructor.

 

public pagereference redirect(){
pagereference intermediatePage = Page.PMSprintIntermediatePage;
intermediatePage.setRedirect(true);
return intermediatePage;
}

 

Any thoughts?

  • September 22, 2012
  • Like
  • 0
I have a piece of code that inserts multiple records of an object, loops over the objects, and creates a queueable instance for each one that involves a DML on this object. When I perform this code for one record, the code performs successfully, but when I queue up more than one, I get an UNABLE TO LOCK ROW error.

There are no triggers, workflow rules, etc. on the SObject (it's a brand new, fresh object created by myself), and no other DML operations take place in either class on those objects. Any ideas on why this is occuring?

Here is a sample of the code:
public with sharing class QueueableTest {

    public void test() {
        List<MyObject__c> osToInsert = new List<MyObject__c>();
        for(integer i = 0; i < 10; i++) {
           osToInsert.add(new MyObject__c());
        }
        insert osToInsert;

        for(MyObject__c o : osToInsert) {
            System.enqueueJob(new MyQueueableClass(o);
        }
    }
}
 
public class MyQueueableClass implements Queueable {
   
    MyObject__c o;
    
    public MyQueueableClass(MyObject__c o){
        this.o = o;
    }
    
    public void execute(QueueableContext context) {
        o.status__c = 'Running';
        update o;
        //Do something
    }
}

 
  • March 05, 2015
  • Like
  • 0
Hi, I am having a particular scenario in which all apex jobs, called from a future class or a scheduled apex job, are always stuck in queue under the Apex Jobs list. This stops my process because I call upon an approval process in a future class and without this we are not getting approval requests and can't process the records. Has anybody else had this issue before? This is the first time it happens to me, and it started occurring since last week, when no change was done to what was previously working.

Thanks for your attention.
I have this list of lists and when I used this code I only get the last element of the list

//////////////////////////////////////////////////////////// APEX CODE ////////////////////////////////////////////////////////////////////////////////////   
private List<List<MinistrySharesSummary>> ListCollector (List<MinistrySharesSummary> suggestedAmountsList){
        List<List<MinistrySharesSummary>> classisList = new List<List<MinistrySharesSummary>>();
        List<MinistrySharesSummary> churchList = new List<MinistrySharesSummary>();
        
        String tempParent = suggestedAmountsList.get(0).parent;
        for(MinistrySharesSummary ms : suggestedAmountsList){
            
            if(ms.parent == tempParent ){
                churchList.add(ms);     
            }
            else{
                classisList.add(churchList);
                churchList.clear();
                churchList.add(ms);
                tempParent = ms.parent;
            }
        }
        
        return classisList;
    }

 
Good morning everyone,  

I have a trigger that will assign a lookup value from a custom object (data_center_location__c) to an Opportunity based on a picklist field (location__c) on the Opportunity.  The trigger works okay, but i'm having trouble with my test class.  I'm receiving the Expression error when trying to save.  I also have to state that i'm not a developer so I don't have a great understanding of basic concepts when it comes to test classes:

Trigger is:

trigger UpdateDataCenterLocation on Opportunity (before insert, before update){
      Set<String> locationSet = new Set<String>();
      Map<String,Id> mapLocationSetwithDataCntr = new Map<String,Id>();
      for (Opportunity obj: trigger.new){
          if(!String.isBlank(obj.Location__c)){
              locationSet.add(obj.Location__c);
          }
      }
      if(!locationSet.isEmpty()){
          for(Data_Center_Location__c dataCenter : [SELECT Id,Opportunity_Location_Code__c FROM Data_Center_Location__c WHERE Opportunity_Location_Code__c IN :locationSet]){
              mapLocationSetwithDataCntr.put(dataCenter.Opportunity_Location_Code__c,dataCenter.Id);//Expecting there will be one record for each location, otherwise this map will have last Data_Center_Location__c Id
          }
      }
      for (Opportunity obj: trigger.new){
          if(!String.isBlank(obj.Location__c) && mapLocationSetwithDataCntr != null && mapLocationSetwithDataCntr.get(obj.Location__c) != null){
                  obj.Data_Center_Location__c = mapLocationSetwithDataCntr.get(obj.Location__c);
        }
          else{
              obj.Data_Center_Location__c = null;
          }
      }
  }

________
Again, the trigger works as should, the test class on the other hand doesn't:

@isTest

    Private class UpdateDataCenterLocationTestClass {
        static testMethod void UpdateDataCenterLocation () {
    
        List <Opportunity> OpportunityLst = new List <Opportunity>();
        Opportunity Opp = new Opportunity ();
       Opportunity.Name = 'test Opportunity';
       Opportunity.Location__c = 'TX-DAL-03LEW' ;
       Opportunity.Stagename = 'Stage 1: Qualified Prospect';
       
       Opportunity.Closedate = '2015, 2, 26';
        OpportunityLst.add(opp);
        
        insert Opp;
    
    }
    }

--------------------------
For the test class, i'm just trying to create an Opportunity with the location__c field populated with a value, seems easy enough.  Any guidance would be much appreciated.

Thanks everyone
-d

I am trying to add a simple action status to my page and call it from a button, but the stop text is always visable as soon as the page loads.Even when the id attribute is not specified, the stop text renders. I don't know what is calling it or how it is being called.

 

I've tried nesting it in an action region, nesting it and the button in the same action region, using the "for" attribute to reference the action region around the button, and removing action regions altogether. I tried nesting it in pageblocks, pageBlocksections, and i've removed it from any pageblock at all. I've tried using a facet instead of "stopText" attribute and still that text shows up. Has anybody experienced this? How do I fix it???

For some reason, I can't get a custom visualforcepage to redirect. I can't see anything wrong with my code. I've debugged and it's entering the function, it's returning the right url, it just isn't redirecting. The page doesn't even reload. I am calling the function conditionally from a constructor.

 

public pagereference redirect(){
pagereference intermediatePage = Page.PMSprintIntermediatePage;
intermediatePage.setRedirect(true);
return intermediatePage;
}

 

Any thoughts?

  • September 22, 2012
  • Like
  • 0

Hi,

 

 I have a checkbox on clicking the check box i what to pass the id.

 I m using param but i m unable to get id in controller

 

code-:

<apex:inputCheckbox value="{!radioCheck}">
                      <apex:actionSupport event="onclick"  action="{!UpdateTanent}" rerender="frm"/>
                       <apex:param name="managerid" value="{!p.id}" assignTo="{!getCheckedTenant}"/>                    
              </apex:inputCheckbox>

 

 

getCheckedTenant is coming null in controller.

 

I have also tried with hidden field

 

<apex:inputCheckbox value="{!radioCheck}" onclick="sendpasswd('{p.id}'})">
                      <apex:actionSupport event="onclick"  action="{!UpdateTanent}" rerender="frm"/>

     </apex:inputCheckbox>

 

<apex:inputHidden value="{!getCheckedTenant}" id="theHiddenInput"/>
  <script>
       function sendpasswd(val) {
      alert(val);
    document.getElementById("{!$Component.frm.theHiddenInput}").value =val;
  }

 

but getCheckedTenant is coming null in controller.

 

 

I Dont know where i m going wrong..!!!!

 

Thanks

Shailu

 

 

 

 

 

  • February 08, 2012
  • Like
  • 0

All,

 

I have a requirement to get a sorted list of sObject ApexCode. For each sObject set the Status Field to a pre-defined value and update the List. To acheive this I have sorted query on the sObject which returns a List. For some reason the iteration over the sObject List using the for loop does not return the results in sorted order. Execution of query itself in Eclipse returns the sorted results.

 

Here is the psuedo-code (Apex Code). Can someone tell me what is missing here:

//Check 1::

List<sObject> resultList = [Select Id, Name from sObject where value >100 order by startDate asc];

 

for (sObject result: resultList)

{

  // Check 2::

   System.debug('result start Date='+result.startDate);  

}

 

Here sObject is the custom object,

          Sort Query returns the results in the required order

          Iteration over the List is NOT ordered.

 

 

Any thoughts what am I missing here?

 

TIA

Rahul

  

Hi,

 

Is it possible to use letter-spacing value (with CSS) in PDF? I tried but without no luck. Letter-spacing in HTML with CSS seems to work, but a client needs PDF output...

 

Current CSS value:

 

letter-spacing: 1em; 

 

(I also tested with pt and px -values, without no luck) 

 

Regards

 

Pasi 

I'm trying to use visualforce to perform the following:
A. Show related lists (and all headings) only if a related record exists.
B. If a related record does not exist, the particular section is not displayed.
 
I'm trying to use the apex:relatedList tag with the rendered attribute.
 
Is it possible to check if the list is empty as a boolean expression within visualforce without having to create a custom controller method? I have a working solution, but if I want to add this functionality for all related lists, it's a lot of extra controller code to write.
 
Thanks in advance.
 
 
VisualForce View Page
<apex:page standardController="Account" extensions="AccountHiddenListController">
    <apex:detail relatedList="false">
        <apex:relatedList list="Opportunities" rendered="{!relatedOpportunitiesExist}">    
        </apex:relatedList>
    </apex:detail>
</apex:page>
 
 
Controller Code:
public class AccountHiddenListController
{
    private final Account account;
    private boolean relatedOpportunitiesExist;
   
    public AccountHiddenListController (ApexPages.StandardController accountController)
    {
        this.account = (Account) accountController.getRecord();
    }
   
    public boolean getRelatedOpportunitiesExist()
    {
        if (this.relatedOpportunitiesExist != null)
        {
            return this.relatedOpportunitiesExist;
        }
   
        List<Opportunity> opp = this.getOpportunitiesList();
        if (opp.size() > 0)
        {
            this.relatedOpportunitiesExist = true;
        }
        else
        {
            this.relatedOpportunitiesExist = false;       
        }
        return this.relatedOpportunitiesExist;
           
    }
   
    public void setRelatedOpportunitiesExist()
    {
   
    }
   
    public List<Opportunity> getOpportunitiesList()
    {
        if (this.account == null)        
            return null;       
        return [select o.id
        from Opportunity o
        where o.AccountId = :account.id];
       
    }
   
}
Does anyone know what does this define:
System.ListException: Missing id at index: 0

I am trying to delete in my testmethod the item i created during my testmethod and it does not work...
anyone have an example of using delete in there test methods or what
that message defines.
Thanks