• Nisse Knudsen.ax1026
  • NEWBIE
  • 85 Points
  • Member since 2011

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 23
    Replies

I am getting an error with Too Many DML Statements for a small trigger that I wrote. I know that it has to do with the insert being inside the loop, but I cannot figure out how to correctly write this. I am hoping someone can take a look since it is so small.

 

trigger ReferralChatterFollow on Referral__c (after insert) {

    for(Referral__c r: Trigger.New) {
                    EntitySubscription follow = new EntitySubscription (
                        parentId = r.id,
                        subscriberId = UserInfo.getUserId());
                    insert follow;
    }
}

 

I have the following trigger that takes the user that is in the Assigned field and makes them the record owner once the record is created. Also, if the owner is changed on the record, it will update the Assigned field. This is working perfectly for me, but I am having an issue with code coverage for my other triggers, etc. 

 

I would like to tweek the trigger to say that if the Assigend field is blank, then make the record owner the current user (i.e. normal behavior) and populate the Assigned field with the current user (or maybe it would be easier to populate the Assigned field with the current user so that it assigns ownership that way). This way, I will not get all of these exceptions thrown. I still want the 2nd part of the trigger to work (when owner is changed update the Assigned). 

 

Can someone please help me tweek this trigger?

 

trigger ReferralAssignOwner on Referral__c(before insert, before update) {
  for(Referral__c r:Trigger.new)                                         // For each record
    if(Trigger.isInsert)                                                 // If we're inserting
      r.OwnerId = r.Assigned__c;                                         // Assign ownership from Assigned__c
    else                                                                 // Otherwise (an update)
      if(r.OwnerId != Trigger.oldMap.get(r.id).OwnerId)                  // If ownership has changed
        r.Assigned__c = r.OwnerId;                                       // Place the new owner in Assigned__c
      else                                                               // Otherwise (owner not changed, is an update)
        if(r.Assigned__c != Trigger.oldMap.get(r.id).Assigned__c)        // If the Assigned__c field changed
          r.OwnerId = r.Assigned__c;                                     // Assigned ownership from Assigned__c
}

 

I'm not sure how to check if the checkedvendor or selectedvendor list is null. The visualforce page searches for vendors, then you tick a box and "send RFP" to each one.

 

I am getting the following error when calling the sendRFP method when you fill in the Primary County - but do NOT perform a search before calling sendRFP. If you perform the search then call sendRFP - it just finishes return orderURL (last line in sendRFP).

 

caused by: System.NullPointerException: Attempt to de-reference a null object

Class.ProposalExtension.sendRFP: line 316, column 29 External entry point

 

What i need to know is, is it possible to do error checking in the method something like.. if(vendorList.size() <1) - throw an error. I'm not sure where to insert that into this method.

 

Controller Method

    public PageReference sendRFP() {
    	//Create a list to store the selected Vendors
    	List<Contact> selectedVendor = new List<Contact>();
    	//Loop through the Vendor search results and get the checked records
//316 	for(checkedVendor cV : vendorList) {       
    		if(cV.checked == true) {
    			selectedVendor.add(cV.ven);
    		}
    	}
    	//Create a new RFP record for each selected Vendor
    	for(Contact sVen : selectedVendor){
    		Proposal__c p = new Proposal__c();
    		p.Vendor__c = sVen.Id;
    		p.Order__c = orderId;
    		insert p;
    	}
    	//Set Service Request Valuation Order Date
    	Order__c ord = [SELECT Id, Valuation_Order_Date__c FROM Order__c WHERE Id = :orderId];
    	if(ord.Valuation_Order_Date__c == NULL){
    		ord.Valuation_Order_Date__c = system.today();
    	}
    	update ord;
    	
    	//Return user to the Order page
    	PageReference orderURL = new PageReference('/' + orderId);
    	return orderURL;
    }

 

 

 

Visualforce (if needed)

