• AribaGalaxy
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies

Last week I worked on my first trigger - I got some help here on finishing it but now I am lost on how to test it. So far all I have done is created two accounts with which I think I need to create a partnership and then a task to test, but I am not sure how to go about this. Most of what I have is based on "how-tos" and the structure of other triggers; I'm not a developer by trade but I am trying to learn. I'm not looking for the work to be done (though I wouldn't turn it down) as much as I am looking for a starting point...

 

Any help is greatly appreciated.

Trigger:

trigger JWGetAssociations on Task (after insert, after update) {
if(FutureTriggerController.isFutureUpdate != true){

FutureTriggerController.isFutureUpdate =true;
Map<Id, Id> TaskToAccountMap = new Map<Id, Id>();
Map<Id, Id> AcctToPartnerMap = new Map<Id, Id>();
Map<Id, Account> PartnerResponseMap = new Map<Id, Account>();
List<Task> tListToBeUpdated = new List<Task>();
for(Task jwtask : [SELECT Id, AccountID FROM Task WHERE ID in: trigger.new]){
TaskToAccountMap.put(jwtask.id, jwtask.AccountId);
}

list <Id> partner1 = new list <Id>();
for(Partner partner : [SELECT Id, AccountToId, AccountFromId FROM Partner WHERE AccountFromId in: TaskToAccountMap.values()]){

AcctToPartnerMap.put(partner.AccountToId , partner.AccountToId);
}
for(Account part : [SELECT Id, Name FROM Account WHERE ID in: AcctToPartnerMap.values()]){
PartnerResponseMap.put(part.ID, part);
}

for(Task o : trigger.new){
Id acctid = TaskToAccountMap.get(o.Id);
list <String> partnerAcc = new list <String>();
for( id Accid : AcctToPartnerMap.keyset()){
Account acc = PartnerResponseMap.get(Accid);
partnerAcc.add(acc.Name+'\n');
partnerAcc.add('\n\n');
}
for(integer i=0;i<partnerAcc.size();i++){
}
Task t = new task(Id = o.Id);
if(t.jw_Associated_Distributors__c == null){
t.jw_Associated_Distributors__c = '';
for(integer i=0;i< partnerAcc.size();i++){
t.jw_Associated_Distributors__c += partnerAcc[i];
}
}
tListToBeUpdated.add(t);
}
if(tListToBeUpdated.size()>0){
upsert tListToBeUpdated;
}
}
}

 FutureTriggerController class code: 

public class FutureTriggerController{
public static boolean isFutureUpdate = false;
}

 

Thus far; my test class looks like this. I know it's far from done and I am not sure if I am even starting off right.

@isTest  
private class testClass_Trigger{  
      private static TestMethod void JWGetAssociations(){  
         Account jwacct1 = new Account(name='TestAccount1');
            insert jwacct1;
         Account jwacct2 = new Account(name='TestAccount2');
            insert jwacct2;
    }  
  
  
}

 

We're working on our first trigger. I am trying to update a custom field in TASK with a list of Partner accounts related to the account the task is being created for. The code below works if I update a task, but it does not work upon creation of a new task. I tried to execute the trigger after update but received a read only error.

 

Any help is greatly appreciated. We're working on this in the free version of developer force if that matters.

 

trigger JWGetAssociations on Task (before insert, before update) {
    
    Map<Id, Id> TaskToAccountMap = new Map<Id, Id>();
    Map<Id, Id> AcctToPartnerMap = new Map<Id, Id>();
    Map<Id, Account> PartnerResponseMap = new Map<Id, Account>();

    for(Task jwtask : [SELECT Id, AccountID FROM Task WHERE ID in: trigger.new]){
        TaskToAccountMap.put(jwtask.id, jwtask.AccountId);
    }
    
    list <Id> partner1 = new list <Id>();
    for(Partner partner : [SELECT Id, AccountToId, AccountFromId FROM Partner WHERE AccountFromId in: TaskToAccountMap.values()]){
     
        AcctToPartnerMap.put(partner.AccountToId , partner.AccountToId);
    } 

    for(Account part : [SELECT Id, Name FROM Account WHERE ID in: AcctToPartnerMap.values()]){
        PartnerResponseMap.put(part.ID, part);
    }
    
    for(Task o : trigger.new){

        Id acctid = TaskToAccountMap.get(o.Id);

         list <String> partnerAcc = new list <String>(); 
         for( id Accid : AcctToPartnerMap.keyset()){
             Account acc = PartnerResponseMap.get(Accid);
             partnerAcc.add(acc.Name+'\n');
             partnerAcc.add('\n\n');
         }
         for(integer i=0;i<partnerAcc.size();i++){
         }
)
            if(o.jw_Associated_Distributors__c == null){
                o.jw_Associated_Distributors__c = '';
               for(integer i=0;i< partnerAcc.size();i++){
                       o.jw_Associated_Distributors__c += partnerAcc[i];  
                }
        }
    } 
}

 

