• frofrik2
  • NEWBIE
  • 0 Points
  • Member since 2011

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

I have the following code in one of my classes:


if(adwc != null) {
       adwc.Used__c = true;
       adwc.Used_Time__c = datetime.now();
       update adwc;        
}

 

When trying to sace I just get the error "Variable does not exist: adwc" on the line with "update adwc;".

 

Any ideas why I get this error, the check is done to avoid this?



Hi all,

 

I have created a test method for one of my triggers.
First it creates an account with a related opportunity. 
But when I'm trying to access one of the custom fields on the account through the opportunity, it only returns null.

 

This is the code I'm having trouble with:

 

 

        Account a = new Account(Name='testkonto',Status__c='Live',Store_ID__c='999999',
        CurrencyIsoCode='SEK',Country__c='Sweden',Industry='Art and Design');
        insert a;
        
        Opportunity o = new Opportunity(Name='Opp1',Account=a,StageName='Contract Sent',
        CloseDate=Date.newInstance(2011, 07, 15), Pricing_is_approved__c=1, Country2__c='Sweden',
        CurrencyIsoCode='SEK');
        insert o;
        
        a.Approval_Status__c = 'Sent for approval';  
        
        Test.startTest();
    	update a;
    	Test.stopTest();

        
        system.debug('account id: '+a.Id);
        system.debug('account approval status: '+a.Approval_Status__c);
        system.debug('account country: '+a.Country__c);
        system.debug('opp account id: '+o.Account.Id);
        system.debug('opp account name: '+o.Account.Name);
        system.debug('opp account approval status: '+o.Account.Approval_Status__c);
        system.debug('opp account country: '+o.Account.Country__c);

 

 

The field Approval_Status__c is returning null when accessing it through o.Account, but 'Sent for approval' when accessed directly.

 

Any ideas?

Hi,

I'm having problems with a test class that fails on a validation rule even when it shouldn't.
When running it, it's failing with the following reason: 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, mapOwnerInfoToAccount: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 0012000000e1kjCAAQ; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Store-ID can not be populated when Status is set to Prospecting. You need to choose the status Test Mode or Live.: [Status__c] Trigger.mapOwnerInfoToAccount: line 150, column 2: []


But in the test case, the Status__c is set to Live, so it shouldn't be a problem.
Though when I look through the log of the test case it seems to pass first and then it just fails, can't understand why.
Copied a part of the log:

11:51:59.049|WF_ACTIONS_END| None
11:51:59.049|CODE_UNIT_FINISHED|Workflow:Account
11:51:59.051|DML_END|[150]
11:51:59.051|VF_PAGE_MESSAGE|Store-ID can not be populated when Status is set to Prospecting. You need to choose the status Test Mode or Live.
11:51:59.052|EXCEPTION_THROWN|[150]|System.DmlException: Update failed. First exception on row 0 with id 0012000000e1kjCAAQ; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Store-ID can not be populated when Status is set to Prospecting. You need to choose the status Test Mode or Live.: [Status__c]
11:51:59.058|FATAL_ERROR|System.DmlException: Update failed. First exception on row 0 with id 0012000000e1kjCAAQ; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Store-ID can not be populated when Status is set to Prospecting. You need to choose the status Test Mode or Live.: [Status__c]

 

Some code from the test class:

 

 

Account a1 = new Account(Name='testkonto',
        CurrencyIsoCode='SEK',Country__c='Sweden',Industry='Art and Design');
        insert a1;
        a1.Status__c = 'Live';
        a1.Store_ID__c='9999';
        update a1;

 

And here's the trigger that I'm testing:

 

 

