• SteveDev
  • NEWBIE
  • 25 Points
  • Member since 2011

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

I create a trigger  which prevent user form save account if it associated with a recordtype account:

Is the following trigger correct? Do I need to put the query outside the account for loop.

 

Trigger UmbrellaAccountTrigger on Account (before insert,before update) {
private Account[] Acc =Trigger.new;
integer SOQL;
List <contact> Con= New List <Contact>();
For(Account a:Acc){
a.Updated__c=[select count() from contact where accountId=:a.ID];
If((a.Updated__c!= 0)&&(a.RecordTypeC__c==1 )){

a.addError('You can not save Umbrella Record associated with a contact');
}
}
}

 

Note: a.Updated__c is a custom field on account and it display the number of relcated contact



  • October 14, 2011
  • Like
  • 0

Hi

 

I'm trying to send an email via apex using an email template.

 

The problem I'm coming across is that apparently I need to set the targetObjectId, even though I'm setting the toAddresses (and the documentation states that it only requires one of these to be populated).

 

Here's the code:

 

public static void bypassEmail(String email, String offerId) {

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

EmailTemplate et = [Select Id from EmailTemplate where Name = 'Bypass / Delegated Approval'];

mail.setWhatId(OfferId);

mail.setTemplateId(et.Id);

mail.setToaddresses(new String[] {email});

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 

I can't set a targetObjectId as it needs to be sent to an address held in a custom field. Does anyone know a way to make this work or am I going to have to do a replace on the template Body to turn the merge fields into the values?

 

Thanks

 

Steve

I create a trigger  which prevent user form save account if it associated with a recordtype account:

Is the following trigger correct? Do I need to put the query outside the account for loop.

 

Trigger UmbrellaAccountTrigger on Account (before insert,before update) {
private Account[] Acc =Trigger.new;
integer SOQL;
List <contact> Con= New List <Contact>();
For(Account a:Acc){
a.Updated__c=[select count() from contact where accountId=:a.ID];
If((a.Updated__c!= 0)&&(a.RecordTypeC__c==1 )){

a.addError('You can not save Umbrella Record associated with a contact');
}
}
}

 

Note: a.Updated__c is a custom field on account and it display the number of relcated contact



  • October 14, 2011
  • Like
  • 0