• kcharubin
  • NEWBIE
  • 30 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
trigger closeTuoCasesWhenDefectFixed on Tuo_Defect__c (after update) {
    for(Tuo_Defect__c d : Trigger.new){
        if(d.Status__c == 'Closed - Fixed'){
            List<Tuo_Case__c> cases = [select Status__c, Solution__c from Tuo_Case__c where Tuo_Defect__c =: d.id];
            for(Tuo_Case__c c : cases ){
                c.Status__c = 'Solution Available';
                c.Solution__c = d.Resolution__c;
                update c;
            }
        }
    }
}

 I wrote the code above and it works fine when there are only a few Cases related to the Defect

Today I tried updating a Defect that has 77 related Cases and I get the following error message.

 

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger closeTuoCasesWhenDefectFixed caused an unexpected exception, contact your administrator: closeTuoCasesWhenDefectFixed: System.LimitException: Too many DML statements: 151".

 

I can't figure out how to get rid of this error message.

Any help would be greatly appriciated.

I am working on a Lead Request system.

Every user has a Lead Center record from which they can manage all their leads and submit Lead Requests.

Each user is only responsible for some set of states.

 

I am trying to make the process of finding the leads for a given request automatic

In the code below I pass in the Lead Request ID as a parameter using a button.

Using the Lead Request ID I then run a query to find the Lead Request Record.

 

On the Lead Request Record there is a text field which lists all the states that a given user is responsible for.

In the findLeads() function below I am trying to run a query on Consumer_Leads__c to find the requested number of leads 

that are in the states listed on the Lead Request.

 

My code work if there is only one state listed.

The IN Clause works in such a way that the parameters need to be single quoted and comma separated

 

If there is only one state listed then the string looks like 'FL' which is in the proper syntax

The problem occurs when there are multiple states listed, the string the looks like 'FL,CT,TX' which is incorrect format

For the IN Clause to accep the input it would have to be 'FL','CT','TX'

 

I would really appriciate if someone could help me figure out how to convert the text field listing the states into the proper format that the IN Clause would accept.

 

This is the code I have so far, Currently it only works if there is only one state listed in the Territory__c text field on the Lead Request

 

public class MyLeadsController {

    public List<Consumer_Leads__c> allLeads {get; set;}
    public String leadRequestID {get; set;}
    public Integer numLeads {get; set;}
    
    public MyLeadsController(ApexPages.StandardController controller) {
    
        leadRequestID = ApexPages.currentPage().getParameters().get('lc');
        
    }
    
    public void findLeads(){
        Lead_Request__c leadRequest = [select id, Number_of_Leads_Requested__c, Territory__c, Lead_Center__c
                                    from Lead_Request__c
                                    where id =: leadRequestID];
        
        allLeads = [select Lead_Center__c, Lead_Request_NEW__c, First_Name__c, Last_Name__c, State__c, City__c, ZIP_Code__C, Lead_Source__c, CreatedDate
                    from Consumer_Leads__c
                    where Lead_Center__c = 'a19Q0000001OaRM' AND State__c IN (:leadRequest.Territory__c)
                    limit :(Integer)leadRequest.Number_of_Leads_Requested__c];
                    
       numLeads = allLeads.size();
    }
}

 

Hello I am a beginner developer. I have implemented an apex trigger that counts all related Consumer Lead records.

I am getting this error when I try to create a new Lead Request record

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger rollupConsumerLeads caused an unexpected exception, contact your administrator: rollupConsumerLeads: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.rollupConsumerLeads: line 5, column 1
 

 

trigger rollupConsumerLeads on Lead_Request__c (before insert, before update) {
  for(Lead_Request__c p:Trigger.new)
    p.Leads_Given_NEW__c = 0;
  for(Consumer_Leads__c c:[select id,Lead_Request_NEW__c from Consumer_Leads__c where Lead_Request_NEW__c in :Trigger.new])
    Trigger.newMap.get(c.Lead_Request_NEW__c).Leads_Given_NEW__c++;
}

 

Any help would be appricciated.

Hello

I've recently been writting a few basic controllers for some visualforce pages, and of course now  need to test them. Problem is I don't really know how. Normally you know you'd instantiate the class, pass data to the methods, and assert against the results right?  With this controller I dont know what to test against.

 

It would be great if someone could help me write a test calss for this

 

public class MyLeadsController {

    public List<Consumer_Leads__c> unassignedLeads {get; set;}
    public List<Consumer_Leads__c> allLeads {get; set;}
    public String leadCenter {get; set;}
    
    public MyLeadsController(ApexPages.StandardController controller) {
    
        leadCenter = ApexPages.currentPage().getParameters().get('lc');
        
        this.allLeads = [select id, First_Name__c, Last_Name__c, State__c, Lead_Request__c, IFP_Producer_Receiving_the_Lead__c, Lead_Center__c
        from Consumer_Leads__c 
        where Lead_Center__c = :leadCenter AND IFP_Producer_Receiving_the_Lead__c != ''
        order by id]; 
        
        this.unassignedLeads = [select id, First_Name__c, Last_Name__c, State__c, Lead_Request__c, IFP_Producer_Receiving_the_Lead__c, Lead_Center__c 
        from Consumer_Leads__c
        where Lead_Center__c = :leadCenter AND IFP_Producer_Receiving_the_Lead__c = ''
        order by id];
    }
    


