• IanR
  • NEWBIE
  • 300 Points
  • Member since 2009

  • Chatter
    Feed
  • 12
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 49
    Replies

Help please.....

I am new to coding in general so please go easy on me.  I got some help with my code but can't seem to figure out why I am getting a "System.NullPointerException: Attempt to de-reference a null object" error from my trigger every time I save.  Here is the scenario:

Basically do screenings and we record Total_cash__c, Total_charges__c, and Total_checks__c collected on our opportunities.  We needed a way to link each opportunity to a custom object Deposit__c and be able to sum each related field on the Deposit__c.  There will never be more than 10 opportunities attached to one Deposit via lookup. Because I cannot create a master-detail with an opportunity to run a roll-up I need to do it with a trigger on an opportunity with a lookup field to the Deposit custom object.  My code compiles but gives me the de-reference a null object error and I can figure out why. 

The error starts here.  Am I doing something wrong in the way I am accessing and trying to set the value of the fields of Sum_of_Cash__c, Sum_of_Checks, Sum_of_Charges   ??The fields are created on the Deposit__c custom object and of the same type on the related opportunity.

thisDeposit.Sum_of_Cash__c = totalSumCash;

 

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

//instantiate opportunity

Opportunity thisScreening = Trigger.New[0];

// retrieve from the DB all of the opportunities related to the current related deposit

List<Opportunity> screenings = [SELECT Deposited__r.Name, Total_cash__c, Total_checks__c, Total_charges__c
FROM Opportunity WHERE Deposited__c =: thisScreening.Deposited__c];

//instantiate this related deposit

Deposit__c thisDeposit = thisScreening.Deposited__r;

// init variables for sum
double totalSumCash = 0, totalSumChecks = 0, totalSumCharges = 0;

//iterate through each opportunity in this list, calculate the sum on the deposit

for(Opportunity o :screenings){
totalSumCash += o.Total_Cash__c;
totalSumCharges += o.Total_Charges__c;
totalSumChecks += o.Total_Checks__c;
}
thisDeposit.Sum_of_Cash__c = totalSumCash;
thisDeposit.Sum_of_Checks__c = totalSumCash;
thisDeposit.Sum_of_Credit__c = totalSumCash;
// update the related deposit record in the DB
update thisDeposit;
}
Thanks for helping anyone who tackles this 

Hi ,

Below is the class which i am using to retrieve leadis and contactids from campaign which are a total of more then 2000 records from select query using for loop.

 

public class Test

{

   Set<Id> leadid = new Set<Id>();

        Set<Id> contactid = new Set<Id>();

