• JohnC5674
  • NEWBIE
  • 0 Points
  • Member since 2007

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 8
    Replies
I have a trigger that assigns leads out to reps based on another custom object.  The part I cant figure out is how to put in if the lead had a zip code that doesnt exist in the zip code object, assign the lead to me.  Can anyone help me with this if I send you the trigger?
I am trying to create a formula field to show the # of days left in the month.  The formula is referencing a Date field to go off of.  Does anyone know why I am getting #Error!? If anyone knows how to fix this, do you also know a way to show the # of Business Days left in the month?
 
DAY(DATE(YEAR( Date__c ),MONTH( Date__c )+1,0))-DAY( Date__c )
We have an object called Subscribers that is tied to the account level.  I added a field called Total Lines to the account record and I am trying to create an scontrol to count all subscribers tied to an account and populate that number in the Total Lines field on the account.  Can someone please help me with this? I have pasted the scontrol below.
 
<script src="/soap/ajax/8.0/connection.js" type="text/javascript"></script>
<script>
//Query for Owner Division
var accountID = "{!Account.Id}";
var subkey = "{!Subscriber__c.SUB_KEY__c}";
{
subResult = sforce.connection.query("Select Name from Subscriber__c where Account__c='accountID and subkey<>null'");

subRecords = subResult.getArray("records");
var subRecord = subRecords.size;

//Query for Account Custom Division Field
var accountID = "{!Account.Id}";
accountResult = sforce.connection.query("Select Total_Lines__c from Account where id = '" + accountID + "'");
accountRecords = accountResult.getArray("records");
var accountRecord = accountRecords[0];

//If the Division on the Account is populated, do not update the Account
if(accountRecord.Total_Lines__c != subRecord) {
var account = new sforce.SObject("Account");
account.ID = "{!Account.Id}";
account.Total_Lines__c = subRecord;
result = sforce.connection.update([account]);
window.parent.location.href = "/{!Account.Id}";
}
}
</script>
Hello everyone,
 
I'm not familiar with scontrols at all and need help on something.  When users create cases, we have no way to know what market or territory that users is from so we can't create reports to show the number of cases created by territory or market.  Is there a way to create a field and inline scontrol so that anytime a user creates a case, it will populate with what is in the Territory field on the user record? 
 
 
I'm trying to assign record ownership on custom-object records as they are created via the API.  The custom object is called "Sales Quotes".  I would like to change the owner on each record from the login username used by the API to the same owner that is set on the Opportunity (Sales Quotes being related to Opportunity via lookup relationship). 
 
The preferred method would have been Workflow rule but the field update does not allow dynamic selection of user.  So I'm hoping this could be an easy Apex trigger that could run after each record is created.  Does anyone have any ideas to accomplish this easily and/or some sample code that would work?
 
Thanks from an Apex newbie!
  • December 09, 2008
  • Like
  • 0
I'm writing a bulk trigger to update lead owners based on a zip code table we have.

I think I'm close to having the whole thing working, but I'm getting the "Attempt to de-reference a null object" error when I actually execute a test of my code.

Here is the code:

Code:
trigger LeadAssignmentTrigger on Lead (before insert) 
{    
    List<String> zips = new List<String>();

    // Loop through Leads and create list of zip codes
    for (Lead lead : Trigger.new)
    {
        if (lead.PostalCode != NULL)
        {
            zips.add(lead.PostalCode);    
        }
    }

    //query zip code table and link zips to Sales reps
    // Name field = a single zip code
Map<String, Zip_Code__c> leadsToUpdate = new Map<String, Zip_Code__c>
([select Name, Sales_Rep__c from Zip_Code__c where Name in :zips]);

// If there is at least one match, bulk update
if (leadsToUpdate.size() > 0)
{
for (Lead lead : Trigger.new)
{
//assign the lead owner to the zip code owner
lead.OwnerId = leadsToUpdate.get(lead.PostalCode).Sales_Rep__c; //this line gives the error
}
}
}

There must be some small problem I have in here. Basically what I want to do is find the Sales Rep who corresponds to the new lead's zip code and assign that sales rep as the new lead OWNER.

If anyone knows why I'm getting that error and can give me some advice I would be much obliged.

Thanks

We are trying to automatically assign lead ownership based on our database of Zip Codes. Since there are so many zip codes, we can't manually put them in the native assignment rules.

I'm trying to write a trigger to reassign the Lead Owner but this is my first one and I can't seem to get it right. Here's what I have:

Code:
trigger LeadAssignmentTrigger on Lead (before insert) 
{
    List<Lead> leadsToUpdate = new List<Lead>();

    for (Lead lead : Trigger.new)
    {
     
      if (lead.PostalCode != NULL)
      {
          // Find the sales rep for the current zip code
          List<Zip_Code__c> zip = [select Sales_Rep__c from Zip_Code__c 
where Name = :lead.PostalCode limit 1];


// if you found one
if (zip.size() > 0)
{
//assign the lead owner to the zip code owner
lead.Owner = zip.Sales_Rep__c; // This is my problem line

leadsToUpdate.add(lead);

}
}

}

// update the records
try
{
update leadsToUpdate;
}
catch (DmlException dm)
{
leadsToUpdate.addError('There was a problem reassigning the Lead Owner');
}

}

I have bolded the problem line. All I want to do is to assign the User from my Zip Code object (just a list of zip codes and user lookups) to the current lead creation on any given Lead insert.

Can someone please tell me what the correct syntax should be?

Thanks
We have an object called Subscribers that is tied to the account level.  I added a field called Total Lines to the account record and I am trying to create an scontrol to count all subscribers tied to an account and populate that number in the Total Lines field on the account.  Can someone please help me with this? I have pasted the scontrol below.
 
<script src="/soap/ajax/8.0/connection.js" type="text/javascript"></script>
<script>
//Query for Owner Division
var accountID = "{!Account.Id}";
var subkey = "{!Subscriber__c.SUB_KEY__c}";
{
subResult = sforce.connection.query("Select Name from Subscriber__c where Account__c='accountID and subkey<>null'");

subRecords = subResult.getArray("records");
var subRecord = subRecords.size;

//Query for Account Custom Division Field
var accountID = "{!Account.Id}";
accountResult = sforce.connection.query("Select Total_Lines__c from Account where id = '" + accountID + "'");
accountRecords = accountResult.getArray("records");
var accountRecord = accountRecords[0];

//If the Division on the Account is populated, do not update the Account
if(accountRecord.Total_Lines__c != subRecord) {
var account = new sforce.SObject("Account");
account.ID = "{!Account.Id}";
account.Total_Lines__c = subRecord;
result = sforce.connection.update([account]);
window.parent.location.href = "/{!Account.Id}";
}
}
</script>
Hello everyone,
 
I'm not familiar with scontrols at all and need help on something.  When users create cases, we have no way to know what market or territory that users is from so we can't create reports to show the number of cases created by territory or market.  Is there a way to create a field and inline scontrol so that anytime a user creates a case, it will populate with what is in the Territory field on the user record?