• Kyle_at_box
  • NEWBIE
  • 0 Points
  • Member since 2010

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

Hi All,

 

I'm working with a couple of custom objects that have a master-detail relationship with one another.  The master's api name is zqu_Quote__c and the detail's api name is zqu__QuoteCharge__c.

 

I'm trying to write a simple trigger that will query for the field "zqu__Discount__c" in the detail object and assign that value to the field Discount__c in the master object.  Unfortunately, I'm having trouble accessing the master object in my query.  My code is below - I think my issue has to do with the syntax I'm using to call for the ID of the zqu__Quote__c object.  Any suggestions?

 

 

trigger DiscountUpdate on zqu__QuoteCharge__c (after insert) {

	 list<QuoteCharges__c> myList = [select q.Id,    q.zqu__Discount__c, q.zqu__Quote__r.Discount__c from zqu__QuoteCharge__c q where q.Quote__c =:quoteID];
	 
	 for (QuoteCharge__c qc: myList) {
	 	qc.zqu__Quote__r.Discount__c = qc.zqu__Discount__c;
	 	}
	 update mylist;
}

 

 

I have a similar issue to this posting here, although I'm still not able to figure out what's causing this error to show up: 

 

http://forums.sforce.com/t5/Apex-Code-Development/Method-does-not-exist-or-incorrect-signature-in-test-class/m-p/187840

 

I've written a method that takes a list of leads, iterates across it and changes certain fields, updates the appropraite records, then returns the list.  

 

public with sharing class LeadUpdate {

       public static List<Lead> changeSource(List<Lead> boxlist){
       
        for(lead a:boxlist){
        
        if (a.Source_Detail_Most_Recent__c == '??') {
         a.Source_Detail__c = '';
         a.LeadSource = 'REP NEEDS TO ASK';
          
         }       try {update boxlist;} catch ( System.DmlException e) {
 
            system.assert(e.getMessage().contains('irst error: FIELD_CUSTOM_VALIDATION_EXCEPTION, A lead with this email address already exists'),
                e.getMessage());           
 
    }
    return boxlist;
       }
}

 

 

I'll be activating this through a VF page, so my idea is just to pass a list that is populated by a SQL query into the above method.  However, when testing this method (there are actually ~100 if statements, though I'm just testing on the first one for now) I'm running into this error:

 

"Method does not exist or incorrect signature: LeadUpdate.chagneSource(List<Lead>)

 

My test looks like this:

 

 

@isTest
private class LeadUpdateTest {

	private static testmethod void updatetest(){
		List<Lead> boxlist = new List<Lead>();
		for(integer j = 0; j < 10; j++){
			lead a = new lead (LastName = 'test' + j, Source_Detail__c = '??', LeadSource = '');
			boxlist.add(a);
		}
		insert boxlist;
		
		LeadUpdate lu = new LeadUpdate();
		List<Lead> testolist = null;
		testolist = LeadUpdate.changeSource(boxlist);
		for(lead a: testolist){
			system.assertEquals('', a.Source_Detail__c);
			system.assertEquals('REP NEEDS TO ASK', a.LeadSource);
		}
	}

}

 

 

 

any ideas?  thank you all!

 

 

 

 

 

 

Hi All,

 

I'm relatively new to writing in Apex, so forgive me if it looks like I'm making rookie mistakes - I probably am making rookie mistakes :)

 

Myself and a colleague are trying to perform a cleanup of some old data.  We have a field called "Lead Source," which is a picklist with around 8 or so values.  The powers that be have come up with 7 or so different values that make more sense than the initial 8, so our task is to map the old values to their respective new ones.  Altogether, there are around 40,000 records that need to be adjusted.  

 

We've decided to approach this by writing a simple apex class in our sandbox:

 

 

public class leadSourceMap {
    public VFConnect(ApexPages.StandardController controller) { }
        public static void changeSource(){
        Account[] acclist = [SELECT Id,Lead_Source__c FROM account WHERE account.Lead_Source__c =  'Direct'];
        for(account a:acclist){
        if (a.Lead_Source__c == 'Direct') {
         a.Lead_Source__c = 'Rep Needs To Ask';
         }
         try { update a; } catch ( System.DmlException e) {
 
            system.assert(e.getMessage().contains('irst error: FIELD_CUSTOM_VALIDATION_EXCEPTION, A lead with this email address already exists'),
                e.getMessage());   
                
        }
    }

}
}

 

We couldn't figure out how to make this run, so we decided to build a simple visualforce page that just called the changesource method when any account was accessed:

 

 

 

<apex:page standardController="Account"
 extensions="VFConnect"
 action="{!changeSource}"
>
  <apex:sectionHeader title="Auto-Running Apex Code"/>
  <apex:outputPanel >
      You tried calling Apex Code from a button.  If you see this page, something went wrong.  You should have
      been redirected back to the record you clicked the button from.
  </apex:outputPanel>
</apex:page>

 To our great joy, this script worked when we tested it on a batch of 25 accounts that we had loaded into my sandbox.  Unfortunately, when I tried it on about 500 accounts, it returned this error:

 

Content cannot be displayed: Assertion Failed: Update failed. First exception on row 0 with id 001P000000HMwuFIAT; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, EDP1.ActivityReset: execution of AfterUpdatecaused by: System.LimitException: EDP1:Too many SOQL queries: 101(EDP1): []

 

It looks like we're querying the database for each action, but I meant to write our apex such that it queried once and then pulled from that array to go through and make the appropriate changes.  Any help on both the SOQL question and on how we might be able to architect this better would be greatly appreciated!

 

