• mdangond
  • NEWBIE
  • 0 Points
  • Member since 2009

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

Is there a way to send an email message to a user notifying them that they have been added to an opportunity sales team or that an specific opportunity is now being shared with them?

 

I tried doing this via workflow and was not able to. I then tried to do it via a trigger and later found out that the trigger would not work since it can only fire when the opportunity is being updated and it seems that the act of "sharing" is not considered an update on the opportunity object.

 

Here's my Trigger's code:

 

trigger NotifyOpportunitySharing on Opportunity (after insert, after update) {

 

EmailTemplate template = [ Select id From EmailTemplate WHERE DeveloperName = 'OpportunitySharingNotification' LIMIT 1 ];

//For Old Opportunity

 Set<Id> oldOppId = new Set<Id>(); for (Opportunity oldOpp : trigger.old){

oldOppId.add(oldOpp.Id);

}

List<OpportunityTeamMember> oldOtms = [Select Id, OpportunityId, UserId FROM OpportunityTeamMember WHERE OpportunityId in : oldOppId ];

 

//For new oppotunity

 Set<Id> oppId = new Set<Id>(); for (Opportunity opp : trigger.new){

oppId.add(opp.Id);

}

List<OpportunityTeamMember> Otms = [Select Id, OpportunityId, UserId FROM OpportunityTeamMember WHERE OpportunityId in : oppId ];

If (Otms.size() > 0){

for (OpportunityTeamMember oldOppTeam : oldOtms) {

for (OpportunityTeamMember oppTeam : otms) {System.debug(

'***oppTeam.UserId: '+oppTeam.UserId+ '****oldOppTeam.UserId :'+oldOppTeam.UserId);

if (oppTeam.UserId != oldOppTeam.UserId) {

//Send an email alert

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

//User salesRep = [SELECT Email FROM User WHERE Id = :trigger.new[i].OpportunityTeamMember.UserId LIMIT 1];

//User salesRep = [SELECT Email FROM User WHERE Id = Otms.get(i).Id LIMIT 1];

//mail.templateId = template.Id;

//mail.targetObjectId = salesRep.Id;

//mail.targetObjectId = oppTeam.Id;

mail.setSubject('Trigger testing');

mail.setPlainTextBody('We are testing....please ignore....');String[] toAddress =

new String[] {'manuel.dangond@qlogic.com'};

mail.setToAddresses(toAddress);

mail.setSaveAsActivity(false);

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

 

}

 

}

}

 

Any ideas or suggestions would be very much appreciated!

 

Thanks!

Message Edited by mdangond on 02-26-2010 08:35 AM

In trying to enforce our account naming standard, I would like to write a trigger that checks for the existance of the "Billing City" in the new account name a user is trying to create. Our account naming convention is "Accout Name - Billing City", so my trigger needs to check for the existance of a hyphen (" - ") and Billing City in the name.

 

A correct account name would be: IBM - San Francisco or HP - San Diego.

 

Can this be done with a trigger?

 

Thanks!

Thanks so much SelectedPartner. This solution worked!

 

But now I need to improve on this logic just a little bit and I need to validate that the account name is following our naming standard. Our Account naming standard is "Company Name - Site City", where Site City is a custom field that has the name of the city where the company is located. So what I am now trying to do is to add one or two more lines of code that will do the following:

 

1. Check that the company name has a " - " in its name.

2. Check that the Site City value (which is required) is also part of the name.

 

Example: IBM - San Francisco is the correct way to name the IBM account in San Francisco. So anything like just "IBM" would be invalid. "IBM - "would also be invalid, since it's missing the city name at the end of the name. "IBM - Boston", with a Site City = San Francisco would also be invalid since Boston is not equal to the value of Site City, in this case, San Francisco.

 

In summary: Is there a way to check for the existance of " - " and a matching value of Site City on the new account name a user is trying to create? If this is true, can you please give me an example of how this code would look like? I'm already using your code. Thanks a million!

I need to write an Apex Trigger that will check if an account exists when a user tries to create a new account, and either allow the insert if the account is not found or block the insert and display a message telling the user this account cannot be created since it already exists.

 

I have never written an Apex Code and I will be going to a class in January to learn how to write Apex Code, but in the meantime (since I need this trigger ASAP) can someone provide the code to do this? I imagine this is not very complicated and it is a trigger that many other people may have already written.

 

Thanks so much in advance to whoever can help me with this Apex Trigger code.

In trying to enforce our account naming standard, I would like to write a trigger that checks for the existance of the "Billing City" in the new account name a user is trying to create. Our account naming convention is "Accout Name - Billing City", so my trigger needs to check for the existance of a hyphen (" - ") and Billing City in the name.

 

A correct account name would be: IBM - San Francisco or HP - San Diego.

 

Can this be done with a trigger?

 

Thanks!

I need to write an Apex Trigger that will check if an account exists when a user tries to create a new account, and either allow the insert if the account is not found or block the insert and display a message telling the user this account cannot be created since it already exists.

 

I have never written an Apex Code and I will be going to a class in January to learn how to write Apex Code, but in the meantime (since I need this trigger ASAP) can someone provide the code to do this? I imagine this is not very complicated and it is a trigger that many other people may have already written.

 

Thanks so much in advance to whoever can help me with this Apex Trigger code.