<apex:page standardController="Proposal__c" extensions="ProposalExtension" tabStyle="Proposal__c" cache="false">
    <apex:sectionHeader title="New RFP"/>
    <apex:form id="searchForm">
        <apex:pageBlock title="Vendor Search" id="SearchBlock" mode="edit">          
            <apex:pageBlockButtons >
                <apex:commandButton value="Search" action="{!vendorSearch}" rerender="results" status="status" id="searchButton" />
                <apex:commandButton value="Send RFP" action="{!sendRFP1}" status="status" id="rfpButton" />
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Search Criteria" columns="2" collapsible="false" showHeader="false">
                <apex:inputField id="primaryCounty" value="{!con.Primary_County__c}" required="true"/>              
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Search Results" id="results" columns="1" collapsible="false">
                <apex:actionStatus id="status" startText="searching..." />   
                <apex:pageBlockTable value="{!vendorList}" var="v" id="searchResults">
                    <apex:column >
                        <apex:facet name="header"> 
                            <apex:inputCheckbox onclick="checkAll(this);"/>
                        </apex:facet>
                    <apex:inputCheckbox value="{!v.Checked}" id="selectedVendor"/>
                    </apex:column>                
                    <apex:column headerValue="Vendor Name">
                        <apex:outputLink value="/{!v.ven.Id}">{!v.ven.Name}</apex:outputLink>
                    </apex:column> 
                     <apex:column headerValue="Account Name">
                        <apex:outputLink value="/{!v.ven.Account.Id}">{!v.ven.Account.Name}</apex:outputLink>
                    </apex:column>       
                </apex:pageBlockTable> 
            </apex:pageBlockSection>          
        </apex:pageBlock>      
    </apex:form>
<script>
    function checkAll(cb) {
        var inputElem = document.getElementsByTagName("input");
        for(var i=0; i<inputElem.length; i++) {
            if(inputElem[i].id.indexOf("selectedVendor")!=-1)
            inputElem[i].checked = cb.checked;
        }
    }   
</script>
</apex:page>

 

 

  • February 09, 2012
  • Like
  • 0

Hey! :)

 

I added a ContentDocument trigger via Force.com IDE und wanted to include this trigger in my managed package.

I create a test method that should fire my trigger, which then calls a trigger handler class.

 

Now the problem:

 

Whe I run the test class, I see as a result, that 80-ish% of my trigger handler code has been covered. This means, the trigger did definitely fire!! But I can't see this trigger in the result list.

But the biggest problem is, that the packaging process aborts everytime with the reason, that the ContentDocument trigger has 0% test coverage.

 

I don't know what to do, it just appears to me, that the ContentDocument trigger has not been fully integrated by SFDC?

 

Any help is appreciated!

 

Best Regards,

 

Nisse

I am getting an error with Too Many DML Statements for a small trigger that I wrote. I know that it has to do with the insert being inside the loop, but I cannot figure out how to correctly write this. I am hoping someone can take a look since it is so small.

 

trigger ReferralChatterFollow on Referral__c (after insert) {

    for(Referral__c r: Trigger.New) {
                    EntitySubscription follow = new EntitySubscription (
                        parentId = r.id,
                        subscriberId = UserInfo.getUserId());
                    insert follow;
    }
}

 

Hi,

 

     I know how to compare strings and Integers, but i am looking for something like below:

  I have 3 strings :

 

 String str1 =  ' abcd' ;

String  str2 = ' cded' ;

String str3 = ' ==' ; ( This is a oparator and can be any != OR > OR < OR any operator) 

 

Now i need a method or any way to check the above three so that i get a boolean value back based on these three arguments.

 

 

Thanks

Bramha

 

 

Hi 

i wanna generate a report , where i need to display a

bar chart and the data has to come from the controller

How could i achieve this , anyone help me with the approach.. 

I have the following trigger that takes the user that is in the Assigned field and makes them the record owner once the record is created. Also, if the owner is changed on the record, it will update the Assigned field. This is working perfectly for me, but I am having an issue with code coverage for my other triggers, etc. 

 

I would like to tweek the trigger to say that if the Assigend field is blank, then make the record owner the current user (i.e. normal behavior) and populate the Assigned field with the current user (or maybe it would be easier to populate the Assigned field with the current user so that it assigns ownership that way). This way, I will not get all of these exceptions thrown. I still want the 2nd part of the trigger to work (when owner is changed update the Assigned). 

 