Thank you all!

 

 

 

 

Hi All,

 

I'm working with a couple of custom objects that have a master-detail relationship with one another.  The master's api name is zqu_Quote__c and the detail's api name is zqu__QuoteCharge__c.

 

I'm trying to write a simple trigger that will query for the field "zqu__Discount__c" in the detail object and assign that value to the field Discount__c in the master object.  Unfortunately, I'm having trouble accessing the master object in my query.  My code is below - I think my issue has to do with the syntax I'm using to call for the ID of the zqu__Quote__c object.  Any suggestions?

 

 

trigger DiscountUpdate on zqu__QuoteCharge__c (after insert) {

	 list<QuoteCharges__c> myList = [select q.Id,    q.zqu__Discount__c, q.zqu__Quote__r.Discount__c from zqu__QuoteCharge__c q where q.Quote__c =:quoteID];
	 
	 for (QuoteCharge__c qc: myList) {
	 	qc.zqu__Quote__r.Discount__c = qc.zqu__Discount__c;
	 	}
	 update mylist;
}

 

 

I have a similar issue to this posting here, although I'm still not able to figure out what's causing this error to show up: 

 

http://forums.sforce.com/t5/Apex-Code-Development/Method-does-not-exist-or-incorrect-signature-in-test-class/m-p/187840

 

I've written a method that takes a list of leads, iterates across it and changes certain fields, updates the appropraite records, then returns the list.  

 

public with sharing class LeadUpdate {

       public static List<Lead> changeSource(List<Lead> boxlist){
       
        for(lead a:boxlist){
        
        if (a.Source_Detail_Most_Recent__c == '??') {
         a.Source_Detail__c = '';
         a.LeadSource = 'REP NEEDS TO ASK';
          
         }       try {update boxlist;} catch ( System.DmlException e) {
 
            system.assert(e.getMessage().contains('irst error: FIELD_CUSTOM_VALIDATION_EXCEPTION, A lead with this email address already exists'),
                e.getMessage());           
 
    }
    return boxlist;
       }
}

 

 

I'll be activating this through a VF page, so my idea is just to pass a list that is populated by a SQL query into the above method.  However, when testing this method (there are actually ~100 if statements, though I'm just testing on the first one for now) I'm running into this error:

 

"Method does not exist or incorrect signature: LeadUpdate.chagneSource(List<Lead>)

 

My test looks like this:

 

 

@isTest
private class LeadUpdateTest {

	private static testmethod void updatetest(){
		List<Lead> boxlist = new List<Lead>();
		for(integer j = 0; j < 10; j++){
			lead a = new lead (LastName = 'test' + j, Source_Detail__c = '??', LeadSource = '');
			boxlist.add(a);
		}
		insert boxlist;
		
		LeadUpdate lu = new LeadUpdate();
		List<Lead> testolist = null;
		testolist = LeadUpdate.changeSource(boxlist);
		for(lead a: testolist){
			system.assertEquals('', a.Source_Detail__c);
			system.assertEquals('REP NEEDS TO ASK', a.LeadSource);
		}
	}

}

 

 

 

any ideas?  thank you all!

 

 

 

 

 

 

Hi All,

 

I'm relatively new to writing in Apex, so forgive me if it looks like I'm making rookie mistakes - I probably am making rookie mistakes :)

 

Myself and a colleague are trying to perform a cleanup of some old data.  We have a field called "Lead Source," which is a picklist with around 8 or so values.  The powers that be have come up with 7 or so different values that make more sense than the initial 8, so our task is to map the old values to their respective new ones.  Altogether, there are around 40,000 records that need to be adjusted.  

 

We've decided to approach this by writing a simple apex class in our sandbox:

 

 

public class leadSourceMap {
    public VFConnect(ApexPages.StandardController controller) { }
        public static void changeSource(){
        Account[] acclist = [SELECT Id,Lead_Source__c FROM account WHERE account.Lead_Source__c =  'Direct'];
        for(account a:acclist){
        if (a.Lead_Source__c == 'Direct') {
         a.Lead_Source__c = 'Rep Needs To Ask';
         }
         try { update a; } catch ( System.DmlException e) {
 
            system.assert(e.getMessage().contains('irst error: FIELD_CUSTOM_VALIDATION_EXCEPTION, A lead with this email address already exists'),
                e.getMessage());   
                
        }
    }

}
}

 

We couldn't figure out how to make this run, so we decided to build a simple visualforce page that just called the changesource method when any account was accessed:

 

 

 

<apex:page standardController="Account"
 extensions="VFConnect"
 action="{!changeSource}"
>
  <apex:sectionHeader title="Auto-Running Apex Code"/>
  <apex:outputPanel >
      You tried calling Apex Code from a button.  If you see this page, something went wrong.  You should have
      been redirected back to the record you clicked the button from.
  </apex:outputPanel>
</apex:page>

 To our great joy, this script worked when we tested it on a batch of 25 accounts that we had loaded into my sandbox.  Unfortunately, when I tried it on about 500 accounts, it returned this error:

 

Content cannot be displayed: Assertion Failed: Update failed. First exception on row 0 with id 001P000000HMwuFIAT; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, EDP1.ActivityReset: execution of AfterUpdatecaused by: System.LimitException: EDP1:Too many SOQL queries: 101(EDP1): []

 

It looks like we're querying the database for each action, but I meant to write our apex such that it queried once and then pulled from that array to go through and make the appropriate changes.  Any help on both the SOQL question and on how we might be able to architect this better would be greatly appreciated!

 

Thank you all!