trigger mapOwnerInfoToAccount on Account_Owner_Info__c (after insert, after update) {

	List<String> storeids = new List<String>();
	Map<String, Account_Owner_Info__c> aoifs = new Map<String, Account_Owner_Info__c>();

	for(Integer i = 0; i < Trigger.new.size();i++)
	{
		if(Trigger.new[i].EID__c <> '')
		{
			storeids.add(Trigger.new[i].EID__c);
			aoifs.put(Trigger.new[i].EID__c, Trigger.new[i]);
		}
	}
	
	List<Account> accounts = [
	SELECT
		Id,
		EOI_Agree_with_pno__c,
		EOI_Number_of_Owners__c,
		EOI_Orgno__c,
		EOI_Owner_1_First_Name__c,
		EOI_Owner_1_Last_Name__c,
		EOI_Owner_1_Pno__c,
		EOI_Owner_2_First_Name__c,
		EOI_Owner_2_Last_Name__c,
		EOI_Owner_2_Pno__c,
		EOI_Submitter_name__c,
		EOI_Submitter_Pno__c,
		Store_ID__c,
		Status__c
	FROM
		Account
	WHERE
		Store_ID__c IN :storeids
	];
	
	List<Account> accountsToUpdate = new List<Account>();
	
	for(Account a : accounts)
	{
		Account_Owner_Info__c ao = aoifs.get(a.Store_ID__c);
		if(a.EOI_Agree_with_Pno__c == null && a.EOI_Submitter_Pno__c == null)
		{
			a.EOI_Agree_with_Pno__c = ao.Agree_with_Pno__c;				
			a.EOI_Number_of_Owners__c = ao.Number_of_Owners__c;
			a.EOI_Orgno__c = ao.Orgno__c;
			
			a.EOI_Owner_1_First_Name__c = ao.Owner_1_First_Name__c;
			a.EOI_Owner_1_Last_Name__c = ao.Owner_1_Last_Name__c;
			a.EOI_Owner_1_Pno__c = ao.Owner_1_Pno__c;
			
			a.EOI_Owner_2_First_Name__c = ao.Owner_2_First_Name__c;
			a.EOI_Owner_2_Last_Name__c = ao.Owner_2_Last_Name__c;
			a.EOI_Owner_2_Pno__c = ao.Owner_2_Pno__c;
			
			a.EOI_Submitter_name__c = ao.Submitter_name__c;
			a.EOI_Submitter_Pno__c = ao.Submitter_Pno__c;
			
			accountsToUpdate.add(a);
			
		}
	}
	
	update accountsToUpdate;
}

(I removed some additional variables so line 150 is the one where the update is fired).

 

 

 

Could you guys maybe give me a clue about what the problem is?

Hi all,

 

I have created a test method for one of my triggers.
First it creates an account with a related opportunity. 
But when I'm trying to access one of the custom fields on the account through the opportunity, it only returns null.

 

This is the code I'm having trouble with:

 

 

        Account a = new Account(Name='testkonto',Status__c='Live',Store_ID__c='999999',
        CurrencyIsoCode='SEK',Country__c='Sweden',Industry='Art and Design');
        insert a;
        
        Opportunity o = new Opportunity(Name='Opp1',Account=a,StageName='Contract Sent',
        CloseDate=Date.newInstance(2011, 07, 15), Pricing_is_approved__c=1, Country2__c='Sweden',
        CurrencyIsoCode='SEK');
        insert o;
        
        a.Approval_Status__c = 'Sent for approval';  
        
        Test.startTest();
    	update a;
    	Test.stopTest();

        
        system.debug('account id: '+a.Id);
        system.debug('account approval status: '+a.Approval_Status__c);
        system.debug('account country: '+a.Country__c);
        system.debug('opp account id: '+o.Account.Id);
        system.debug('opp account name: '+o.Account.Name);
        system.debug('opp account approval status: '+o.Account.Approval_Status__c);
        system.debug('opp account country: '+o.Account.Country__c);

 

 

The field Approval_Status__c is returning null when accessing it through o.Account, but 'Sent for approval' when accessed directly.

 

Any ideas?

Hi,

I'm having problems with a test class that fails on a validation rule even when it shouldn't.
When running it, it's failing with the following reason: 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, mapOwnerInfoToAccount: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 0012000000e1kjCAAQ; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Store-ID can not be populated when Status is set to Prospecting. You need to choose the status Test Mode or Live.: [Status__c] Trigger.mapOwnerInfoToAccount: line 150, column 2: []