Can someone please help me tweek this trigger?

 

trigger ReferralAssignOwner on Referral__c(before insert, before update) {
  for(Referral__c r:Trigger.new)                                         // For each record
    if(Trigger.isInsert)                                                 // If we're inserting
      r.OwnerId = r.Assigned__c;                                         // Assign ownership from Assigned__c
    else                                                                 // Otherwise (an update)
      if(r.OwnerId != Trigger.oldMap.get(r.id).OwnerId)                  // If ownership has changed
        r.Assigned__c = r.OwnerId;                                       // Place the new owner in Assigned__c
      else                                                               // Otherwise (owner not changed, is an update)
        if(r.Assigned__c != Trigger.oldMap.get(r.id).Assigned__c)        // If the Assigned__c field changed
          r.OwnerId = r.Assigned__c;                                     // Assigned ownership from Assigned__c
}

 

I am getting a system.assertEquals error on the following test class. Error:

System.AssertException: Assertion Failed: Expected: null, Actual: 00580000001k6g1AAAClass.testReferralAssignOwner.test: line 11, column 1

 Test Class:

@isTest
private class testReferralAssignOwner {
  static testMethod void test() {
    List<User> testUsers = [select id from user where isactive = true limit 2];
    Account a = new Account(Name='test');
    insert a;
    List<Referral__c> refs = new List<Referral__c>();
    refs.add(new Referral__c(Client_Name__c=a.id,Phone__c='12345',Assigned__c=testUsers[0].Id));
    refs.add(new Referral__c(Client_name__c=a.id,Phone__c='12345',Assigned__c=testUsers[1].Id));
    insert refs;
    system.assertEquals(refs[0].OwnerId,testUsers[0].Id); // OwnerId should equal Assigned__c;
    system.assertEquals(refs[1].OwnerId,testUsers[1].Id); // OwnerId should equal Assigned__c;
    refs[0].OwnerId = testUsers[1].Id;
    refs[1].Assigned__c = testUsers[0].Id;
    update refs;
    system.assertEquals(refs[0].Assigned__c,testUsers[1].Id); // Assigned__c should equal OwnerId now
    system.assertEquals(refs[1].OwnerId,testUsers[0].Id); // OwnerId should equal Assigned__c now
  }  
}

 It says that it is expecitng null and getting a user ID instead. It should be expecting the user ID, so I am not sure what the problem is. Any help is greatly appreciated!

I'm not sure how to check if the checkedvendor or selectedvendor list is null. The visualforce page searches for vendors, then you tick a box and "send RFP" to each one.

 

I am getting the following error when calling the sendRFP method when you fill in the Primary County - but do NOT perform a search before calling sendRFP. If you perform the search then call sendRFP - it just finishes return orderURL (last line in sendRFP).

 

caused by: System.NullPointerException: Attempt to de-reference a null object

Class.ProposalExtension.sendRFP: line 316, column 29 External entry point

 

What i need to know is, is it possible to do error checking in the method something like.. if(vendorList.size() <1) - throw an error. I'm not sure where to insert that into this method.

 

Controller Method

    public PageReference sendRFP() {
    	//Create a list to store the selected Vendors
    	List<Contact> selectedVendor = new List<Contact>();
    	//Loop through the Vendor search results and get the checked records
//316 	for(checkedVendor cV : vendorList) {       
    		if(cV.checked == true) {
    			selectedVendor.add(cV.ven);
    		}
    	}
    	//Create a new RFP record for each selected Vendor
    	for(Contact sVen : selectedVendor){
    		Proposal__c p = new Proposal__c();
    		p.Vendor__c = sVen.Id;
    		p.Order__c = orderId;
    		insert p;
    	}
    	//Set Service Request Valuation Order Date
    	Order__c ord = [SELECT Id, Valuation_Order_Date__c FROM Order__c WHERE Id = :orderId];
    	if(ord.Valuation_Order_Date__c == NULL){
    		ord.Valuation_Order_Date__c = system.today();
    	}
    	update ord;
    	
    	//Return user to the Order page
    	PageReference orderURL = new PageReference('/' + orderId);
    	return orderURL;
    }

 

 

 

