• SF94108
  • NEWBIE
  • 0 Points
  • Member since 2011

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

I have a before insert and update trigger that updates two writeable fields in the account based on custom setting fields. When I test manually, the trigger works. However, my test code is failing. The account name is saving but the trigger to update continent and region doesn't seem to run. I added start test and stop test around inserting the accounts but that doesn't seem to help. How do I ensure the trigger runs and updates the account a3? 

 

@isTest
private class Test_AccountTrigger {

    static testMethod void test() {


       //create 2 accounts -  billing country not in list, billing country in list
        Account a2 = new Account();
        a2.Name = 'invalid country';
        a2.billingcountry='alsdkfjasd;if';
        a2.industry = 'Agency';
        a2.Annual_company_revenue__c = 'under $100M';

        Account a3 = new Account();
        a3.Name = 'valid country';
        a3.billingcountry='Germany';
        a3.industry = 'Agency';        
        a3.Annual_company_revenue__c = 'under $100M';

        
        Test.startTest();  
                insert a2;    
                insert a3;
        Test.stopTest();
                  
                
        // Query the newly inserted records
        Account aa2 = [Select Name, Continent__c, Region1__c FROM Account where Id = :a2.Id];
        Account aa3 = [Select Name, Continent__c, Region1__c FROM Account where Id = :a3.Id];
        System.debug('aa2 ' + aa2.Name + ' continent = ' + aa2.Continent__c);
        System.debug('aa3 ' + aa3.Name + ' continent = ' + aa3.Continent__c);

        // If the trigger works, then territory and region will only be set on last account
        System.assertEquals(null, aa2.Continent__c);
        System.assertEquals(null, aa2.Region1__c);
        System.assertEquals('Europe',aa3.Continent__c);
        System.assertEquals('EMEA', aa3.Region1__c);
       

    }
}

 

 

Trying to write (my first) trigger to pull from a picklist field on the Contact to a duplicate picklist on a Task field.

Contact field info is 

Field Label: SOI

Object Name: Contact

Field Name: SOI

Data Type: Picklist

API Name: SOI__c

 

Task Field Info is

Field Label: Contact's SOI

Object Name: Activity

Field Name: Contacts_SOI

Data Type: Picklist

API Name: Contacts_SOI__c

 

I currently receive the error message:

Error: Compile Error: Incompatible key type Schema.SObjectField for MAP<Id,LIST<Task>> at line 6 column 20
 

 

The code that I am trying to use is:

 

Trigger TaskBefore on Task(before insert, before update){
Map<Id, List<Task>> whoIds = new Map<Id, List<Task>>{};
For (Task t : trigger.new)
If(t.WhoId != null){
List<Task> tasks = whoIds.get(task.WhoId);
If (tasks == null){
tasks = new List<Task>{};
whoIds.put(t.WhoId, tasks);
}
tasks.add(t);
}
For(Contact con : [Select Id, Name,SOI__c from Contact where Id in :whoIds.keySet()])
For(Task t : whoIds.get(con.id))

t.contacts_SOI__c = con.SOI__c;}

 

Please help!

 

 

Hi,

 

I created this trigger:

 

trigger CriarTarefa_Produtos_Cobranca on Task (after update) {

    List<Task> taskProd = new List<Task>();
    for (Task tt : Trigger.new)
    if (tt.subject == 'Cobrança - Problemas com produtos' && tt.status == 'Concluído' || tt.subject == 'Cobrança - Pergunta não solucionada' && tt.status == 'Concluído'){
                taskProd.add (new Task(
                         Subject = 'Cobrança - Questão solucionada?',
                         Status = 'Nenhum',
                         WhatID = tt.WhatID,
                         Description = tt.description,
                    	 OwnerId = '005U0000001KrXY',
                         ActivityDate = Date.today()));
 }

    for (Task tt : Trigger.new)
    if (tt.subject == 'Cobrança - Questão solucionada?' && tt.Quest_o_solucionada__c == 'SIM' && tt.status == 'Concluído'){
                taskProd.add (new Task(
                         Subject = 'Cobrança - Feche o chamado e notifique o formando',
                         Status = 'Nenhum',
                         WhatID = tt.WhatID,
                         Description = tt.description,
                    	 OwnerId = '005U0000001KrXY',
                         ActivityDate = Date.today()));
 }
    for (Task tt : Trigger.new)
    if (tt.subject == 'Cobrança - Questão solucionada?' && tt.Quest_o_solucionada__c == 'NÃO' && tt.status == 'Concluído'){
                taskProd.add (new Task(
                         Subject = 'Cobrança - Pergunta não solucionada',
                         Status = 'Nenhum',
                         WhatID = tt.WhatID,
                         Description = tt.description,
                    	 OwnerId = '005U0000000FrCz',
                         ActivityDate = Date.today()));
 }
                insert taskProd;
            }

 And my test class:

 

@IsTest(SeeAllData=true)
public class CriarTarefa_Pendencia_Duomind_test{
static testmethod void MyUnitTest(){
    
 
     User u = [select id from User where LastName='Marketing'];
      
     Case c = new Case (recordtypeid='012U000000011yC');
    
     Task tsk  = new Task(Status='Não iniciado', Priority='Normal', subject='- Iniciador do Fluxo -');
     insert tsk;
 
    tsk.Status = 'Concluído';
    update tsk;
}
}

 

My code coverage is in 74%.

What I'm missing here?

 

Any help?

 

Thanks !

Hi everyone,

 

 I have ti generate a guid using formula field in salesforce.

 

Any idea.please let me know.

 

Thanks in advance

Need to do a simple total of values from a query. Some database numeric fields do not have a value.

 

here's the code snippet-

trigger.new[i].total_Amount__c = Trigger.new[i].meals_cost__C +Trigger.new[i].Admin_Fee__c;

 

in this case admin_fee__C is not applicable so has null value(its a numeric field)

 

Tried most functions to get around the issue - how do I get the total working?

 

Thanks much.

 

included below is a summary of my various attempts!

 

trigger.new[i].total_Amount__c = Trigger.new[i].meals_cost__C + NULLVALUE(Trigger.new[i].Admin_Fee__c,0);

Error:
Method does not exist or incorrect signature: NULLVALUE(Decimal, Integer) at line 47 column 71


tried replacing with decimal with following local variable
decimal replaceNULL=0;
trigger.new[i].total_Amount__c = Trigger.new[i].meals_cost__C + NULLVALUE(Trigger.new[i].Admin_Fee__c,replaceNULL);
     
Error:
Method does not exist or incorrect signature: NULLVALUE(Decimal, Decimal) at line 48 column 71

same with blankvalue
trigger.new[i].total_Amount__c = Trigger.new[i].meals_cost__C + BLANKVALUE(Trigger.new[i].Admin_Fee__c,replaceNULL);

error:
Method does not exist or incorrect signature: BLANKVALUE(Decimal, Decimal) at line 48 column 71

 

if (ISNULL(Trigger.new[i].Admin_Fee__c) ) {Trigger.new[i].Admin_Fee__c=0;}

--Error:
--Method does not exist or incorrect signature: ISNULL(Decimal) at line 45 column 11

if (ISBLANK(Trigger.new[i].Admin_Fee__c) ) {Trigger.new[i].Admin_Fee__c=0;}
--similar error


also tried using len(fieldname) <1 to check if null - does not work