• ynwa
  • NEWBIE
  • 0 Points
  • Member since 2012

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

Hi All,

 

I need help with the below test class (trigger code below). It's my first trigger. I am trying to test an insert (for now) and it seems like my trigger is not working. However my trigger works when I insert/update in Salesforce and bulk insert/update using dataloader. Why does the test class fail to populate the Sales_Rep_CS__c field?

 

Thanks

 

Update: The test results in a Failure: "Assertion Failed: Expected: null, Actual: Julien Trapes"

@isTest
private class AssignSaleRep_Test_Class {

	static testMethod void Test1_TestInsertWithcountryValue() {
		list <Account> liacc = new list <Account>{};
		string SR_CS;
		Account a1 = new Account();
		a1.name = 'PRSingleTest';
		a1.BillingCountry= 'France';
		a1.BillingPostalCode = '59008';
		a1.Sales_Rep_CS__c ='F';
      	a1.Sales_Rep_M__c ='';
		system.debug('^^^^^^^^^^**********^^^^^'+a1);
		liacc.add(a1);
		insert liacc;
	
		list<Account> ia = [select name, sales_rep_cs__c from Account where id IN :liacc];
		for(Account s1 : ia)
		{
			system.debug('!!!!!!!!!!!!!!!!!!!!!'+s1.Sales_Rep_CS__c);
			system.assertEquals(s1.Sales_Rep_CS__c, 'Julien Trapes');
		}
	}
}

 

The Trigger:

trigger Assign_Sales_Rep on Account (before insert, before update) 
{
	// Grab Terriory information based on CountryPostcode
    map<String, String> map_CountryPostcode_to_SalesRepCS = new map<String, String>();
    map<String, String> map_CountryPostcode_to_SalesRepM = new map<String, String>();
    
    string AccCountryPostcode = ''; 
	List<String> postalCodes = new List<String>();
	List<Account> accList = new List<Account>();
	
	for (Account acc : trigger.new)
	{
		if (acc.BillingPostalCode == null || acc.BillingPostalCode == '' || acc.BillingPostalCode == ' ' || acc.BillingCountry == Null || acc.BillingCountry == '' || acc.BillingCountry == ' ')
	    {
	    }
		else
		{
			accList.add(acc);
			AccCountryPostcode = acc.BillingCountry+acc.BillingPostalCode;
			postalCodes.add(AccCountryPostcode);
		}
  	
	}
	
	for(Sale_Territory__c st : [SELECT CountryPostcode__c, Sales_Rep_CS__c, Sales_Rep_M__c FROM Sale_Territory__c WHERE CountryPostcode__c IN :postalCodes])
	{
		map_CountryPostcode_to_SalesRepCS.put(st.CountryPostcode__c, st.Sales_Rep_CS__c);
        map_CountryPostcode_to_SalesRepM.put(st.CountryPostcode__c, st.Sales_Rep_M__c);
        system.debug('&&&&&&&&&&&'+map_CountryPostcode_to_SalesRepCS);
	}
	
	for(Account act : accList)
	{
		if (map_CountryPostcode_to_SalesRepCS.containsKey(AccCountryPostcode))
		{
			act.Sales_Rep_CS__c = map_CountryPostcode_to_SalesRepCS.get(AccCountryPostcode);      
			system.debug('@@@@@@@'+act.Sales_Rep_CS__c);             
		}
		else
		{
			act.Sales_Rep_CS__c ='';
		}
		
		if (map_CountryPostcode_to_SalesRepM.containsKey(AccCountryPostcode))
		{
			act.Sales_Rep_M__c = map_CountryPostcode_to_SalesRepM.get(AccCountryPostcode);                
		}
		else
		{
			act.Sales_Rep_M__c ='';
		}
	}
}

 

  • July 31, 2012
  • Like
  • 0

Hi All,

I am new to programming and this is my first apex trigger. I am writing a trigger to insert values from a custom object (ST__C) into account fields based on account country and postcode. There is no link between the two objects therefore the trigger needs loop through ST__c and find a match for the (string) variable account.billingcountry+account.billingpostcode.

 

I hit the limit SOQL queries issue if the batch size in dataloader is greater than 100.

 