        List<String> emails=new List<String>();

 

public void TestMethod()

{

 

  for(campaignmember camp:[Select leadid,contactid from campaignmember where campaignid=:'campaignId']) {

  leadid.add(camp.leadid);

contactid.add(camp.contactid); 

 

 

 

 

here i am able to run the query which has more than 2000 records in the for loop but unable to add the leadid and contactid to the List<Id> (i.e  leadid , contactid) respectively as shown above.

An exception - collection exceeds maximum size: 1001 is being disaplayed.

 

My actual intenstion is to get the leadids and contactids and run the respective select query and add the email address to a list string emails.

 for (Contact cnt: [Select Email from contact WHERE Id IN :contactid]) 

 {

         if(cnt.Email != null)

         {

              emails.add(cnt.Email);

         }

 } 

 

can any one help me out.Thanks in advance

 

Thanks 

prashanth. 

 

 

  • September 10, 2009
  • Like
  • 0
I'm writing a trigger to determine which fields have changed when an sObject is updated. This code must be future-proof, so, I do not want to hard code any field names - does anyone know of a way of acheiving this?
  • September 09, 2009
  • Like
  • 0

To augment Web2Case's matching* in SFDC, I am attempting to build a relationship between the domain name within the submitted email address to the Asset and/or Account.

trigger domainMatch on Case (before insert) { for (Case c : Trigger.new) { String WebEmail = c.SuppliedEmail; System.debug('WebEmail = ' + WebEmail); // Find where the @ sign occurs Integer index = WebEmail.indexOf('@', 0); System.debug('index = ' + index); // Extract all text after the @ sign String emailDomain = WebEmail.substring(index+1); System.debug('emailDomain = ' + emailDomain); // When the Contact has not been matched, search through Account & Asset for the Domain if ((c.Contact == null) && (index != -1)) { if ([SELECT a.Name from Account a WHERE a.Name = :emailDomain] != null) { c.Account = [SELECT a.id from Account a WHERE a.Name = :emailDomain]; update c.Account; System.debug('c.Account = ' + c.Account); } if ([SELECT a.Name from Account a WHERE a.Name = :emailDomain] != null) { c.Asset = [SELECT a.id from Asset a WHERE a.Name = :emailDomain]; update c.Asset; System.debug('c.Asset = ' + c.Asset); } } } }

 

From looking at the debug logs (below) I have extracted the domain name from the email address and am able to find the appropriate ID in SFDC, but the lookup field on the Case record does not appear to be linked to the Asset or Account. 

 

How can I link the case to the Account and/or Asset?

 *** Beginning domainMatch on Case trigger event BeforeInsert for null

20090902190439.204:Trigger.domainMatch: line 14, column 5: SelectLoop:LIST:SOBJECT:Case
20090902190439.204:Trigger.domainMatch: line 17, column 5: WebEmail = nosuchuser@domain.com
20090902190439.204:Trigger.domainMatch: line 22, column 5: index = 10
20090902190439.204:Trigger.domainMatch: line 26, column 5: emailDomain = domain.com
20090902190439.204:Trigger.domainMatch: line 30, column 17: SOQL query with 1 row finished in 44 ms
20090902190439.204:Trigger.domainMatch: line 31, column 29: SOQL query with 1 row finished in 21 ms
20090902190439.204:Trigger.domainMatch: line 32, column 17: Update: SOBJECT:Account
20090902190439.204:Trigger.domainMatch: line 32, column 17:     DML Operation executed in 110 ms
20090902190439.204:Trigger.domainMatch: line 33, column 17: c.Account = Account:{Id=0016000000MKEMVAA5}
20090902190439.204:Trigger.domainMatch: line 35, column 17: SOQL query with 1 row finished in 30 ms
20090902190439.204:Trigger.domainMatch: line 36, column 27: SOQL query with 1 row finished in 44 ms
20090902190439.204:Trigger.domainMatch: line 37, column 17: Update: SOBJECT:Asset
20090902190439.204:Trigger.domainMatch: line 37, column 17:     DML Operation executed in 75 ms
20090902190439.204:Trigger.domainMatch: line 38, column 17: c.Asset = Asset:{Id=02i60000004B2vBAAS}

Cumulative resource usage:

Resource usage for namespace: (default)
Number of SOQL queries: 4 out of 20
Number of query rows: 4 out of 1000
Number of SOSL queries: 0 out of 0
Number of DML statements: 2 out of 20
Number of DML rows: 2 out of 100
Number of script statements: 14 out of 10200
Maximum heap size: 0 out of 200000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 10
Number of record type describes: 0 out of 10
Number of child relationships describes: 0 out of 10
Number of picklist describes: 0 out of 10
Number of future calls: 0 out of 10
Number of find similar calls: 0 out of 0
Number of System.runAs() invocations: 0 out of 0

Total email recipients queued to be sent : 0

*** Ending domainMatch on Case trigger event BeforeInsert for null

 

BTW, I know that I need to build better bulk processing into this code . . . that's the next challenge.

 

==================================

* By default, Web2Case only compares the complete email address to the Email address within Contact records.  If anyone else at that company submits a case and they do not have a Contact record with their email address, their case is not associated with that Account nor Asset.

Hello,

 

I have two triggers.  One checks for duplicate opportunities and the auto populates the opportunity name with the account name + the mm/yy format of the effective date. The problem is they do not work together.  The dup checker does not detect what I automatically fill in from the other trigger!  Do I have to pull them together as one trigger or is there a way to create this logic in a class and then have one trigger call that class.  If you could give me some direction it would be appreciated.

 

I have this controller extension:

 

public class OpportunityClosedLost { public Opportunity opp; public apexpages.standardController controller {get; set;} public opportunityClosedLost(ApexPages.StandardController stdController) { // constructor controller = stdController; this.opp= (Opportunity)stdController.getRecord(); Opportunity opps = (Opportunity)stdController.getRecord(); opps = [SELECT RecordTypeId, StageName FROM Opportunity WHERE id=:system.currentpageReference().getparameters().get('id')]; //VRC opportunity if(opps.RecordTypeId =='012700000009RIb'){ isVrc = true; } //vRad Alliance Opportunity if(opps.RecordTypeId =='012T00000000JJD'){ isAlliance = true; } //EC Opportinity if(opps.RecordTypeId =='012700000005KwS'){ isEc = true; } } public List<SelectOption> getStageOptions(){ List<SelectOption> options = new List<SelectOption>(); options.add(new SelectOption('null','-- Select One --')); Schema.DescribeFieldResult oppStage = Schema.sObjectType.Opportunity.fields.StageName; for (Schema.PickListEntry oppPickVal : oppStage.getPicklistValues()){ // create a selectoption for each pickval options.add(new SelectOption(oppPickVal.getValue(),oppPickVal.getLabel())); } return options; } public Boolean isVrc{ get{ if(isVrc == null){ isVrc = false; } return isVrc; } set; } public Boolean isAlliance{ get{ if(isAlliance == null){ isAlliance = false; } return isAlliance; } set; } public Boolean isEc{ get{ if(isEc == null){ isEc = false; } return isEc; } set; } }

I have written a test class and it is only catching the true situations for the boolean properties colored in blue I am not sure how to test the false condition. I am also unsure how to test the SelectList portion of the code that is red.

 

Here is my test class so far:

 

 

public with sharing class OpportunityClosedLostTest { static testMethod void OpportunityClosedLostTest(){ Opportunity opp1 = new Opportunity(Name = 'Opportunity1', Probability = 20.00, CloseDate = Date.newInstance(System.now().year(),10,10), StageName = 'Prospect', RecordTypeId = '012700000009RIb'); insert opp1; Opportunity opp2 = new Opportunity(Name = 'Opportunity2', Probability = 70.00, CloseDate = Date.newInstance(System.now().year(),12,31), StageName = 'Quote Requested', RecordTypeId = '012700000005KwS'); insert opp2; Opportunity opp3 = new Opportunity(Name = 'Opportunity3', Probability = 50.00, CloseDate = Date.newInstance(System.now().year(),9,18), StageName = 'Competitive Situation', RecordTypeId = '012T00000000JJD'); insert opp3; //Test Opportunity Edit Page VRC Test.SetCurrentPageReference(New PageReference('Page.ClosedOpp')); ApexPages.Standardcontroller sc1 = New ApexPages.StandardController(opp1); System.CurrentPageReference().getParameters().put('id',opp1.Id); OpportunityClosedLost cOpp1 = new OpportunityClosedLost(sc1); System.debug(cOpp1.isVrc); update opp1; //Test Opportunity Detail Page VRC Test.setCurrentPageReference(New PageReference('Page.ClosedOppView')); ApexPages.StandardController sc2 = New ApexPages.StandardController(opp1); System.CurrentPageReference().getParameters().put('id',opp1.id); OpportunityClosedLost cOpp2 = new OpportunityClosedLost(sc2); System.debug(cOpp2.isVrc); update opp1; //Test Opportunity Edit Page EC Test.SetCurrentPageReference(New PageReference('Page.ClosedOpp')); ApexPages.StandardController sc3 = New ApexPages.StandardController(opp2); System.CurrentPageReference().getParameters().put('id', opp2.id); OpportunityClosedLost cOpp3 = new OpportunityClosedLost(sc3); System.debug(cOpp3.isEc); update opp2; //Test Opportunity Detail Page EC Test.SetCurrentPageReference(New PageReference('Page.ClosedOppView')); ApexPages.StandardController sc4 = New ApexPages.StandardController(opp2); System.CurrentPageReference().getParameters().put('id', opp2.id); OpportunityClosedLost cOpp4 = new OpportunityClosedLost(sc4); System.debug(cOpp4.isEc); update opp2; //Test Opportunity Edit Page vRad Alliance Test.SetCurrentPageReference(New PageReference('Page.ClosedOpp')); ApexPages.Standardcontroller sc5 = new ApexPages.Standardcontroller(opp3); System.currentPageReference().getParameters().put('id', opp3.id); OpportunityClosedLost cOpp5 = new OpportunityClosedLost(sc5); System.debug(cOpp5.isAlliance); update opp3; //Test Opportunity Detail Page vRad Alliance Test.setCurrentPageReference(New PageReference('Page.ClosedOppView')); ApexPages.StandardController sc6 = new ApexPages.StandardController(opp3); System.currentPageReference().getParameters().put('id', opp3.id); OpportunityClosedLost cOpp6 = new OpportunityClosedLost(sc6); System.debug(cOpp6.isAlliance); update opp3; } }

 

  • August 31, 2009
  • Like
  • 0

I am test designing a custom application and have it all configured nicely, but need some help with the code as I'm a spring newbie in this area.

 

I am very familiar with HTML etc and have recently been researching apex/java style syntax and structure and it's a very slow process.

 

I understand you need to have classes defined and then you can create trigger scripts and visualforce pages that interact with the classes.

 

I understand the class types and the basic concept of methods but the details here-in are where I am finding it hard to self teach myself - Let alone achieve my goal.

 

Should I be using IDE? How does one find the correct code operators and how to use them? Anyway I find myself typing in lines of code just guessing and realising I'm like a blind man feeling around in a room of buttons hoping I press the right one. I have done the fundamentals course and are trying to get my head around the cook book. But I'm getting into the hard code stuff now.

 

I would be grateful if someone could shine a torch around for me in my current goal before I go for a personal educational course on this. 

 

My Goal:

 

In a force.com custom app I have an Object (tab - arbitrarily called "Items") that creates an item as an auto number record (on clicking new button)

 

Then takes me to the create page where I specify the related contact / account and other info

 

I have a number field in this object and which also appears on the create page which is "Number of items"

 

Now the idea is that the information entered on the create page will look at the "Number of items" and then create identical records from the entered information, but with unique record entries in the database.

 

For example: I fill in the item details in the fields on the create page and specify "Number of items = 5" (type '5' in the field)

 

I want it to create 5 new item records using the Auto Number record sequence


ITEM-001

ITEM-002

ITEM-003

ITEM-004

ITEM-005

 

Seems logical and simple enough, but making it happen is proving difficult for me.

 

I figure, I need to use a trigger to replicate the record, so use 'before insert' to kick in when the save button is pressed to create the record(s) and some how have it look at the field with the amount of iterations and have some code that makes it 'stamp' that many iterations. And that I need to define this as a class.

 

Either that or I could create a visualforce wizard page that looks more familiar to me from my html coding experience to replace the standard record create page (on clicking new) where I need to define the class as well.

 

 

What I am wondering - Is this a simple coding task that I am just not good enough yet to understand? Considering I have been researching for a day now and have not come much closer. Is this something that someone out here could think "Oh yes you use this and that and there you go" or does this kind of thing take many days/hours of development?

 

If it is a straight forward hand full of lines could someone show me some code so I can attempt to reverse engineer it for my understanding. Or even the way I should structure the class and what code operators I should be looking at.

 

I feel like I have the idea in the logic but I can't translate it into code.

 

Any help is much appreciated as I really want to learn how to do this rather than pay to have it done for me. (I'm trying to learn to be a developer even though I'm totally newb). Even advise on how to learn for someone at my level

 

TIA

 

 

How can we throw exception in Apex. I am trying do something like:

 

 

 

 

public class testExpt
{
public void exptTesting(Test_Object__c[] testObjectArray)
{
for (Test_Object__c t: testObjectArray)
{
if(t.test_field__c < 25.00)
{
throw new Exception('This is bad number');
}
}
}
}

 

 

 How can I achieve this in Apex?

 

Hello Everyone,


I want to append the effective date' month and year to the opportunity name when the user saves the record.  For example, if the opportunity name is 'Joe's Pizza' and the effective date is '09/26/09' then when the record is saved and views it should show 'Joes Pizza 09/09'.  The requirement is for the opportunity name to end with the mm/yy of the effective date and currently the users are manually typing this in and sometimes making typo's.

 

This is what I have but I know it does not work so I am asking for a little help.  One thing I do not know is how to concatenate in Apex among many other things as you can tell.  Is there a resource that gives all syntax for all built in methods, functions, etc for Apex.

 

 

trigger AppendMMYYEffectiveDate2OppName on Opportunity (before insert) {
    Name = Name || Month(Effective_Date__c.month) || '/' & Effective_Date__c.year);
}

 

I have a test method that looks like the following:

 

 

@isTest
private class systemTest() {
static testMethod void runTest1() {
account a = new account(name='Test Person');
insert a;
contact c = new contact(firstname='Test', lastname='Person', accountid=a.id);
insert c;
RecordType rt = [select id from recordtype where sobjecttype = 'Account' and name = 'Test'];
a.recordtypeid = rt.id;
update a;
}
}

The wrinkle here is that the named RecordType is a person account record type. So, ultimately, what I am trying to do is, in a test method, create a person account and then run a test against it (the trigger in on the account object, as person accounts do not trigger contact triggers).

 

Does anyone have an idea why this might be happening? I do not see anything on the forums or in the documentation to explain this. The error occurs at the line in bold above. The error does not state which field is failing. However, if I remove the line"a.recordtypeid = rt.id", the code passes, but my trigger won't work without this bit of logic in place (it's designed to work specifically with person accounts).

 

I have a VF page ( VF page1)  that is using a extention Controller to display case history. I have another VF page ( VF page2 )  that will render a printable version of the Case history. I would like to add a command button ( <apex:commandButton) to allow VF page1 to call VF Page2. Is this possible or is there a better way to acomplish this?

 

Regards,

Any way to get the Name or Id of the current Visual Force page from within the controller class?
Message Edited by Vintara on 08-13-2009 01:06 PM

Help please.....

I am new to coding in general so please go easy on me.  I got some help with my code but can't seem to figure out why I am getting a "System.NullPointerException: Attempt to de-reference a null object" error from my trigger every time I save.  Here is the scenario:

Basically do screenings and we record Total_cash__c, Total_charges__c, and Total_checks__c collected on our opportunities.  We needed a way to link each opportunity to a custom object Deposit__c and be able to sum each related field on the Deposit__c.  There will never be more than 10 opportunities attached to one Deposit via lookup. Because I cannot create a master-detail with an opportunity to run a roll-up I need to do it with a trigger on an opportunity with a lookup field to the Deposit custom object.  My code compiles but gives me the de-reference a null object error and I can figure out why. 

The error starts here.  Am I doing something wrong in the way I am accessing and trying to set the value of the fields of Sum_of_Cash__c, Sum_of_Checks, Sum_of_Charges   ??The fields are created on the Deposit__c custom object and of the same type on the related opportunity.

thisDeposit.Sum_of_Cash__c = totalSumCash;

 

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

//instantiate opportunity

Opportunity thisScreening = Trigger.New[0];

// retrieve from the DB all of the opportunities related to the current related deposit

List<Opportunity> screenings = [SELECT Deposited__r.Name, Total_cash__c, Total_checks__c, Total_charges__c
FROM Opportunity WHERE Deposited__c =: thisScreening.Deposited__c];

//instantiate this related deposit

Deposit__c thisDeposit = thisScreening.Deposited__r;

// init variables for sum
double totalSumCash = 0, totalSumChecks = 0, totalSumCharges = 0;

//iterate through each opportunity in this list, calculate the sum on the deposit

for(Opportunity o :screenings){
totalSumCash += o.Total_Cash__c;
totalSumCharges += o.Total_Charges__c;
totalSumChecks += o.Total_Checks__c;
}
thisDeposit.Sum_of_Cash__c = totalSumCash;
thisDeposit.Sum_of_Checks__c = totalSumCash;
thisDeposit.Sum_of_Credit__c = totalSumCash;
// update the related deposit record in the DB
update thisDeposit;
}
Thanks for helping anyone who tackles this 

I'm pretty new to salesforce so I was wondering if the following is possible. When a new contact is being created, is it possible to use some custom fields on that contact object to generate a new account and then relate the contact to it. I'm guessing this could be done using an Apex trigger. If anyone has any pointers or sample code, I would apprecaite it.

 

Thanks,

Phillip

Hi ,

Below is the class which i am using to retrieve leadis and contactids from campaign which are a total of more then 2000 records from select query using for loop.

 

public class Test

{

   Set<Id> leadid = new Set<Id>();

        Set<Id> contactid = new Set<Id>();

        List<String> emails=new List<String>();

 

public void TestMethod()

{

 

  for(campaignmember camp:[Select leadid,contactid from campaignmember where campaignid=:'campaignId']) {

  leadid.add(camp.leadid);

contactid.add(camp.contactid); 

 

 

 

 

here i am able to run the query which has more than 2000 records in the for loop but unable to add the leadid and contactid to the List<Id> (i.e  leadid , contactid) respectively as shown above.

An exception - collection exceeds maximum size: 1001 is being disaplayed.

 

My actual intenstion is to get the leadids and contactids and run the respective select query and add the email address to a list string emails.

 for (Contact cnt: [Select Email from contact WHERE Id IN :contactid]) 

 {

         if(cnt.Email != null)

         {

              emails.add(cnt.Email);

         }

 } 

 

can any one help me out.Thanks in advance

 

Thanks 

prashanth. 

 

 

  • September 10, 2009
  • Like
  • 0

Hi,

 

Inside Contact I'd like to look for all contacts whose first name + ' ' + last name equals a local varialbe, say myVar. I can't figure out how to do the concatenation. I've tried :(FirstName + ' ' + LastName) and that didn't work. This is an inline query. Any ideas please? Thanks!

  • September 09, 2009
  • Like
  • 1
I'm writing a trigger to determine which fields have changed when an sObject is updated. This code must be future-proof, so, I do not want to hard code any field names - does anyone know of a way of acheiving this?
  • September 09, 2009
  • Like
  • 0

Hi,

 

I want to process around 10,000 records using Apex. While querying on object I have limited to 1000 records at a time but I just want to know, "How can I get only those records, which has not been processed/ queried."? So that I can process 1000 records every time in loop.

We have a custom object for Contact Roles. A field in Contacts (the gone field) updates the value of a field in 'Contact Roles', and a field in Contact Roles when updated (not one field but a combination of fields) has to set the value of a field in Contact. I know its a loop, but the requirements are such that I cant think of a work around. The trigger in 'Contact Roles' has to be an 'after', while the one in Contact is 'before'

 

Is there a way to specify the order in which these triggers are executed, or stop execution of one trigger till the other completes its execution?

 

Thanks,

Saania

  • September 03, 2009
  • Like
  • 0

Hi All,

          I am new to apex and SFDC development. I am trying to create a new account(tried contact too) using apex class and I am trying to run the following apex class on salesforce sandbox using the 'run test' button the code runs successfully but when I browse for that contact/account I am not seeing the data.

 

Could anyone explain what is going wrong here?

 

public class testAccountCopy {
public static testmethod void t1()
{
Account acct = new Account(Name = 'Siva Account', account_name_copy__c = 'Siva Account', account_category__c='Customer');
insert acct ;

}
}

  • September 03, 2009
  • Like
  • 0

Folks,

I have 200 assignment rule entries on my Lead object. Now I want to migrate them to different sandboxes. Looks like there is no automated way to do this either through ANT Migration or Eclipse tool. I am not able to figure out where(which object) does salesforce store these rule entries. It all looks grim because I may have to recreate all the 200 rule entries manually in other sandboxes.

 

If anyone know a better solution, please let me know. I would appreciate your response.

 

Thanks.

To augment Web2Case's matching* in SFDC, I am attempting to build a relationship between the domain name within the submitted email address to the Asset and/or Account.

trigger domainMatch on Case (before insert) { for (Case c : Trigger.new) { String WebEmail = c.SuppliedEmail; System.debug('WebEmail = ' + WebEmail); // Find where the @ sign occurs Integer index = WebEmail.indexOf('@', 0); System.debug('index = ' + index); // Extract all text after the @ sign String emailDomain = WebEmail.substring(index+1); System.debug('emailDomain = ' + emailDomain); // When the Contact has not been matched, search through Account & Asset for the Domain if ((c.Contact == null) && (index != -1)) { if ([SELECT a.Name from Account a WHERE a.Name = :emailDomain] != null) { c.Account = [SELECT a.id from Account a WHERE a.Name = :emailDomain]; update c.Account; System.debug('c.Account = ' + c.Account); } if ([SELECT a.Name from Account a WHERE a.Name = :emailDomain] != null) { c.Asset = [SELECT a.id from Asset a WHERE a.Name = :emailDomain]; update c.Asset; System.debug('c.Asset = ' + c.Asset); } } } }

 

From looking at the debug logs (below) I have extracted the domain name from the email address and am able to find the appropriate ID in SFDC, but the lookup field on the Case record does not appear to be linked to the Asset or Account. 

 

How can I link the case to the Account and/or Asset?

 *** Beginning domainMatch on Case trigger event BeforeInsert for null

20090902190439.204:Trigger.domainMatch: line 14, column 5: SelectLoop:LIST:SOBJECT:Case
20090902190439.204:Trigger.domainMatch: line 17, column 5: WebEmail = nosuchuser@domain.com
20090902190439.204:Trigger.domainMatch: line 22, column 5: index = 10
20090902190439.204:Trigger.domainMatch: line 26, column 5: emailDomain = domain.com
20090902190439.204:Trigger.domainMatch: line 30, column 17: SOQL query with 1 row finished in 44 ms
20090902190439.204:Trigger.domainMatch: line 31, column 29: SOQL query with 1 row finished in 21 ms
20090902190439.204:Trigger.domainMatch: line 32, column 17: Update: SOBJECT:Account
20090902190439.204:Trigger.domainMatch: line 32, column 17:     DML Operation executed in 110 ms
20090902190439.204:Trigger.domainMatch: line 33, column 17: c.Account = Account:{Id=0016000000MKEMVAA5}
20090902190439.204:Trigger.domainMatch: line 35, column 17: SOQL query with 1 row finished in 30 ms
20090902190439.204:Trigger.domainMatch: line 36, column 27: SOQL query with 1 row finished in 44 ms
20090902190439.204:Trigger.domainMatch: line 37, column 17: Update: SOBJECT:Asset
20090902190439.204:Trigger.domainMatch: line 37, column 17:     DML Operation executed in 75 ms
20090902190439.204:Trigger.domainMatch: line 38, column 17: c.Asset = Asset:{Id=02i60000004B2vBAAS}

Cumulative resource usage:

Resource usage for namespace: (default)
Number of SOQL queries: 4 out of 20
Number of query rows: 4 out of 1000
Number of SOSL queries: 0 out of 0
Number of DML statements: 2 out of 20
Number of DML rows: 2 out of 100
Number of script statements: 14 out of 10200
Maximum heap size: 0 out of 200000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 10
Number of record type describes: 0 out of 10
Number of child relationships describes: 0 out of 10
Number of picklist describes: 0 out of 10
Number of future calls: 0 out of 10
Number of find similar calls: 0 out of 0
Number of System.runAs() invocations: 0 out of 0

Total email recipients queued to be sent : 0

*** Ending domainMatch on Case trigger event BeforeInsert for null

 

BTW, I know that I need to build better bulk processing into this code . . . that's the next challenge.

 

==================================

* By default, Web2Case only compares the complete email address to the Email address within Contact records.  If anyone else at that company submits a case and they do not have a Contact record with their email address, their case is not associated with that Account nor Asset.

Apex Trigger Error: RECORD TYPE UPDATE: System.NullPointerException: Attempt to de-reference a null object

 

Hi,

I am getting an error message with a trigger on case. Cant figure what I am doing wrong.

Thanks in advance for any help with this.

 

Scenario: Apex Trigger to update record type based on TYPE value on a case. Fetching record type ID where record type name is 'SR'

 

Error on Save:  

Error:Apex trigger Case_Record_Type_Update caused an unexpected exception, contact your administrator: Case_Record_Type_Update: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.Case_Record_Type_Update: line 22, column 34

 

I have tried with some changes in the below code but same error each time.

 

CODE:

 

 

trigger Case_Record_Type_Update on Case (before insert, before update) {

   for (Case cs : Trigger.new) {

      if ((Trigger.isInsert | Trigger.isUpdate) && cs!= null){  

          Schema.DescribeSObjectResult DSOR = Schema.SObjectType.Case;          

          Map<String,Schema.RecordTypeInfo> rtMapByName = DSOR.getRecordTypeInfosByName();

      

       if (cs.Type == 'Service Request') {

           if (cs.Status == 'Accept' | cs.Status == 'Disregard') {

             cs.Subject = 'Accept/Disregard';

             Schema.RecordTypeInfo rtByName = rtMapByName.get('SR');

             Id NewRecordTypeforCase = rtByName.getRecordTypeId(); <--- ERROR LINE

             cs.RecordTypeId = NewRecordTypeforCase;

 

         } // End If Accept/Disregard

      } // End If Service Request

 

    } // End If Not NUll check

  } // End For Loop on Case

} // End Trigger Block

 

 

 

 

DEBUG LOG:

 

*** Beginning SetAssetAccount on Case trigger event BeforeUpdate for 500T0000001fVim

20090902190242.983:Trigger.SetAssetAccount: line 8, column 2: SelectLoop:LIST:SOBJECT:Case
20090902190242.983:Trigger.SetAssetAccount: line 18, column 2: >>>>>Changed Asset IDs: {}

Cumulative resource usage:

Resource usage for namespace: (default)
Number of SOQL queries: 0 out of 20
Number of query rows: 0 out of 1000
Number of SOSL queries: 0 out of 0
Number of DML statements: 0 out of 20
Number of DML rows: 0 out of 100
Number of script statements: 6 out of 10200
Maximum heap size: 0 out of 200000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 10
Number of record type describes: 0 out of 10
Number of child relationships describes: 0 out of 10
Number of picklist describes: 0 out of 10
Number of future calls: 0 out of 10
Number of find similar calls: 0 out of 0
Number of System.runAs() invocations: 0 out of 0

Total email recipients queued to be sent : 0
Static variables and sizes:
SetAssetAccount:assetIds:4
SetAssetAccount:idx:4


*** Ending SetAssetAccount on Case trigger event BeforeUpdate for 500T0000001fVim

*** Beginning Case_Record_Type_Update on Case trigger event BeforeUpdate for 500T0000001fVim

20090902190242.991:Trigger.Case_Record_Type_Update: line 2, column 2: SelectLoop:LIST:SOBJECT:Case
System.NullPointerException: Attempt to de-reference a null object

Trigger.Case_Record_Type_Update: line 22, column 34


Cumulative resource usage:

Resource usage for namespace: (default)
Number of SOQL queries: 0 out of 20
Number of query rows: 0 out of 1000
Number of SOSL queries: 0 out of 0
Number of DML statements: 0 out of 20
Number of DML rows: 0 out of 100
Number of script statements: 11 out of 10200
Maximum heap size: 0 out of 200000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 10
Number of record type describes: 1 out of 10
Number of child relationships describes: 0 out of 10
Number of picklist describes: 0 out of 10
Number of future calls: 0 out of 10
Number of find similar calls: 0 out of 0
Number of System.runAs() invocations: 0 out of 0

Total email recipients queued to be sent : 0
Stack frame variables and sizes:
  Frame0
    rtByName:0
    rtMapByName:326
    cs:0
    DSOR:153


*** Ending Case_Record_Type_Update on Case trigger event BeforeUpdate for 500T0000001fVim

 

 

thanks

Prashant

 

Edit 1 and 2: Added intend on Code snippet.

 
Message Edited by PrashantSakhuja on 09-02-2009 04:42 PM
Message Edited by PrashantSakhuja on 09-02-2009 04:43 PM

Hello,

 

I have two triggers.  One checks for duplicate opportunities and the auto populates the opportunity name with the account name + the mm/yy format of the effective date. The problem is they do not work together.  The dup checker does not detect what I automatically fill in from the other trigger!  Do I have to pull them together as one trigger or is there a way to create this logic in a class and then have one trigger call that class.  If you could give me some direction it would be appreciated.

 

Any way to get the Name or Id of the current Visual Force page from within the controller class?
Message Edited by Vintara on 08-13-2009 01:06 PM