• doughauck-corp
  • NEWBIE
  • 70 Points
  • Member since 2017

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 17
    Replies
Hi, Hope someone can help!

When I am calling a method from an instance of a class, I am getting the attempt to dereference a null object when calling a class error. I have tried building in validation to stop null values from being allowed to pass through but to no avail.

My code is below:
// department_Field_Population - Written by Brodie Lawton 10/01/2019
    // Class takes the current Case(s) and iterates through them. If the Department__c field is a triage department
    // and the owner is not a triage queue, then set Department__c to the appropriate department for the running user
    // 
    public Case[] department_Field_Population(List<Case> caseRecords){ 
        List<Case> toUpdate = new List<Case>();
        for (Case c : caseRecords){
            if (!(string.valueOf(c.Owner.Name).Contains('Triage')) && (c.Department__c.Contains('Triage'))){ //If the owner name contains triage, and the department does not
                if (UserInfo.getUserRoleId() == '00E0Y000000XzuUUAS'){ //If the user belongs to 2nd line support, change department__c to 2nd line
                    Case toAdd = new Case(Id = c.Id, Department__c = '2nd Line Support'); //Creates temp case to put into toUpdate list
                    toUpdate.add(toAdd);// Adds temp case to the toUpdate list
                }
                if (UserInfo.getUserRoleId() == '00E0Y000000x6oPUAQ'){ //If the user belongs to 1nd line support, change department__c to 1nd line
                    Case toAdd= new Case(Id = c.Id, Department__c = '1st Line Support'); //Creates temp case to put into toUpdate list
                    toUpdate.add(toAdd);// Adds temp case to the toUpdate list
                }
                if (UserInfo.getUserRoleId() == '00E1v000001ZGaMEAW' || UserInfo.getUserRoleId() == '00E1v000001ZGaHEAW'){ //If the user is a Salesforce user, change department to Dev team
                    Case toAdd = new Case(Id = c.Id, Department__c = 'Development Team');
                    toUpdate.add(toAdd);
                }
                if (UserInfo.getUserRoleId() == '00E1v000001ZGaCEAW'){ //If the user is a Salesforce user, change department to Dev team
                    Case toAdd = new Case(Id = c.Id, Department__c = 'Informatics Team');
                    toUpdate.add(toAdd);
                }
            }
        }
        return toUpdate;
    }
It's quite simple code (explanation included in comments), and I have always been able to get past this error before.

Hope someone can help me out!

Thanks.
 
I know that the proper way to set the fields on, for example, the Account BillingAddress is to set them individually (e.g. Account.BillingCity = 'Ur').  But I need a way to set the fields of an Address passed as an argument, where I don't know its source.  For example:
Account myAcct = new Account(Name='My Account');
Contact myCont = new Contact(FirstName='My', LastName='Contact');

SetCityAndState(myAcct.BillingAddress, 'Podunk', 'IA');
SetCityAndState(myAcct.ShippingAddress, 'Mahsoxarpachee', 'GA');
SetCityAndState(myCont.MailingAddress, 'Kuppakonakoffee', 'HI');

private void SetCityAndState(Address addr, string city, string state))
{
    addr.City = city;
    addr.State = state;
}

Now, I know the System.Address class has methods to get the values from a random Address field.  But in their wisdom, the SFDC designers have decided not to provide methods to set the values using that class.  (I would call it their "ineffable wisdom", but that would be a lie - I have in fact been "eff"-ing them under my breath all morning.)   There is also a reference in the Developers Guide to a Schema.Address standard object, but the Schema.getGlobalDescribe() method has never heard of it.  It probably isn't what I'm looking for anyway. 

This is for a highly-generalized SObject upload and creation class, so it needs to be generic.  Has anyone found a way to accomplish this (seemingly basic) task?

Thanks,
Doug
I am having a problem with the upsert DML command in an Apex class I'm using with my Visualforce page.

