• wilson34
  • NEWBIE
  • 25 Points
  • Member since 2008

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

Hello guys,

 

can anybody help me on this. I have created a lead trigger (before insert) and this trigger is basically needs to check whether the name inserted by the user already exists on either contact or lead object. However, when I try to get the "name" field (standard object), the field is always null.  It just doesn't make any sense. I would really appreciate it if someone can help me on this.

 

Here's my code snippet:

 

trigger FindDuplicateLeads on Lead (before insert, before update)
{

    string nameStr;

    if(Trigger.isInsert)
    {

         for(integer x = 0; x < Trigger.new.size(); x++)
        {
            if(x == 0)
            {

                 nameStr = '\''+ Trigger.new[x].Name +'\'';

                 //other codes here......

            }

        }

 

       system.debug('nameStr debug:'+nameStr);

   }

}

Hello guys,

 

I'm having problem with opening the s-control which has an embede flex object. My problem is I have a custome command button that when the button is clicked, the VF page will call the s-control. The problem is that the page is displayed but it doesn't have a sidebar and header. So what I did at first was to make another VF page that would handle opening the flex object, this works but I need the s-control instead of another VF page. Another option I did was to make a custom button that would call the s-control. This also works but the downside is the Id of the custom button is hardcoded in the URL which  makes the design of the code not so good.

 

any thoughts on this?? I would really appreciate it if you can give any other idea.

 

Thanks in advance.

 

Wilson

Hello Everyone,

I hope you can help me on this..Im working with singleEmail to send an email to a particular sales representative on every territory. but every time I invoked my trigger via update of my objects, it returns an exception. The error is: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.\.: Trigger.Notify_Rep_Trigger: line 90, column 21

my code is written below:

Account territory = [select Territory_Name__c from Account where Id =:data.Account_ID__c];
           
            if(territory.Territory_Name__c != null)
            {
               
                List<string> splitID = territory.Territory_Name__c.split(';', -1);
                Set<string> tID = new Set<string>();
                tID.clear();
               
                List<Territory> territoryId = [Select id From Territory where name in :splitID];
               
                List<UserTerritory> usersId = [Select UserId From UserTerritory where territoryid in :territoryId];
               
                for(integer x=0; x < usersId.size(); x++)
                {
                        tID.add(usersId[x].UserId);
                }
               
                List<User> emailAdd = [select Id, email from User where Id in :tID];
               
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                List <String> Addresses = new List<String>();
           
                for(integer i=0; i < emailAdd.size(); i++)
                {
                    //String[] toAddresses = new String[] {emailAdd[i].email};
       
                    //mail.setToAddresses(toAddresses);
                    mail.setCcAddresses(ccAddresses);
                   
                    mail.setBccSender(true);
                    mail.setUseSignature(false);
                    mail.setSaveAsActivity(false);
                   
                    String toTargetObjects = (string)emailAdd[i].Id;
                   
                    system.debug('target object deb:'+toTargetObjects);
                    system.debug('data id deb:'+data.Id);
                   
                    mail.setTargetObjectId(toTargetObjects);
                    mail.setWhatId(toTargetObjects);
       
                    mail.setTemplateId(templateId);
                   
                    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
                }
            }
        }

any suggestion? I would really appreciate it if you can help me on this.


Thanks in advance,

Wilson




Message Edited by wilson34 on 11-21-2008 01:50 AM

Message Edited by wilson34 on 11-21-2008 01:51 AM

Message Edited by wilson34 on 11-21-2008 01:51 AM

Message Edited by wilson34 on 11-21-2008 01:53 AM

Hello guys,

 

can anybody help me on this. I have created a lead trigger (before insert) and this trigger is basically needs to check whether the name inserted by the user already exists on either contact or lead object. However, when I try to get the "name" field (standard object), the field is always null.  It just doesn't make any sense. I would really appreciate it if someone can help me on this.

 

Here's my code snippet:

 

trigger FindDuplicateLeads on Lead (before insert, before update)
{

    string nameStr;

    if(Trigger.isInsert)
    {

         for(integer x = 0; x < Trigger.new.size(); x++)
        {
            if(x == 0)
            {

                 nameStr = '\''+ Trigger.new[x].Name +'\'';

                 //other codes here......

            }

        }

 

       system.debug('nameStr debug:'+nameStr);

   }

}

Hello Everyone,

I hope you can help me on this..Im working with singleEmail to send an email to a particular sales representative on every territory. but every time I invoked my trigger via update of my objects, it returns an exception. The error is: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.\.: Trigger.Notify_Rep_Trigger: line 90, column 21

my code is written below:

Account territory = [select Territory_Name__c from Account where Id =:data.Account_ID__c];
           
            if(territory.Territory_Name__c != null)
            {
               
                List<string> splitID = territory.Territory_Name__c.split(';', -1);
                Set<string> tID = new Set<string>();
                tID.clear();
               
                List<Territory> territoryId = [Select id From Territory where name in :splitID];
               
                List<UserTerritory> usersId = [Select UserId From UserTerritory where territoryid in :territoryId];
               
                for(integer x=0; x < usersId.size(); x++)
                {
                        tID.add(usersId[x].UserId);
                }
               
                List<User> emailAdd = [select Id, email from User where Id in :tID];
               
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                List <String> Addresses = new List<String>();
           
                for(integer i=0; i < emailAdd.size(); i++)
                {
                    //String[] toAddresses = new String[] {emailAdd[i].email};
       
                    //mail.setToAddresses(toAddresses);
                    mail.setCcAddresses(ccAddresses);
                   
                    mail.setBccSender(true);
                    mail.setUseSignature(false);
                    mail.setSaveAsActivity(false);
                   
                    String toTargetObjects = (string)emailAdd[i].Id;
                   
                    system.debug('target object deb:'+toTargetObjects);
                    system.debug('data id deb:'+data.Id);
                   
                    mail.setTargetObjectId(toTargetObjects);
                    mail.setWhatId(toTargetObjects);
       
                    mail.setTemplateId(templateId);
                   
                    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
                }
            }
        }

any suggestion? I would really appreciate it if you can help me on this.


Thanks in advance,

Wilson




Message Edited by wilson34 on 11-21-2008 01:50 AM

Message Edited by wilson34 on 11-21-2008 01:51 AM

Message Edited by wilson34 on 11-21-2008 01:51 AM

Message Edited by wilson34 on 11-21-2008 01:53 AM

HI

There is a requirement to send emails to contact owners for birthdays of their

respective contacts. So we are calling  Messaging.SingleEmailMessage method within an Apex class

in a loop. But in the Apex class there is a limitation that this method cannot be called more

than 10 times. Contact Owners are more than 50 though. The loop runs this many times .

How to handle this governor limit issue?