I need help in making the code more efficient or setting a batch limit to 100 on the trigger (can we limit batch sizes triggers?

Thanks

 

trigger Assign_Sales_Rep on Account (before insert, before update) {
 // Grab Terriory information based on CountryPostcode
    map<String, String> map_CountryPostcode_to_SalesRepCS = new map<String, String>();
    map<String, String> map_CountryPostcode_to_SalesRepM = new map<String, String>();
    
    string AccCountryPostcode = ''; 

  for (Account sAccount : trigger.new)
  {
  	  	
        if (sAccount.BillingPostalCode == null || sAccount.BillingPostalCode == '' || sAccount.BillingPostalCode == ' ' || sAccount.BillingCountry == Null || sAccount.BillingCountry == '' || sAccount.BillingCountry == ' ')
           {
              //sAccount.ShippingPostalCode.AddError('Billing Postal Code OR Billing Country can not be null');
           }
           else 
			{
				  	
        AccCountryPostcode = sAccount.BillingCountry+sAccount.BillingPostalCode;
		System.debug('***********'+AccCountryPostcode);
    
    
		    for (Sale_Territory__c [] li_Sale_Territory: [ select CountryPostcode__c,
                                            Sales_Rep_CS__c,
                                            Sales_Rep_M__c
                                        from Sale_Territory__c
                                        where CountryPostcode__c = :AccCountryPostcode
                                        ]) 
    		{
        		for(Sale_Territory__c sSale_Territory : li_Sale_Territory)
        		{
            		map_CountryPostcode_to_SalesRepCS.put(sSale_Territory.CountryPostcode__c, sSale_Territory.Sales_Rep_CS__c);
            		map_CountryPostcode_to_SalesRepM.put(sSale_Territory.CountryPostcode__c, sSale_Territory.Sales_Rep_M__c);
		        }                               
		    }   
                if (map_CountryPostcode_to_SalesRepCS.containsKey(AccCountryPostcode))
                {
                    sAccount.Sales_Rep_CS__c = map_CountryPostcode_to_SalesRepCS.get(AccCountryPostcode);                   
                }
                else
                {
                    sAccount.Sales_Rep_CS__c ='FF';
                }
                if (map_CountryPostcode_to_SalesRepM.containsKey(AccCountryPostcode))
                {
                    sAccount.Sales_Rep_M__c = map_CountryPostcode_to_SalesRepM.get(AccCountryPostcode);                
                }
                else
                {
                    sAccount.Sales_Rep_M__c ='';
                }
           }           
    }
    
}

 

  • July 30, 2012
  • Like
  • 0

Hi All,

I'm a new coder and this is my first trigger. I am trying to match a field on the custom object with accounts on insert and update. I get save error on "Method does not exist or incorrect signature: map_CountryPostcode_to_SalesRepSC.containsKey(String)" I have underlined the line where the error occurs.

 

What I am trying to do is match the CountryPostcode field in custom object Sales_territory with concatenated account billing country and account billing postcode.

 

Thanks for your help!

 

 

trigger Assign_Sales_Rep on Account (before insert, before update) {

 // Grab Terriory information based on CountryPostcode
 	map<String, String> map_CountryPostcode_to_SalesRepCS = new map<String, String>();
 	map<String, String> map_CountryPostcode_to_SalesRepM = new map<String, String>();
 	
 	string AccCountryPostcode = '';	

	for (Sale_Territory__c [] li_Sale_Territory: [ select CountryPostcode__c,
											Sales_Rep_CS__c,
											Sales_Rep_M__c
										from Sale_Territory__c
										]) 
	{
		for(Sale_Territory__c sSale_Territory : li_Sale_Territory)
		{
			map_CountryPostcode_to_SalesRepCS.put(sSale_Territory.CountryPostcode__c, sSale_Territory.Sales_Rep_CS__c);
			map_CountryPostcode_to_SalesRepM.put(sSale_Territory.CountryPostcode__c, sSale_Territory.Sales_Rep_M__c);
			
		}								
	}
	
	
    for (Account sAccount : trigger.new)
    {
    	AccCountryPostcode = 'sAccount.BillingCountry'+'sAccount.BillingPostalCode';
    	if (sAccount.BillingPostalCode == null || sAccount.BillingPostalCode == '' || sAccount.BillingPostalCode == ' ' || sAccount.BillingCountry = Null || sAccount.BillingCountry = '' ||sAccount.BillingCountry = ' ')
           {
              //sAccount.ShippingPostalCode.AddError('Billing Postal Code OR Billing Country can not be null');
           }
           else 
           {
           		if (map_CountryPostcode_to_SalesRepSC.containsKey(AccCountryPostcode))
           		{
           			sAccount.Sales_Rep_CS__c = map_CountryPostcode_to_SalesRepCS.get(AccCountryPostcode);       			
           		}
           		else
           		{
           			sAccount.Sales_Rep_CS__c ='';
           		}
           		if (map_CountryPostcode_to_SalesRepM.containsKey(AccCountryPostcode))
           		{
           			sAccount.Sales_Rep_M__c = map_CountryPostcode_to_SalesRepSC.get(AccCountryPostcode);       			
           		}
           		else
           		{
           			sAccount.Sales_Rep_M__c ='';
           		}
           }           
    }


}

 

 

  • July 13, 2012
  • Like
  • 0

I am trying to create a validation rule that should be basic but is not firing for me.

 

I have a picklist called  Prefix__c that has several values in it,

 

I want to fire if PICVAL is = to "Maintenance (CMT)", or "Maintenance Renewal (CMR)" and the custom date field of Maintenance_Start_Date__c is blank so that the date field becomes required,

 

This is what I have in place now, that is not working

 

AND(OR(ISPICKVAL(Prefix__c, "Maintenance (CMT)"),ISPICKVAL(Prefix__c, "Maintenance Renewal (CMR)")),ISBLANK(Maintenance_Start_Date__c))

 

Any assistance would be appreciated..

  • September 17, 2012
  • Like
  • 0

Hi,

 

I created an analytic snapshot report. The source report has 10 rows and only  5 rows are transferred to target object.

Message was sucessfull in snapshot history and interestingly I found message there that source report contains 5 rows only. Actually there are 10 rows in the source report.

Can any one please provide any pointers on this issue?

 

Thanks,

Babu

  • August 24, 2012
  • Like
  • 0

Hi All,

 

I need help with the below test class (trigger code below). It's my first trigger. I am trying to test an insert (for now) and it seems like my trigger is not working. However my trigger works when I insert/update in Salesforce and bulk insert/update using dataloader. Why does the test class fail to populate the Sales_Rep_CS__c field?

 

Thanks

 

Update: The test results in a Failure: "Assertion Failed: Expected: null, Actual: Julien Trapes"

@isTest
private class AssignSaleRep_Test_Class {

	static testMethod void Test1_TestInsertWithcountryValue() {
		list <Account> liacc = new list <Account>{};
		string SR_CS;
		Account a1 = new Account();
		a1.name = 'PRSingleTest';
		a1.BillingCountry= 'France';
		a1.BillingPostalCode = '59008';
		a1.Sales_Rep_CS__c ='F';
      	a1.Sales_Rep_M__c ='';
		system.debug('^^^^^^^^^^**********^^^^^'+a1);
		liacc.add(a1);
		insert liacc;
	
		list<Account> ia = [select name, sales_rep_cs__c from Account where id IN :liacc];
		for(Account s1 : ia)
		{
			system.debug('!!!!!!!!!!!!!!!!!!!!!'+s1.Sales_Rep_CS__c);
			system.assertEquals(s1.Sales_Rep_CS__c, 'Julien Trapes');
		}
	}
}

 

The Trigger:

trigger Assign_Sales_Rep on Account (before insert, before update) 
{
	// Grab Terriory information based on CountryPostcode
    map<String, String> map_CountryPostcode_to_SalesRepCS = new map<String, String>();
    map<String, String> map_CountryPostcode_to_SalesRepM = new map<String, String>();
    
    string AccCountryPostcode = ''; 
	List<String> postalCodes = new List<String>();
	List<Account> accList = new List<Account>();
	
	for (Account acc : trigger.new)
	{
		if (acc.BillingPostalCode == null || acc.BillingPostalCode == '' || acc.BillingPostalCode == ' ' || acc.BillingCountry == Null || acc.BillingCountry == '' || acc.BillingCountry == ' ')
	    {
	    }
		else
		{
			accList.add(acc);
			AccCountryPostcode = acc.BillingCountry+acc.BillingPostalCode;
			postalCodes.add(AccCountryPostcode);
		}
  	
	}
	
	for(Sale_Territory__c st : [SELECT CountryPostcode__c, Sales_Rep_CS__c, Sales_Rep_M__c FROM Sale_Territory__c WHERE CountryPostcode__c IN :postalCodes])
	{
		map_CountryPostcode_to_SalesRepCS.put(st.CountryPostcode__c, st.Sales_Rep_CS__c);
        map_CountryPostcode_to_SalesRepM.put(st.CountryPostcode__c, st.Sales_Rep_M__c);
        system.debug('&&&&&&&&&&&'+map_CountryPostcode_to_SalesRepCS);
	}
	
	for(Account act : accList)
	{
		if (map_CountryPostcode_to_SalesRepCS.containsKey(AccCountryPostcode))
		{
			act.Sales_Rep_CS__c = map_CountryPostcode_to_SalesRepCS.get(AccCountryPostcode);      
			system.debug('@@@@@@@'+act.Sales_Rep_CS__c);             
		}
		else
		{
			act.Sales_Rep_CS__c ='';
		}
		
		if (map_CountryPostcode_to_SalesRepM.containsKey(AccCountryPostcode))
		{
			act.Sales_Rep_M__c = map_CountryPostcode_to_SalesRepM.get(AccCountryPostcode);                
		}
		else
		{
			act.Sales_Rep_M__c ='';
		}
	}
}

 

  • July 31, 2012
  • Like
  • 0

Hi All,

I am new to programming and this is my first apex trigger. I am writing a trigger to insert values from a custom object (ST__C) into account fields based on account country and postcode. There is no link between the two objects therefore the trigger needs loop through ST__c and find a match for the (string) variable account.billingcountry+account.billingpostcode.

 

I hit the limit SOQL queries issue if the batch size in dataloader is greater than 100.

 

I need help in making the code more efficient or setting a batch limit to 100 on the trigger (can we limit batch sizes triggers?

Thanks

 

trigger Assign_Sales_Rep on Account (before insert, before update) {
 // Grab Terriory information based on CountryPostcode
    map<String, String> map_CountryPostcode_to_SalesRepCS = new map<String, String>();
    map<String, String> map_CountryPostcode_to_SalesRepM = new map<String, String>();
    
    string AccCountryPostcode = ''; 

  for (Account sAccount : trigger.new)
  {
  	  	
        if (sAccount.BillingPostalCode == null || sAccount.BillingPostalCode == '' || sAccount.BillingPostalCode == ' ' || sAccount.BillingCountry == Null || sAccount.BillingCountry == '' || sAccount.BillingCountry == ' ')
           {
              //sAccount.ShippingPostalCode.AddError('Billing Postal Code OR Billing Country can not be null');
           }
           else 
			{
				  	
        AccCountryPostcode = sAccount.BillingCountry+sAccount.BillingPostalCode;
		System.debug('***********'+AccCountryPostcode);
    
    
		    for (Sale_Territory__c [] li_Sale_Territory: [ select CountryPostcode__c,
                                            Sales_Rep_CS__c,
                                            Sales_Rep_M__c
                                        from Sale_Territory__c
                                        where CountryPostcode__c = :AccCountryPostcode
                                        ]) 
    		{
        		for(Sale_Territory__c sSale_Territory : li_Sale_Territory)
        		{
            		map_CountryPostcode_to_SalesRepCS.put(sSale_Territory.CountryPostcode__c, sSale_Territory.Sales_Rep_CS__c);
            		map_CountryPostcode_to_SalesRepM.put(sSale_Territory.CountryPostcode__c, sSale_Territory.Sales_Rep_M__c);
		        }                               
		    }   
                if (map_CountryPostcode_to_SalesRepCS.containsKey(AccCountryPostcode))
                {
                    sAccount.Sales_Rep_CS__c = map_CountryPostcode_to_SalesRepCS.get(AccCountryPostcode);                   
                }
                else
                {
                    sAccount.Sales_Rep_CS__c ='FF';
                }
                if (map_CountryPostcode_to_SalesRepM.containsKey(AccCountryPostcode))
                {
                    sAccount.Sales_Rep_M__c = map_CountryPostcode_to_SalesRepM.get(AccCountryPostcode);                
                }
                else
                {
                    sAccount.Sales_Rep_M__c ='';
                }
           }           
    }
    
}

 

  • July 30, 2012
  • Like
  • 0

Hi Folks,

 

I have excel file having 200 records and deleted 150 records. while uploading the data using data loader it is still showing 200 records. but when i open the excel file it is showing only 50 records.

 

what is the issue here, can any one suggest on this ASAP

 

 

Thanks,

Krish

Hello All,

I am trying to create a formula field of type text, which depends on two other picklist fields. For Example If picklist field "Timing__c" = "Thursday Readiness" and if other Picklist field "Result__c" is either "Empty", "Ready," "Major Work", "Minor Work" , then the formula field should show Yes, else it should show up as No.

 

 

IF (ISPICKVAL( Timing__c, "Thursday Readiness") & ISPICKVAL( Result__c , "") ) ,"Yes", "No")

 

Any Suggesstions?

Hi All,

I'm a new coder and this is my first trigger. I am trying to match a field on the custom object with accounts on insert and update. I get save error on "Method does not exist or incorrect signature: map_CountryPostcode_to_SalesRepSC.containsKey(String)" I have underlined the line where the error occurs.

 

What I am trying to do is match the CountryPostcode field in custom object Sales_territory with concatenated account billing country and account billing postcode.

 

Thanks for your help!

 

 

trigger Assign_Sales_Rep on Account (before insert, before update) {

 // Grab Terriory information based on CountryPostcode
 	map<String, String> map_CountryPostcode_to_SalesRepCS = new map<String, String>();
 	map<String, String> map_CountryPostcode_to_SalesRepM = new map<String, String>();
 	
 	string AccCountryPostcode = '';	

	for (Sale_Territory__c [] li_Sale_Territory: [ select CountryPostcode__c,
											Sales_Rep_CS__c,
											Sales_Rep_M__c
										from Sale_Territory__c
										]) 
	{
		for(Sale_Territory__c sSale_Territory : li_Sale_Territory)
		{
			map_CountryPostcode_to_SalesRepCS.put(sSale_Territory.CountryPostcode__c, sSale_Territory.Sales_Rep_CS__c);
			map_CountryPostcode_to_SalesRepM.put(sSale_Territory.CountryPostcode__c, sSale_Territory.Sales_Rep_M__c);
			
		}								
	}
	
	
    for (Account sAccount : trigger.new)
    {
    	AccCountryPostcode = 'sAccount.BillingCountry'+'sAccount.BillingPostalCode';
    	if (sAccount.BillingPostalCode == null || sAccount.BillingPostalCode == '' || sAccount.BillingPostalCode == ' ' || sAccount.BillingCountry = Null || sAccount.BillingCountry = '' ||sAccount.BillingCountry = ' ')
           {
              //sAccount.ShippingPostalCode.AddError('Billing Postal Code OR Billing Country can not be null');
           }
           else 
           {
           		if (map_CountryPostcode_to_SalesRepSC.containsKey(AccCountryPostcode))
           		{
           			sAccount.Sales_Rep_CS__c = map_CountryPostcode_to_SalesRepCS.get(AccCountryPostcode);       			
           		}
           		else
           		{
           			sAccount.Sales_Rep_CS__c ='';
           		}
           		if (map_CountryPostcode_to_SalesRepM.containsKey(AccCountryPostcode))
           		{
           			sAccount.Sales_Rep_M__c = map_CountryPostcode_to_SalesRepSC.get(AccCountryPostcode);       			
           		}
           		else
           		{
           			sAccount.Sales_Rep_M__c ='';
           		}
           }           
    }


}

 

 

  • July 13, 2012
  • Like
  • 0
The following formula will calculate the number of working days (inclusive) between 2 dates. A working day is defined as Monday to Friday. Even if the start or end dates are a weekend, these are accommodated.

IF(AND((5 - (CASE(MOD( Start_Date__c - DATE(1900, 1, 6), 7), 0, 0, 1, 5, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0)) < (CASE(MOD(  End_Date__c  - DATE(1900, 1, 6), 7), 0, 0, 1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 0)) ),
((( End_Date__c  -   Start_Date__c ) + 1) < 7)),
((CASE(MOD(  End_Date__c  - DATE(1900, 1, 6), 7), 0, 0, 1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 0)) - (5 - (CASE(MOD(  Start_Date__c  - DATE(1900, 1, 6), 7), 0, 0, 1, 5, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0)))),
(((FLOOR((( End_Date__c  -  Start_Date__c ) - (CASE(MOD(  Start_Date__c  - DATE(1900, 1, 6), 7), 0, 0, 1, 6, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0))) / 7)) * 5) +
(CASE(MOD(  Start_Date__c  - DATE(1900, 1, 6), 7), 0, 0, 1, 5, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0)) +
(CASE(MOD(  End_Date__c  - DATE(1900, 1, 6), 7), 0, 0, 1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 0))))


The Start Date and End Date fields are custom in the above example and can be replaced as required. If use of a DateTime field is required then the DATEVALUE function will be required.

I also recommend a simple field validation rule is added to check that the End Date is after the Start Date.
  • January 05, 2009
  • Like
  • 9