But in the test case, the Status__c is set to Live, so it shouldn't be a problem.
Though when I look through the log of the test case it seems to pass first and then it just fails, can't understand why.
Copied a part of the log:

11:51:59.049|WF_ACTIONS_END| None
11:51:59.049|CODE_UNIT_FINISHED|Workflow:Account
11:51:59.051|DML_END|[150]
11:51:59.051|VF_PAGE_MESSAGE|Store-ID can not be populated when Status is set to Prospecting. You need to choose the status Test Mode or Live.
11:51:59.052|EXCEPTION_THROWN|[150]|System.DmlException: Update failed. First exception on row 0 with id 0012000000e1kjCAAQ; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Store-ID can not be populated when Status is set to Prospecting. You need to choose the status Test Mode or Live.: [Status__c]
11:51:59.058|FATAL_ERROR|System.DmlException: Update failed. First exception on row 0 with id 0012000000e1kjCAAQ; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Store-ID can not be populated when Status is set to Prospecting. You need to choose the status Test Mode or Live.: [Status__c]

 

Some code from the test class:

 

 

Account a1 = new Account(Name='testkonto',
        CurrencyIsoCode='SEK',Country__c='Sweden',Industry='Art and Design');
        insert a1;
        a1.Status__c = 'Live';
        a1.Store_ID__c='9999';
        update a1;

 

And here's the trigger that I'm testing:

 

 

trigger mapOwnerInfoToAccount on Account_Owner_Info__c (after insert, after update) {

	List<String> storeids = new List<String>();
	Map<String, Account_Owner_Info__c> aoifs = new Map<String, Account_Owner_Info__c>();

	for(Integer i = 0; i < Trigger.new.size();i++)
	{
		if(Trigger.new[i].EID__c <> '')
		{
			storeids.add(Trigger.new[i].EID__c);
			aoifs.put(Trigger.new[i].EID__c, Trigger.new[i]);
		}
	}
	
	List<Account> accounts = [
	SELECT
		Id,
		EOI_Agree_with_pno__c,
		EOI_Number_of_Owners__c,
		EOI_Orgno__c,
		EOI_Owner_1_First_Name__c,
		EOI_Owner_1_Last_Name__c,
		EOI_Owner_1_Pno__c,
		EOI_Owner_2_First_Name__c,
		EOI_Owner_2_Last_Name__c,
		EOI_Owner_2_Pno__c,
		EOI_Submitter_name__c,
		EOI_Submitter_Pno__c,
		Store_ID__c,
		Status__c
	FROM
		Account
	WHERE
		Store_ID__c IN :storeids
	];
	
	List<Account> accountsToUpdate = new List<Account>();
	
	for(Account a : accounts)
	{
		Account_Owner_Info__c ao = aoifs.get(a.Store_ID__c);
		if(a.EOI_Agree_with_Pno__c == null && a.EOI_Submitter_Pno__c == null)
		{
			a.EOI_Agree_with_Pno__c = ao.Agree_with_Pno__c;				
			a.EOI_Number_of_Owners__c = ao.Number_of_Owners__c;
			a.EOI_Orgno__c = ao.Orgno__c;
			
			a.EOI_Owner_1_First_Name__c = ao.Owner_1_First_Name__c;
			a.EOI_Owner_1_Last_Name__c = ao.Owner_1_Last_Name__c;
			a.EOI_Owner_1_Pno__c = ao.Owner_1_Pno__c;
			
			a.EOI_Owner_2_First_Name__c = ao.Owner_2_First_Name__c;
			a.EOI_Owner_2_Last_Name__c = ao.Owner_2_Last_Name__c;
			a.EOI_Owner_2_Pno__c = ao.Owner_2_Pno__c;
			
			a.EOI_Submitter_name__c = ao.Submitter_name__c;
			a.EOI_Submitter_Pno__c = ao.Submitter_Pno__c;
			
			accountsToUpdate.add(a);
			
		}
	}
	
	update accountsToUpdate;
}

(I removed some additional variables so line 150 is the one where the update is fired).

 

 

 

Could you guys maybe give me a clue about what the problem is?