• mlf
  • NEWBIE
  • 0 Points
  • Member since 2013

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

Hi,

 

I'm trying to add a trigger to set a lookup field in Opportunity to point back to the Household.  I'm using 1x1 contact model.  To get to Household from Opportunity, I tried to:

  • get the Account from Opportunity
  • get the Contact from Account (since this is 1x1 model)
  • get the Household from Contact

The trigger code is pretty simple, but somehow the Account and Contact fields are always NULL.  Could you please help?

 

trigger setHouseholdOnOpportunity on Opportunity (before insert) {

    for (Opportunity opp : trigger.new) {
        System.debug('Account is ' + opp.Account);
        System.debug('Contact is ' + opp.Account.npe01__One2OneContact__c);
        if ((opp.Account != NULL) && (opp.Account.npe01__One2OneContact__c != NULL)) {
             System.debug('Contacts household is ' + opp.Account.npe01__One2OneContact__r.npo02__Household__c);
             opp.OppHousehold__c = opp.Account.npe01__One2OneContact__r.npo02__Household__c;
             System.debug('SetHouseholdOnOpp Opp Household is ' + opp.OppHousehold__c);
             update opp;
        }
    }
}

 

Thanks.  Thu :-)

  • April 18, 2013
  • Like
  • 0

Hi,

 

I'm totally green with Apex trigger, and this is my first stab at writing one.  I'm trying to add this Opportunity trigger on NPSP to assign a Designation to an Opportunity transaction when it's created.  The trigger is created from Setup->Customize->Opportunity->Trigger.  DonationDesignationRelationship is a custom object, which has a master-detail relationship with Opportunity.

 

When I hit "Quick Save", I got this error:

 

Error: Compile Error: Invalid type: DonationDesignationRelationship at line 5 column 57 

 

It might be something really straighforward, but somehow I can't figure out.  The code is pretty simple:

 

// Add Designation to a brand new Opportunity

trigger OpportunityAddDesignation on Opportunity (after insert) {    

 

  List<DonationDesignationRelationship> ddrs = new List<DonationDesignationRelationship>();    

  if (Trigger.isInsert && Trigger.isAfter) {    

    for (Opportunity opp: Trigger.new) {      

      if (opp.Amount > 0) {        

        ddrs.add(new DonationDesignationRelationship 

           (Amount = opp.Amount, Designation = a18U000000BOP4r, Opportunity = opp.Id));      

      }    

    }  

  }  

  insert ddrs;

 

}

 

I'd really appreciate any help or pointers to accomplish this.

 

Thanks!

 

 

  • February 07, 2013
  • Like
  • 0

Hi,

 

I'm trying to add a trigger to set a lookup field in Opportunity to point back to the Household.  I'm using 1x1 contact model.  To get to Household from Opportunity, I tried to:

  • get the Account from Opportunity
  • get the Contact from Account (since this is 1x1 model)
  • get the Household from Contact

The trigger code is pretty simple, but somehow the Account and Contact fields are always NULL.  Could you please help?

 

trigger setHouseholdOnOpportunity on Opportunity (before insert) {

    for (Opportunity opp : trigger.new) {
        System.debug('Account is ' + opp.Account);
        System.debug('Contact is ' + opp.Account.npe01__One2OneContact__c);
        if ((opp.Account != NULL) && (opp.Account.npe01__One2OneContact__c != NULL)) {
             System.debug('Contacts household is ' + opp.Account.npe01__One2OneContact__r.npo02__Household__c);
             opp.OppHousehold__c = opp.Account.npe01__One2OneContact__r.npo02__Household__c;
             System.debug('SetHouseholdOnOpp Opp Household is ' + opp.OppHousehold__c);
             update opp;
        }
    }
}

 

Thanks.  Thu :-)

  • April 18, 2013
  • Like
  • 0

Hi,

 

I'm totally green with Apex trigger, and this is my first stab at writing one.  I'm trying to add this Opportunity trigger on NPSP to assign a Designation to an Opportunity transaction when it's created.  The trigger is created from Setup->Customize->Opportunity->Trigger.  DonationDesignationRelationship is a custom object, which has a master-detail relationship with Opportunity.

 

When I hit "Quick Save", I got this error:

 

Error: Compile Error: Invalid type: DonationDesignationRelationship at line 5 column 57 

 

It might be something really straighforward, but somehow I can't figure out.  The code is pretty simple:

 

// Add Designation to a brand new Opportunity

trigger OpportunityAddDesignation on Opportunity (after insert) {    

 

  List<DonationDesignationRelationship> ddrs = new List<DonationDesignationRelationship>();    

  if (Trigger.isInsert && Trigger.isAfter) {    

    for (Opportunity opp: Trigger.new) {      

      if (opp.Amount > 0) {        

        ddrs.add(new DonationDesignationRelationship 

           (Amount = opp.Amount, Designation = a18U000000BOP4r, Opportunity = opp.Id));      

      }    

    }  

  }  

  insert ddrs;

 

}

 

I'd really appreciate any help or pointers to accomplish this.

 

Thanks!

 

 

  • February 07, 2013
  • Like
  • 0