The user makes changes on a generic SObject, which is exposed as the editSObject property of my custom Apex class, called SObjectTreeNode (I'm not very inventive with names, sorry).  When the user hits the Save button, the SObjectTreeNode.upsertSObject() method is called to send the changes to the database, and then the page is refreshed.

When the page refreshes right after a Save, the new values show up in the changed fields just as they should.  Since refreshing the page includes a re-query of the associated SObject, I assumed this meant my changes were in the database.  Not so, though - refreshing the screen a second time, or navigating to the normal SFDC detail page for the object, shows the fields back at their original values.

Below is the upsertSObject() method - with some extra debug code - and its associated output.  (Please note that User__c is a custom text-only field that has no connection to the SFDC User object.  Sorry for the confusion, but I didn't name it.  I picked it for my example because I know there are no WF or Validation rules on this field, but all fields show the same behavior.)

Here is the code:
public SObjectTreeNode upsertSObject()
{
    if(!isEditable)
        throw new sObjectTreeNodeException('Error in node \'' + nodeName + '\': upsertSObject() can only be called on Editable nodes.');
    if(editSObject == null)
        throw new sObjectTreeNodeException('Error in node \'' + nodeName + '\': editSObject is null.');
    
    system.debug(' ');
    system.debug('Running upsertSObject()...');
    
    id editSObjId = (id)editSObject.get('id');
    sObject dbaseSObject = [select Id, User__c from Inspection__c where Id = :editSObjId limit 1];
    
    system.debug(' ');
    system.debug('Pre-Upsert Values:');
    system.debug(' - editSObject.id       = ' + editSObject.get('id'));
    system.debug(' - editSObject.User__c  = ' + editSObject.get('user__c'));
    system.debug(' - dbaseSObject.id      = ' + dbaseSObject.get('id'));
    system.debug(' - dbaseSObject.User__c = ' + dbaseSObject.get('user__c'));
    
    upsert editSObject;
    
    editSObjId = (id)editSObject.get('id');
    dbaseSObject = [select Id, User__c from Inspection__c where Id = :editSObjId limit 1];
    
    system.debug(' ');
    system.debug('Post-Upsert Values:');
    system.debug(' - editSObject.id       = ' + editSObject.get('id'));
    system.debug(' - editSObject.User__c  = ' + editSObject.get('user__c'));
    system.debug(' - dbaseSObject.id      = ' + dbaseSObject.get('id'));
    system.debug(' - dbaseSObject.User__c = ' + dbaseSObject.get('user__c'));
    
    system.debug('Completed upsertSObject()');
    system.debug(' ');
    
    return this;
}

And here is the log output:
20:06:06.3 (2285501897)|USER_DEBUG|[85]|DEBUG|Running upsertSObject()...
20:06:06.3 (2298707241)|USER_DEBUG|[90]|DEBUG| 
20:06:06.3 (2298739034)|USER_DEBUG|[91]|DEBUG|Pre-Upsert Values:
20:06:06.3 (2298843638)|USER_DEBUG|[92]|DEBUG| - editSObject.id       = a1HS0000001hrsRMAQ
20:06:06.3 (2298949438)|USER_DEBUG|[93]|DEBUG| - editSObject.User__c  = Barney Rubble
20:06:06.3 (2299062140)|USER_DEBUG|[94]|DEBUG| - dbaseSObject.id      = a1HS0000001hrsRMAQ
20:06:06.3 (2299176216)|USER_DEBUG|[95]|DEBUG| - dbaseSObject.User__c = Fred Flintstone
20:06:06.3 (2383815970)|USER_DEBUG|[102]|DEBUG| 
20:06:06.3 (2383854572)|USER_DEBUG|[103]|DEBUG|Post-Upsert Values:
20:06:06.3 (2384028718)|USER_DEBUG|[104]|DEBUG| - editSObject.id       = a1HS0000001hrsRMAQ
20:06:06.3 (2384148671)|USER_DEBUG|[105]|DEBUG| - editSObject.User__c  = Barney Rubble
20:06:06.3 (2384263266)|USER_DEBUG|[106]|DEBUG| - dbaseSObject.id      = a1HS0000001hrsRMAQ
20:06:06.3 (2384363465)|USER_DEBUG|[107]|DEBUG| - dbaseSObject.User__c = Barney Rubble
20:06:06.3 (2384393412)|USER_DEBUG|[109]|DEBUG|Completed upsertSObject()

As you can see, it's the same record before and after the upsert, but the value returned by the SOQL statement has changed to match the upserted value.   Any further queries in this same transaction - up until the page has been fully refreshed and my log comes to an end - will show the new value.  Any further refreshes, or navigation through normal SF pages, and the fields go back to their original values.

As far as I can tell, there are no errors encountered in this transaction, hence no reason to roll back changes.  (And my understanding is that rolled back changes wouldn't show up in a subsequent SOQL query, anyway.)   I am working with Visualforce, and in a Sandbox, if that makes any difference.  I can't find any documentation that says it should matter, though.

Can anyone tell me, what gives?

Thanks,
Doug
This has reared its ugly head once again. 
Ran this in Sandbox and was fine until it ran in Production. 

System.NullPointerException: Attempt to de-reference a null object

Class.VolumeMarketBatch.execute: line 39, column 1
 
global with sharing class VolumeMarketBatch implements Database.batchable<sObject> {  // updated implements 1-13-2019 nfs
    
    
    global Database.QueryLocator start(Database.BatchableContext info) {
        
        // Go through and get the list of volume market that has changed
        String returnQuery = 'select Id, Remodeler_Account__c, Postal_Code__c ' +
            '   from Zip_Assignment__c ' +  
            '   where Postal_Code__r.Volume_Market_Update__c = true';
        
        return Database.getQueryLocator(returnQuery); 
        
    }
    
    global void execute(Database.BatchableContext info, List<sObject> sobjectList) {
        // Gets the account and postal codes that have changed
        List<Id> accountIdList = new List<Id>();
        List<Id> pcIdList = new List<Id>();
        for (sObject obj : sobjectList) {
            Zip_Assignment__c zipAssign = (Zip_Assignment__c) obj;
            if (zipAssign.Remodeler_Account__c != null && zipAssign.Postal_Code__c != null){ // added 1-13-2019 nfs
                accountIdList.add(zipAssign.Remodeler_Account__c);
                pcIdList.add(zipAssign.Postal_Code__c);
            }          
        }
        
        
        // Goes through the accounts and postal codes that have changed and sets the Volume Market field on the account
        Map<Id, Account> accountList = new Map<Id, Account>([select Id, Volume_Market__c from Account where Id = : accountIdList]); 
        Map<Id, Postal_Code__c> pcList = new Map<Id, Postal_Code__c>([select Id, Volume_Market_Update__c, Volume_Market__c from Postal_Code__c where Id = : pcIdList]);
        
        for (sObject obj : sobjectList) {
            Zip_Assignment__c zipAssign = (Zip_Assignment__c) obj;
            Account a = accountList.get(zipAssign.Remodeler_Account__c);
            Postal_Code__c pc = pcList.get(zipAssign.Postal_Code__c);
            //System.Debug(pc.Volume_Market__c + a.Volume_Market__c);
            if (pc != null) { 
                if (pc.Volume_Market__c != null) {
                    a.Volume_Market__c = pc.Volume_Market__c;
                }
                pc.Volume_Market_Update__c = false;
            }
        }
        
        // updates both account and postal codes
        upsert accountList.values();
        upsert pcList.values();
    }
    
    global void finish(Database.BatchableContext info) {
        
        
    }
    
}

 
Hi, Hope someone can help!

When I am calling a method from an instance of a class, I am getting the attempt to dereference a null object when calling a class error. I have tried building in validation to stop null values from being allowed to pass through but to no avail.

My code is below:
// department_Field_Population - Written by Brodie Lawton 10/01/2019
    // Class takes the current Case(s) and iterates through them. If the Department__c field is a triage department
    // and the owner is not a triage queue, then set Department__c to the appropriate department for the running user
    // 
    public Case[] department_Field_Population(List<Case> caseRecords){ 
        List<Case> toUpdate = new List<Case>();
        for (Case c : caseRecords){
            if (!(string.valueOf(c.Owner.Name).Contains('Triage')) && (c.Department__c.Contains('Triage'))){ //If the owner name contains triage, and the department does not
                if (UserInfo.getUserRoleId() == '00E0Y000000XzuUUAS'){ //If the user belongs to 2nd line support, change department__c to 2nd line
                    Case toAdd = new Case(Id = c.Id, Department__c = '2nd Line Support'); //Creates temp case to put into toUpdate list
                    toUpdate.add(toAdd);// Adds temp case to the toUpdate list
                }
                if (UserInfo.getUserRoleId() == '00E0Y000000x6oPUAQ'){ //If the user belongs to 1nd line support, change department__c to 1nd line
                    Case toAdd= new Case(Id = c.Id, Department__c = '1st Line Support'); //Creates temp case to put into toUpdate list
                    toUpdate.add(toAdd);// Adds temp case to the toUpdate list
                }
                if (UserInfo.getUserRoleId() == '00E1v000001ZGaMEAW' || UserInfo.getUserRoleId() == '00E1v000001ZGaHEAW'){ //If the user is a Salesforce user, change department to Dev team
                    Case toAdd = new Case(Id = c.Id, Department__c = 'Development Team');
                    toUpdate.add(toAdd);
                }
                if (UserInfo.getUserRoleId() == '00E1v000001ZGaCEAW'){ //If the user is a Salesforce user, change department to Dev team
                    Case toAdd = new Case(Id = c.Id, Department__c = 'Informatics Team');
                    toUpdate.add(toAdd);
                }
            }
        }
        return toUpdate;
    }
It's quite simple code (explanation included in comments), and I have always been able to get past this error before.

Hope someone can help me out!

Thanks.
 
I am having a problem with the upsert DML command in an Apex class I'm using with my Visualforce page.

The user makes changes on a generic SObject, which is exposed as the editSObject property of my custom Apex class, called SObjectTreeNode (I'm not very inventive with names, sorry).  When the user hits the Save button, the SObjectTreeNode.upsertSObject() method is called to send the changes to the database, and then the page is refreshed.

When the page refreshes right after a Save, the new values show up in the changed fields just as they should.  Since refreshing the page includes a re-query of the associated SObject, I assumed this meant my changes were in the database.  Not so, though - refreshing the screen a second time, or navigating to the normal SFDC detail page for the object, shows the fields back at their original values.

Below is the upsertSObject() method - with some extra debug code - and its associated output.  (Please note that User__c is a custom text-only field that has no connection to the SFDC User object.  Sorry for the confusion, but I didn't name it.  I picked it for my example because I know there are no WF or Validation rules on this field, but all fields show the same behavior.)

Here is the code:
public SObjectTreeNode upsertSObject()
{
    if(!isEditable)
        throw new sObjectTreeNodeException('Error in node \'' + nodeName + '\': upsertSObject() can only be called on Editable nodes.');
    if(editSObject == null)
        throw new sObjectTreeNodeException('Error in node \'' + nodeName + '\': editSObject is null.');
    
    system.debug(' ');
    system.debug('Running upsertSObject()...');
    
    id editSObjId = (id)editSObject.get('id');
    sObject dbaseSObject = [select Id, User__c from Inspection__c where Id = :editSObjId limit 1];
    
    system.debug(' ');
    system.debug('Pre-Upsert Values:');
    system.debug(' - editSObject.id       = ' + editSObject.get('id'));
    system.debug(' - editSObject.User__c  = ' + editSObject.get('user__c'));
    system.debug(' - dbaseSObject.id      = ' + dbaseSObject.get('id'));
    system.debug(' - dbaseSObject.User__c = ' + dbaseSObject.get('user__c'));
    
    upsert editSObject;
    
    editSObjId = (id)editSObject.get('id');
    dbaseSObject = [select Id, User__c from Inspection__c where Id = :editSObjId limit 1];
    
    system.debug(' ');
    system.debug('Post-Upsert Values:');
    system.debug(' - editSObject.id       = ' + editSObject.get('id'));
    system.debug(' - editSObject.User__c  = ' + editSObject.get('user__c'));
    system.debug(' - dbaseSObject.id      = ' + dbaseSObject.get('id'));
    system.debug(' - dbaseSObject.User__c = ' + dbaseSObject.get('user__c'));
    
    system.debug('Completed upsertSObject()');
    system.debug(' ');
    
    return this;
}

And here is the log output:
20:06:06.3 (2285501897)|USER_DEBUG|[85]|DEBUG|Running upsertSObject()...
20:06:06.3 (2298707241)|USER_DEBUG|[90]|DEBUG| 
20:06:06.3 (2298739034)|USER_DEBUG|[91]|DEBUG|Pre-Upsert Values:
20:06:06.3 (2298843638)|USER_DEBUG|[92]|DEBUG| - editSObject.id       = a1HS0000001hrsRMAQ
20:06:06.3 (2298949438)|USER_DEBUG|[93]|DEBUG| - editSObject.User__c  = Barney Rubble
20:06:06.3 (2299062140)|USER_DEBUG|[94]|DEBUG| - dbaseSObject.id      = a1HS0000001hrsRMAQ
20:06:06.3 (2299176216)|USER_DEBUG|[95]|DEBUG| - dbaseSObject.User__c = Fred Flintstone
20:06:06.3 (2383815970)|USER_DEBUG|[102]|DEBUG| 
20:06:06.3 (2383854572)|USER_DEBUG|[103]|DEBUG|Post-Upsert Values:
20:06:06.3 (2384028718)|USER_DEBUG|[104]|DEBUG| - editSObject.id       = a1HS0000001hrsRMAQ
20:06:06.3 (2384148671)|USER_DEBUG|[105]|DEBUG| - editSObject.User__c  = Barney Rubble
20:06:06.3 (2384263266)|USER_DEBUG|[106]|DEBUG| - dbaseSObject.id      = a1HS0000001hrsRMAQ
20:06:06.3 (2384363465)|USER_DEBUG|[107]|DEBUG| - dbaseSObject.User__c = Barney Rubble
20:06:06.3 (2384393412)|USER_DEBUG|[109]|DEBUG|Completed upsertSObject()

As you can see, it's the same record before and after the upsert, but the value returned by the SOQL statement has changed to match the upserted value.   Any further queries in this same transaction - up until the page has been fully refreshed and my log comes to an end - will show the new value.  Any further refreshes, or navigation through normal SF pages, and the fields go back to their original values.

As far as I can tell, there are no errors encountered in this transaction, hence no reason to roll back changes.  (And my understanding is that rolled back changes wouldn't show up in a subsequent SOQL query, anyway.)   I am working with Visualforce, and in a Sandbox, if that makes any difference.  I can't find any documentation that says it should matter, though.

Can anyone tell me, what gives?

Thanks,
Doug

I was under the impression that Flows were automatically bulkified, but every time that one of my users uploads a list to SF, I get the error below.

Can someone provide a tips to help with this? The flow is being triggered by a process.
 

Error element Lead_Lookup (FlowRecordLookup).
This error occurred when the flow tried to look up records: Too many SOQL queries: 101. For details, see API Exceptions.
This report lists the elements that the flow interview executed. The report is a beta feature.
We welcome your feedback on IdeaExchange.
Flow Details
Flow Name: Lead_Datestamp_Update
Type: Autolaunched Flow
Version: 10
Status: Active
Flow Interview Details
Interview Label: 
Current User: Felipe Da Cruz (00541000001TeSw)
Start time: 7/20/2017 2:52 PM
Duration: 0 seconds
How the Interview Started
Felipe Da Cruz (00541000001TeSw) started the flow interview.
Some of this flow's variables were set when the interview started.
OldStatus = Working
LeadId = 00Q4100000KYN1HEAX
FAST LOOKUP: Lead_Lookup
Find all Lead records where:
Id Equals {!LeadId} (00Q4100000KYN1HEAX)
Assign those records to {!Lead}.
Save these field values in the variable: Datestamp_Nurturing__c, Datestamp_Ready__c, Datestamp_Working__c, Datestamp_DQ__c, Datestamp_Qualified__c, Datestamp_Qualified_Rejected__c, Datestamp_Lead_Conversion__c, Status, Cycle_Counter__c, Ready_Source__c, Ready_Channel__c, Last_DQ_Rejection_Reason__c, DQ_Rejected_Reason__c, MQL_Created__c, Notification_Sent_Robin_Ready__c
Result
Successfully found records.

FAST LOOKUP: Lead_Lookup
Find all Lead records where:
Id Equals {!LeadId} (00Q4100000KYN1HEAX)
Assign those records to {!Lead}.
Save these field values in the variable: Datestamp_Nurturing__c, Datestamp_Ready__c, Datestamp_Working__c, Datestamp_DQ__c, Datestamp_Qualified__c, Datestamp_Qualified_Rejected__c, Datestamp_Lead_Conversion__c, Status, Cycle_Counter__c, Ready_Source__c, Ready_Channel__c, Last_DQ_Rejection_Reason__c, DQ_Rejected_Reason__c, MQL_Created__c, Notification_Sent_Robin_Ready__c
Result
Failed to find records.

Error Occurred: Too many SOQL queries: 101
Hi, all -

I'm trying to set up a helper method to generate a ConnectApi.PollCapabilityInput class.  (This is part of a larger helper class to generate FeedItemInputs.)  According to the documentation, this class has two properties:
  • choices:  List<String> 
    • The choices used to create a new poll. You must specify 2–10 poll choices for each poll. 
    • Required for creating a poll.
  • myChoiceId:  String 
    • ID of an existing choice on the feed poll.  Used to vote on an existing poll. 
    • Required for voting on a poll.
Using the first one to add a poll seems fairly straight-forward, but I'm having trouble with how to use the myChoiceId to vote on a poll.  Specifically, once I create a PollCapabilityInput object with that field set, how do I use it?  Do I just add it to a blank FeedItemInput and post it?  What feed to I post it to, and what kind of FeedElement is it?

I would really like to see a complete example for this Capability, but I can't seem to find one, here or anywhere else.  Can someone point me toward such an animal?  If not, does anyone at least know how to use this class to vote on an existing poll?

Thanks,
Doug
 
Hi Experts,
What is the difference between Clone () and DeepClone() in Apex? When should we use what? Can someone explain with an example?

Thanks!

Hi, 

After clinking  an action in Component controller. i would like to call and method in PageController. and rerender a pannel in Main Page.

 

Page Start --------

<MyComponent>

[Component Action]      ------[ onclick of this action in Component Controller this component will rerender, but how can i rerender my pannel]     

</MyComponent>

 

 

<my pannel>

</my pannel>

Page Close -------

 

Please Help..

 

I want to create a dynamic select list. Below is my code:

 

Component.Apex.SelectList selectDynamic = new Component.Apex.SelectList();
        selectDynamic.multiselect = false;
        selectDynamic.value = stringList;
        Component.Apex.SelectOptions dynamicOptions = new Component.Apex.SelectOptions();
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('hi','hi'));
        dynamicOptions.value = options;
        selectDynamic.childComponents.add(dynamicOptions);

 

on the page load I'm getting error "Invalid selectOptions found. Use SelectOption type in Apex."

Hi,

 

 I have a page with component passing one attribute i.e.

<-- page-->

  <apex:page controller="testcontroller">

    <c:testcomponent objectname="Account"/>

  </apex:page>

   

 <-- component with controller -->

 

  <apex:component  controller="testcontroller1">

     <apex:attribute name="objectname" type="string"  description="" assignTo={!objname}/>

    <apex:dynamiccomponet componentvalue={!someList}/>

  </apex:component>

 

  public class testcontroller1  {

      public string objname {get;set;}

      public testcontroller1() {

           system.debug('............'+objname);      

     }

     public apex.componet.label getsomeList() {

           system.debug('...................'+objname);

     }

  }

 

 

problem:  objname is showing null in both places. let me know if i did anything wrong. is there is any way to get correct value for objname in any one of the place.

 

 

I am trying to trim leading characters from a string then using that string value in my where clause of my SQL query. I have found several references to a "TrimStart" function in java and .NET, but neither syntax appears to work in the trigger. See the commented code for the .NET "TrimStart" syntax. Does anyone have ideas how to trim leading characters and zeros.

 

Here is my code

trigger LookupBanker on Lead (before insert, before update) { Lead[] leads = Trigger.new; for(Lead lead:leads){ if (lead.employee_id__c!=null){ string origin = lead.employee_id__c; /* string originwoz = origin; originwoz = originwoz.TrimStart('0'); */ Account c = [Select Id, BID__pc FROM Account WHERE RecordTypeId = '012600000000000000' AND BID__pc = :originwoz][0]; lead.Banker_Name__c = c.Id; } } }