Last week I worked on my first trigger - I got some help here on finishing it but now I am lost on how to test it. So far all I have done is created two accounts with which I think I need to create a partnership and then a task to test, but I am not sure how to go about this. Most of what I have is based on "how-tos" and the structure of other triggers; I'm not a developer by trade but I am trying to learn. I'm not looking for the work to be done (though I wouldn't turn it down) as much as I am looking for a starting point...

 

Any help is greatly appreciated.

Trigger:

trigger JWGetAssociations on Task (after insert, after update) {
if(FutureTriggerController.isFutureUpdate != true){

FutureTriggerController.isFutureUpdate =true;
Map<Id, Id> TaskToAccountMap = new Map<Id, Id>();
Map<Id, Id> AcctToPartnerMap = new Map<Id, Id>();
Map<Id, Account> PartnerResponseMap = new Map<Id, Account>();
List<Task> tListToBeUpdated = new List<Task>();
for(Task jwtask : [SELECT Id, AccountID FROM Task WHERE ID in: trigger.new]){
TaskToAccountMap.put(jwtask.id, jwtask.AccountId);
}

list <Id> partner1 = new list <Id>();
for(Partner partner : [SELECT Id, AccountToId, AccountFromId FROM Partner WHERE AccountFromId in: TaskToAccountMap.values()]){

AcctToPartnerMap.put(partner.AccountToId , partner.AccountToId);
}
for(Account part : [SELECT Id, Name FROM Account WHERE ID in: AcctToPartnerMap.values()]){
PartnerResponseMap.put(part.ID, part);
}

for(Task o : trigger.new){
Id acctid = TaskToAccountMap.get(o.Id);
list <String> partnerAcc = new list <String>();
for( id Accid : AcctToPartnerMap.keyset()){
Account acc = PartnerResponseMap.get(Accid);
partnerAcc.add(acc.Name+'\n');
partnerAcc.add('\n\n');
}
for(integer i=0;i<partnerAcc.size();i++){
}
Task t = new task(Id = o.Id);
if(t.jw_Associated_Distributors__c == null){
t.jw_Associated_Distributors__c = '';
for(integer i=0;i< partnerAcc.size();i++){
t.jw_Associated_Distributors__c += partnerAcc[i];
}
}
tListToBeUpdated.add(t);
}
if(tListToBeUpdated.size()>0){
upsert tListToBeUpdated;
}
}
}

 FutureTriggerController class code: 

public class FutureTriggerController{
public static boolean isFutureUpdate = false;
}

 

Thus far; my test class looks like this. I know it's far from done and I am not sure if I am even starting off right.

@isTest  
private class testClass_Trigger{  
      private static TestMethod void JWGetAssociations(){  
         Account jwacct1 = new Account(name='TestAccount1');
            insert jwacct1;
         Account jwacct2 = new Account(name='TestAccount2');
            insert jwacct2;
    }  
  
  
}

 

We're working on our first trigger. I am trying to update a custom field in TASK with a list of Partner accounts related to the account the task is being created for. The code below works if I update a task, but it does not work upon creation of a new task. I tried to execute the trigger after update but received a read only error.

 

Any help is greatly appreciated. We're working on this in the free version of developer force if that matters.

 

trigger JWGetAssociations on Task (before insert, before update) {
    
    Map<Id, Id> TaskToAccountMap = new Map<Id, Id>();
    Map<Id, Id> AcctToPartnerMap = new Map<Id, Id>();
    Map<Id, Account> PartnerResponseMap = new Map<Id, Account>();

    for(Task jwtask : [SELECT Id, AccountID FROM Task WHERE ID in: trigger.new]){
        TaskToAccountMap.put(jwtask.id, jwtask.AccountId);
    }
    
    list <Id> partner1 = new list <Id>();
    for(Partner partner : [SELECT Id, AccountToId, AccountFromId FROM Partner WHERE AccountFromId in: TaskToAccountMap.values()]){
     
        AcctToPartnerMap.put(partner.AccountToId , partner.AccountToId);
    } 

    for(Account part : [SELECT Id, Name FROM Account WHERE ID in: AcctToPartnerMap.values()]){
        PartnerResponseMap.put(part.ID, part);
    }
    
    for(Task o : trigger.new){

        Id acctid = TaskToAccountMap.get(o.Id);

         list <String> partnerAcc = new list <String>(); 
         for( id Accid : AcctToPartnerMap.keyset()){
             Account acc = PartnerResponseMap.get(Accid);
             partnerAcc.add(acc.Name+'\n');
             partnerAcc.add('\n\n');
         }
         for(integer i=0;i<partnerAcc.size();i++){
         }
)
            if(o.jw_Associated_Distributors__c == null){
                o.jw_Associated_Distributors__c = '';
               for(integer i=0;i< partnerAcc.size();i++){
                       o.jw_Associated_Distributors__c += partnerAcc[i];  
                }
        }
    } 
}