    public PageReference Save(){
        update allLeads;
        update unassignedLeads;
        return null;
    }   
    
    public PageReference Back(){
        return new PageReference('/'+leadCenter);
    } 
   
}

 

I am working on a Lead Request system.

Every user has a Lead Center record from which they can manage all their leads and submit Lead Requests.

Each user is only responsible for some set of states.

 

I am trying to make the process of finding the leads for a given request automatic

In the code below I pass in the Lead Request ID as a parameter using a button.

Using the Lead Request ID I then run a query to find the Lead Request Record.

 

On the Lead Request Record there is a text field which lists all the states that a given user is responsible for.

In the findLeads() function below I am trying to run a query on Consumer_Leads__c to find the requested number of leads 

that are in the states listed on the Lead Request.

 

My code work if there is only one state listed.

The IN Clause works in such a way that the parameters need to be single quoted and comma separated

 

If there is only one state listed then the string looks like 'FL' which is in the proper syntax

The problem occurs when there are multiple states listed, the string the looks like 'FL,CT,TX' which is incorrect format

For the IN Clause to accep the input it would have to be 'FL','CT','TX'

 

I would really appriciate if someone could help me figure out how to convert the text field listing the states into the proper format that the IN Clause would accept.

 

This is the code I have so far, Currently it only works if there is only one state listed in the Territory__c text field on the Lead Request

 

public class MyLeadsController {

    public List<Consumer_Leads__c> allLeads {get; set;}
    public String leadRequestID {get; set;}
    public Integer numLeads {get; set;}
    
    public MyLeadsController(ApexPages.StandardController controller) {
    
        leadRequestID = ApexPages.currentPage().getParameters().get('lc');
        
    }
    
    public void findLeads(){
        Lead_Request__c leadRequest = [select id, Number_of_Leads_Requested__c, Territory__c, Lead_Center__c
                                    from Lead_Request__c
                                    where id =: leadRequestID];
        
        allLeads = [select Lead_Center__c, Lead_Request_NEW__c, First_Name__c, Last_Name__c, State__c, City__c, ZIP_Code__C, Lead_Source__c, CreatedDate
                    from Consumer_Leads__c
                    where Lead_Center__c = 'a19Q0000001OaRM' AND State__c IN (:leadRequest.Territory__c)
                    limit :(Integer)leadRequest.Number_of_Leads_Requested__c];
                    
       numLeads = allLeads.size();
    }
}

 

Hello I am a beginner developer. I have implemented an apex trigger that counts all related Consumer Lead records.

I am getting this error when I try to create a new Lead Request record

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger rollupConsumerLeads caused an unexpected exception, contact your administrator: rollupConsumerLeads: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.rollupConsumerLeads: line 5, column 1
 

 

trigger rollupConsumerLeads on Lead_Request__c (before insert, before update) {
  for(Lead_Request__c p:Trigger.new)
    p.Leads_Given_NEW__c = 0;
  for(Consumer_Leads__c c:[select id,Lead_Request_NEW__c from Consumer_Leads__c where Lead_Request_NEW__c in :Trigger.new])
    Trigger.newMap.get(c.Lead_Request_NEW__c).Leads_Given_NEW__c++;
}

 

Any help would be appricciated.

Hello

I've recently been writting a few basic controllers for some visualforce pages, and of course now  need to test them. Problem is I don't really know how. Normally you know you'd instantiate the class, pass data to the methods, and assert against the results right?  With this controller I dont know what to test against.

 

It would be great if someone could help me write a test calss for this

 

public class MyLeadsController {

    public List<Consumer_Leads__c> unassignedLeads {get; set;}
    public List<Consumer_Leads__c> allLeads {get; set;}
    public String leadCenter {get; set;}
    
    public MyLeadsController(ApexPages.StandardController controller) {
    
        leadCenter = ApexPages.currentPage().getParameters().get('lc');
        
        this.allLeads = [select id, First_Name__c, Last_Name__c, State__c, Lead_Request__c, IFP_Producer_Receiving_the_Lead__c, Lead_Center__c
        from Consumer_Leads__c 
        where Lead_Center__c = :leadCenter AND IFP_Producer_Receiving_the_Lead__c != ''
        order by id]; 
        
        this.unassignedLeads = [select id, First_Name__c, Last_Name__c, State__c, Lead_Request__c, IFP_Producer_Receiving_the_Lead__c, Lead_Center__c 
        from Consumer_Leads__c
        where Lead_Center__c = :leadCenter AND IFP_Producer_Receiving_the_Lead__c = ''
        order by id];
    }
    


    public PageReference Save(){
        update allLeads;
        update unassignedLeads;
        return null;
    }   
    
    public PageReference Back(){
        return new PageReference('/'+leadCenter);
    } 
   
}