• Mark Lewis 21
  • NEWBIE
  • 20 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
I have an autoresponse email trigger with this code
trigger EmailToLeadResponseTrigger on Lead (after insert) {
    //Query on template object
    EmailTemplate emailTemplate = [SELECT id FROM EmailTemplate WHERE name = :'Sales: Lead Created'];
    //List of emails
    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
    
    for (Lead lead : [SELECT Id, Lead.Email FROM Lead WHERE Id IN : Trigger.new]) {
        if (lead.Email != null) {
            //Initialize messaging method
            Messaging.SingleEmailMessage singleMail = new Messaging.SingleEmailMessage();
            //Set object Id
            singleMail.setTargetObjectId(lead.Id);
            //Set template Id
            singleMail.setTemplateId(emailTemplate.Id);
            //Flag to false to stop inserting activity history
            singleMail.setSaveAsActivity(false);
            //Add mail
            emails.add(singleMail);
        }
    }
    //Send mail
    Messaging.sendEmail(emails);	    
}

However, in my inbox it actually shows the user im using's email adress. Can I make this hidden or one of those "noreply@....com" emails where It just rejects replies to that given email?
Hello guys

I have code that automatically generates leads from my email. Now what I need is something that can inform the sender that their query is being processed. Now I have created a tigger to send the response but it doesnt seem to work. Is there something I am missing?
 
trigger EmailToLeadResponseTrigger on Lead (after insert) {
	final String template = 'SalesLeadCreatedWebInquiries';
    Id templateId;
    
    try {
    templateId = [SELECT id FROM EmailTemplate WHERE Name = :template].id;
    } catch (QueryException e) {
    //...handle exception if no template is retrieved, or create condition to set email body in code
    }
    List<Messaging.SingleEmailMessage> messages = new List<Messaging.SingleEmailMessage>();
    //Send a single mail to contact each created lead
    for (Lead l : [SELECT Name, Lead.Email FROM Lead WHERE Id in :Trigger.new]) {
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        
        message.setTemplateId(templateId);
        message.setTargetObjectId(l.Id);
        message.setWhatId(l.Id);
        message.setToAddresses(new String[] {l.Email});
        messages.add(message);
    }
    
}

 
Hello guys

I have code that automatically generates leads from my email. Now what I need is something that can inform the sender that their query is being processed. Now I have created a tigger to send the response but it doesnt seem to work. Is there something I am missing?
 
trigger EmailToLeadResponseTrigger on Lead (after insert) {
	final String template = 'SalesLeadCreatedWebInquiries';
    Id templateId;
    
    try {
    templateId = [SELECT id FROM EmailTemplate WHERE Name = :template].id;
    } catch (QueryException e) {
    //...handle exception if no template is retrieved, or create condition to set email body in code
    }
    List<Messaging.SingleEmailMessage> messages = new List<Messaging.SingleEmailMessage>();
    //Send a single mail to contact each created lead
    for (Lead l : [SELECT Name, Lead.Email FROM Lead WHERE Id in :Trigger.new]) {
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        
        message.setTemplateId(templateId);
        message.setTargetObjectId(l.Id);
        message.setWhatId(l.Id);
        message.setToAddresses(new String[] {l.Email});
        messages.add(message);
    }
    
}

 

Hi,

Using this below code able to create the user successfully.' I want to get the newly inserted user Id Immediately '  .Once again we put the query to get a user id or Is any way to get the user id. how to get this . Using Userinfo.getUserId() we can get current loged in user. Please guide me to achive this .

        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];

        User u = new User(Alias = 'standt', Email='standarduser@testorg.com',
            EmailEncodingKey='UTF-8', LastName='Testing123', LanguageLocaleKey='en_US',
            LocaleSidKey='en_US', ProfileId = p.Id,
            TimeZoneSidKey='America/Los_Angeles', UserName='standarduserTestUser@testorg.com'); 
        insert u;
      
Advance Thanks
Maheshwar
I have an autoresponse email trigger with this code
trigger EmailToLeadResponseTrigger on Lead (after insert) {
    //Query on template object
    EmailTemplate emailTemplate = [SELECT id FROM EmailTemplate WHERE name = :'Sales: Lead Created'];
    //List of emails
    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
    
    for (Lead lead : [SELECT Id, Lead.Email FROM Lead WHERE Id IN : Trigger.new]) {
        if (lead.Email != null) {
            //Initialize messaging method
            Messaging.SingleEmailMessage singleMail = new Messaging.SingleEmailMessage();
            //Set object Id
            singleMail.setTargetObjectId(lead.Id);
            //Set template Id
            singleMail.setTemplateId(emailTemplate.Id);
            //Flag to false to stop inserting activity history
            singleMail.setSaveAsActivity(false);
            //Add mail
            emails.add(singleMail);
        }
    }
    //Send mail
    Messaging.sendEmail(emails);	    
}

However, in my inbox it actually shows the user im using's email adress. Can I make this hidden or one of those "noreply@....com" emails where It just rejects replies to that given email?
Hello guys

I have code that automatically generates leads from my email. Now what I need is something that can inform the sender that their query is being processed. Now I have created a tigger to send the response but it doesnt seem to work. Is there something I am missing?
 
trigger EmailToLeadResponseTrigger on Lead (after insert) {
	final String template = 'SalesLeadCreatedWebInquiries';
    Id templateId;
    
    try {
    templateId = [SELECT id FROM EmailTemplate WHERE Name = :template].id;
    } catch (QueryException e) {
    //...handle exception if no template is retrieved, or create condition to set email body in code
    }
    List<Messaging.SingleEmailMessage> messages = new List<Messaging.SingleEmailMessage>();
    //Send a single mail to contact each created lead
    for (Lead l : [SELECT Name, Lead.Email FROM Lead WHERE Id in :Trigger.new]) {
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        
        message.setTemplateId(templateId);
        message.setTargetObjectId(l.Id);
        message.setWhatId(l.Id);
        message.setToAddresses(new String[] {l.Email});
        messages.add(message);
    }
    
}