Visualforce (if needed)

<apex:page standardController="Proposal__c" extensions="ProposalExtension" tabStyle="Proposal__c" cache="false">
    <apex:sectionHeader title="New RFP"/>
    <apex:form id="searchForm">
        <apex:pageBlock title="Vendor Search" id="SearchBlock" mode="edit">          
            <apex:pageBlockButtons >
                <apex:commandButton value="Search" action="{!vendorSearch}" rerender="results" status="status" id="searchButton" />
                <apex:commandButton value="Send RFP" action="{!sendRFP1}" status="status" id="rfpButton" />
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Search Criteria" columns="2" collapsible="false" showHeader="false">
                <apex:inputField id="primaryCounty" value="{!con.Primary_County__c}" required="true"/>              
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Search Results" id="results" columns="1" collapsible="false">
                <apex:actionStatus id="status" startText="searching..." />   
                <apex:pageBlockTable value="{!vendorList}" var="v" id="searchResults">
                    <apex:column >
                        <apex:facet name="header"> 
                            <apex:inputCheckbox onclick="checkAll(this);"/>
                        </apex:facet>
                    <apex:inputCheckbox value="{!v.Checked}" id="selectedVendor"/>
                    </apex:column>                
                    <apex:column headerValue="Vendor Name">
                        <apex:outputLink value="/{!v.ven.Id}">{!v.ven.Name}</apex:outputLink>
                    </apex:column> 
                     <apex:column headerValue="Account Name">
                        <apex:outputLink value="/{!v.ven.Account.Id}">{!v.ven.Account.Name}</apex:outputLink>
                    </apex:column>       
                </apex:pageBlockTable> 
            </apex:pageBlockSection>          
        </apex:pageBlock>      
    </apex:form>
<script>
    function checkAll(cb) {
        var inputElem = document.getElementsByTagName("input");
        for(var i=0; i<inputElem.length; i++) {
            if(inputElem[i].id.indexOf("selectedVendor")!=-1)
            inputElem[i].checked = cb.checked;
        }
    }   
</script>
</apex:page>

 

 

  • February 09, 2012
  • Like
  • 0

Hello,

 

I try to deploy a trigger and its test class in production but I have this error :

Failure Message: "System.LimitException: Too many query rows: 50001", Failure Stack Trace:...

 

The code coverage of this trigger is 100%.

 

I think the pb is due to another test class for another trigger but the both (the 2 triggers and the 2 test classes) are on the same object (Opportunity).

The other trigger is already deployed.

 

How can I solve this problem ?

 

Thank you.

I'm new to salesforce.com and VisualForce/Apex.  I have developed a custom Page that renders a PDF, but I need to conditionally display content based on a field value set on a product - if that product is a line item on the quote.

 

Specifically when I load this page from the quote and display quote information and line item detail (already done), I need to display a div if any of those products' "Agreement_Supplement__c" picklist field contains the value "Supplement A" - but I have another div that needs displayed if that same picklist field contains the value "Supplement B".  It seems that I need to create a function that takes in the orderid and supplement name and returns a true/false.

 

Esentially in my page I would like to be able to do something similar to if(hassupplement(theorderid, thesupplementname),"display:block;","display:none;").  I've read through the documentation and tried a few things, but haven't been able to acomplish this yet.

  • February 08, 2012
  • Like
  • 0

New to custom controllers ...Why we needApexPages.StandardSetController while writing custom list controllers ? A simple example I was reading was doing something like this : 

public class opportunityList2Con {
// ApexPages.StandardSetController must be instantiated
// for standard list controllers
public ApexPages.StandardSetController setCon {
get {
if(setCon == null) {
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
[select name,closedate from Opportunity]));
}
return setCon;
}
set;
}
// Initialize setCon and return a list of records
public List<Opportunity> getOpportunities() {
return (List<Opportunity>) setCon.getRecords();
}
}

 

I modified this and inside 'getOpportunities()' function , I directly written that simple query and it was working perfectly fine.

so why need to use  'setcon' property of type ApexPages.Standardsetcontroller and use Database.query locator.. which is making everything look so complex!

Please suggest