• _why the unlucky stiff
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 7
    Replies

Hello gentlemen, I am getting the famous 'attempt to de reference a null object error' when for this particular condition It is specifically happening because of this line - (comparing old value to new and making sure it's not the same). 

 

(opp.StageName != oldMap.get(opp.Id).StageName)

 

Here is the larger context - (line 11-12)

 

		// Declare Collections and variables
		final List<Opportunity> changedOpps = new List<Opportunity>();
		Set<Id> UserId = new Set<Id>();
		final String NewFleet = '012Q00000008rSIIAY';
		final String NewGovernment = '012Q00000008rSNIAY';
		
		// Create a map of Opportunities that are ClosedWon and have a particular RecordType
			System.debug('Before for loop');
		for (Opportunity opp : newMap.values()){
			System.debug('After length check: ' + newMap.Values());
			if ((opp.StageName != null) && (opp.StageName != oldMap.get(opp.Id).StageName)){
				System.debug('After length check 2: ' + opp.Name);
				if (opp.StageName == 'Closed Won') {
					System.debug('After Stage check: ' + opp.Name);
					if (opp.RecordTypeId == NewFleet|| opp.RecordTypeId == NewGovernment){
						System.debug('After RecordTypeCheck : ' + opp.Name);
						changedOpps.add(opp);
					}
				}
			}
		}

 

 

List<Account> newAccount = new List<Account>();    

vs.

List<Account> newAccount;

 

When would you declare and for what use? 

 

Hello, I am fairly new to Apex.I need to create a list of accounts for which it's owner has changed in an after update trigger. Can anyone show a sample code if this is simple enough?

 

Also, what would you use to compare and filter, Trigger.new & Trigger.old OR Trigger.newMap & Trigger.OldMap? Also, how to then update this back to the account object? The documentation does not have an example on this and  reading it further confused me. Am I on the right track? This can't be that difficult, can it?

 

I took a stab at this below and this completely does not work.

 

public static void ownrChangeUpdate(List<Account> newAccs, List<Account> oldAccs){
		
		List<Account> changedAccs;
		List<Account> updateAccs;
		Set<Id> UserId = new Set<Id>();
		
		for (Integer i = 0; i < newAccs.size(); i++) {
			if (oldAccs[i].OwnerId != newAccs[i].OwnerId) {
				changedAccs.add(newAccs[i]);
			}
        }
        
        for(Account a :changedAccs){ 
             UserId.add(a.OwnerId);
		}
		
		Map<ID,User> Usermap= new Map<ID,User>([SELECT ID, Group__c, Branch__c from User where ID IN :UserId]) ;
		
		For(Account Acc :changedAccs) { 
                    User thisUser = UserMap.get(Acc.OwnerId);
                If (thisUser != null) {
    			
                    Acc.Group__c = thisUser.Group__c;
                    Acc.Branch__c = thisUser.Branch__c;
                    updateAccs.add(Acc);
            	}    
            	  
          }	
		
		if(!updateAccs.isEmpty()){
                update updateAccs;
            }
			  
				
	}

 

Hello, I have figured out how to login and query records. I can store the resultset in a strongly typed Object like Account or sObject for partner WSDL or just the plain Queryresult. However, I now need to move these records (insert) them into an internal database. I am new to java. Can anyone offer any pointers on how to do this?

What would the syntax be for the following requirement in SOQL?

 

I have threee fields:

1. First Name

2. Last Name

3. Description (Long Text Area)

 

I need to get all names which have the word 'Developer' (or any keyword) in the 'Description' Long Text area. I have hit the wall trying to use the keywords 'contains' or 'includes' without success. Doesn anyone know how to build a SOQL using these both keywords?

 

Any help much appreciated.

Hello I have a page that I am trying to generate as a PDF. I am trying to access values from a custom object 'FieldVisitors__c' to display on the PDF page. So far, I have had no luck. Could some gentleman explain how to access fields from this custom object to display on the PDF page?

 

As you can see below, I was only able to get the User name and date to work. I need to access fields like FieldVisitors__c.Subject

Account Name (A lookup field to Account object) etc...

 

Can someone point me to the right direction? I am much obliged.

 

<apex:page standardController="FieldVisitors__c" renderAs="PDF" >
    <h1>Field Visit Report</h1>
    <h2>Report Created By {!$User.FirstName} on {!NOW()}</h2>
</apex:page>

 

Hello Folks, I need a set of users under different profiles to build data for my test case. What is the best way to go about this? If I try to build this Manually, I face a series problems, i.e DML will fail saying OwnerId is missing etc. Can anybody guide me the best way to do this?

list<User> lUsr = new list<User>();
        
        User oUsr = new User();
        oUsr.FirstName = 'James';
        oUsr.LastName = 'Dean';
        oUsr.Email = 'james@dean.com';
        oUsr.Username = 'jdean@jamesdean.com';
        oUsr.Alias = 'jdean';
        oUsr.CommunityNickname = 'j1234';
        OUsr.TimeZoneSidKey = 'America/Denver';
        oUsr.LocaleSidKey = 'en_CA';
        oUsr.EmailEncodingKey = 'ISO-8859-1';
        oUsr.ProfileId = '00eF0000000WOiJIAW';
        OUsr.LanguageLocaleKey = 'en_US';
        lUsr.add(oUsr);

 

Hello Folks, I am a complete newbie to Apex. I have a simple custom controller class for displaying a VF page when a user clicks a custom button. I can't figure out for the life of me how to write a test class for this. Please see the Controller Class and the Test class 'attempt' I made below. Could someone be gracious enough to point me to the right direction?

 

The context from VF to get to this button is : Create a new Case froma record type --> Create a new record for 'Contract Admin Entry' object (available onec the case is created) --> Custom button clicked within this page (custom controller called)

 

Here is the Custom Controller :

 

public class CustomSettingController {
	public string CAEID {Get;set;}
	public Contract_Admin_Entry__c oCAE {get;set;}
	public boolean shouldRender {Get;set;}
	
// Default Constructor
//	 public CustomSettingController(){  }

// Custom Constructor
  public CustomSettingController(ApexPages.StandardController ctl){
	shouldRender = false;
  	CAEID=ApexPages.currentPage().getParameters().get('ID');
  	if(CAEID!=''){
  		 		
  		list<Contract_Admin_Entry__c> lCAE = [SELECT Case_Type__c, Case__c FROM Contract_Admin_Entry__c where ID=:CAEID];
  		if(lCAE.size()>0){
  			oCAE = lCAE.get(0);
			shouldRender = true;
  		} 
  	}
  }
  
// Main Method	
  public list<ContractAdmin__c> getCaseTypeProcesses(){
  		 list<ContractAdmin__c> lCaseTypeProcess = [Select c.Case_Type__c, c.Process__c From ContractAdmin__c c where Case_Type__c=:oCAE.Case_Type__C order by Case_Type__c limit 1000];
  		 if(lCaseTypeProcess==null || lCaseTypeProcess.size()==0){
  		 	ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'No Checklist available for this Case Type.'));
  		 }
    		return lCaseTypeProcess;

  }
}

 Here is my attempt to write the Test Class :

 

@isTest
private class CustomSettingController_Test {

    static testMethod void myUnitTest() {
        
        // TO DO: implement unit test
        //Build 8 objects of ContractAdmin__c
        
        list<ContractAdmin__c> lCA = new list<ContractAdmin__c>();
        
        ContractAdmin__c oCA = new ContractAdmin__c();
        ocA.Case_Type__c = 'Canada ADP';
        oCA.Process__c = 'Tier - 1';
        lCA.add(ocA);
        
     	ContractAdmin__c oCA1 = new ContractAdmin__c();
        ocA1.Case_Type__c = 'Canada ADP';
        oCA1.Process__c = 'Are T and C’s attached or T and C confirmation page included';
        lCA.add(ocA1);   
        insert lCA;
        

        //build Case
        
        list<Case> lCase = new list<Case>();
        
        Case oCase = new Case();
        oCase.Tier__c = 'Tier 1';
        oCase.Origin = 'Usage Adjustment';
        oCase.Status = 'Received';
        lCase.add(oCase);

      
        Case oCase1 = new Case();
        oCase1.Tier__c = 'Tier 2';
        oCase1.Origin = 'Contract Admin';
        oCase1.Status = 'In-Progress';
        lCase.add(oCase1);
        
        insert lCase;
        
        //build Contract_Admin_Entry__c
        
        list<Contract_Admin_Entry__c> lCAE = new list<Contract_Admin_Entry__c>();
        
        Contract_Admin_Entry__c oCAE = new Contract_Admin_Entry__c();
     	oCAE.Case_Type__c = 'Canada ADP';
  //   	oCAE.Id = 'CA-00000009';
     	lCAE.add(oCAE);
     	
     	Contract_Admin_Entry__c oCAE1 = new Contract_Admin_Entry__c();
     	oCAE1.Case_Type__c = 'Canada Transfer';
  //   	oCAE1.Id = 'CA-00000010';
     	lCAE.add(oCAE1);
     	
     	insert lCAE;
     	
     	// build Account
     	
     	list<Account> lACC = new list<Account>();
        
        Account oACC = new Account();
     	oACC.Name = 'Ryans Training Center';
     	lACC.add(oACC);
     	
     	Account oACC1 = new Account();
     	oACC1.Name = 'RPM Inc';
     	lACC.add(oACC1);
     	
     	Account oACC2 = new Account();
     	oACC2.Name = 'LDE2';
     	lACC.add(oACC2);
     	
     	insert lACC;
     	
     	
     	// build Contact
     	
     	list<Contact> lCON = new list<Contact>();
        
        Contact oCON = new Contact();
    	oCON.FirstName = 'Anne';
    	oCON.LastName = 'McGraw';
//	   	oCON.Name;
     	lCON.add(oCON);
     	
     	Contact oCON1 = new Contact();
     	oCON1.FirstName = 'Kelly';
     	oCON1.LastName = 'McGill';
//     	oCON1.Name;
     	lCON.add(oCON1);
     	
     	Contact oCON2 = new Contact();
     	oCON2.FirstName = 'Jeff';
     	oCON2.LastName = 'Althaus';
 //    	oCON2.Name;
     	lCON.add(oCON2);
     	
     	insert lCON;
     	
     //Test coverage for the CaseTypeProcess visualforce page
		PageReference pageRef = Page.CaseTypeProcess;
		Test.setCurrentPageReference(pageRef);
		
	// create an instance of the controller
     	Test.startTest();
     	
     	Contract_Admin_Entry__c tCAE = new Contract_Admin_Entry__c();
   		ApexPages.Standardcontroller sc = new ApexPages.Standardcontroller(tCAE);
    	CustomSettingController csc = new CustomSettingController(sc);   	
  //   	List nextPage = csc.getCaseTypeProcesses();
     	
     	
     	Test.stopTest();
    }
     
}

 

Hello gentlemen, I am getting the famous 'attempt to de reference a null object error' when for this particular condition It is specifically happening because of this line - (comparing old value to new and making sure it's not the same). 

 

(opp.StageName != oldMap.get(opp.Id).StageName)

 

Here is the larger context - (line 11-12)

 

		// Declare Collections and variables
		final List<Opportunity> changedOpps = new List<Opportunity>();
		Set<Id> UserId = new Set<Id>();
		final String NewFleet = '012Q00000008rSIIAY';
		final String NewGovernment = '012Q00000008rSNIAY';
		
		// Create a map of Opportunities that are ClosedWon and have a particular RecordType
			System.debug('Before for loop');
		for (Opportunity opp : newMap.values()){
			System.debug('After length check: ' + newMap.Values());
			if ((opp.StageName != null) && (opp.StageName != oldMap.get(opp.Id).StageName)){
				System.debug('After length check 2: ' + opp.Name);
				if (opp.StageName == 'Closed Won') {
					System.debug('After Stage check: ' + opp.Name);
					if (opp.RecordTypeId == NewFleet|| opp.RecordTypeId == NewGovernment){
						System.debug('After RecordTypeCheck : ' + opp.Name);
						changedOpps.add(opp);
					}
				}
			}
		}

 

 

List<Account> newAccount = new List<Account>();    

vs.

List<Account> newAccount;

 

When would you declare and for what use? 

 

Hello, I am fairly new to Apex.I need to create a list of accounts for which it's owner has changed in an after update trigger. Can anyone show a sample code if this is simple enough?

 

Also, what would you use to compare and filter, Trigger.new & Trigger.old OR Trigger.newMap & Trigger.OldMap? Also, how to then update this back to the account object? The documentation does not have an example on this and  reading it further confused me. Am I on the right track? This can't be that difficult, can it?

 

I took a stab at this below and this completely does not work.

 

public static void ownrChangeUpdate(List<Account> newAccs, List<Account> oldAccs){
		
		List<Account> changedAccs;
		List<Account> updateAccs;
		Set<Id> UserId = new Set<Id>();
		
		for (Integer i = 0; i < newAccs.size(); i++) {
			if (oldAccs[i].OwnerId != newAccs[i].OwnerId) {
				changedAccs.add(newAccs[i]);
			}
        }
        
        for(Account a :changedAccs){ 
             UserId.add(a.OwnerId);
		}
		
		Map<ID,User> Usermap= new Map<ID,User>([SELECT ID, Group__c, Branch__c from User where ID IN :UserId]) ;
		
		For(Account Acc :changedAccs) { 
                    User thisUser = UserMap.get(Acc.OwnerId);
                If (thisUser != null) {
    			
                    Acc.Group__c = thisUser.Group__c;
                    Acc.Branch__c = thisUser.Branch__c;
                    updateAccs.add(Acc);
            	}    
            	  
          }	
		
		if(!updateAccs.isEmpty()){
                update updateAccs;
            }
			  
				
	}

 

What would the syntax be for the following requirement in SOQL?

 

I have threee fields:

1. First Name

2. Last Name

3. Description (Long Text Area)

 

I need to get all names which have the word 'Developer' (or any keyword) in the 'Description' Long Text area. I have hit the wall trying to use the keywords 'contains' or 'includes' without success. Doesn anyone know how to build a SOQL using these both keywords?

 

Any help much appreciated.

Hello Folks, I am a complete newbie to Apex. I have a simple custom controller class for displaying a VF page when a user clicks a custom button. I can't figure out for the life of me how to write a test class for this. Please see the Controller Class and the Test class 'attempt' I made below. Could someone be gracious enough to point me to the right direction?

 

The context from VF to get to this button is : Create a new Case froma record type --> Create a new record for 'Contract Admin Entry' object (available onec the case is created) --> Custom button clicked within this page (custom controller called)

 

Here is the Custom Controller :

 

public class CustomSettingController {
	public string CAEID {Get;set;}
	public Contract_Admin_Entry__c oCAE {get;set;}
	public boolean shouldRender {Get;set;}
	
// Default Constructor
//	 public CustomSettingController(){  }

// Custom Constructor
  public CustomSettingController(ApexPages.StandardController ctl){
	shouldRender = false;
  	CAEID=ApexPages.currentPage().getParameters().get('ID');
  	if(CAEID!=''){
  		 		
  		list<Contract_Admin_Entry__c> lCAE = [SELECT Case_Type__c, Case__c FROM Contract_Admin_Entry__c where ID=:CAEID];
  		if(lCAE.size()>0){
  			oCAE = lCAE.get(0);
			shouldRender = true;
  		} 
  	}
  }
  
// Main Method	
  public list<ContractAdmin__c> getCaseTypeProcesses(){
  		 list<ContractAdmin__c> lCaseTypeProcess = [Select c.Case_Type__c, c.Process__c From ContractAdmin__c c where Case_Type__c=:oCAE.Case_Type__C order by Case_Type__c limit 1000];
  		 if(lCaseTypeProcess==null || lCaseTypeProcess.size()==0){
  		 	ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'No Checklist available for this Case Type.'));
  		 }
    		return lCaseTypeProcess;

  }
}

 Here is my attempt to write the Test Class :

 

@isTest
private class CustomSettingController_Test {

    static testMethod void myUnitTest() {
        
        // TO DO: implement unit test
        //Build 8 objects of ContractAdmin__c
        
        list<ContractAdmin__c> lCA = new list<ContractAdmin__c>();
        
        ContractAdmin__c oCA = new ContractAdmin__c();
        ocA.Case_Type__c = 'Canada ADP';
        oCA.Process__c = 'Tier - 1';
        lCA.add(ocA);
        
     	ContractAdmin__c oCA1 = new ContractAdmin__c();
        ocA1.Case_Type__c = 'Canada ADP';
        oCA1.Process__c = 'Are T and C’s attached or T and C confirmation page included';
        lCA.add(ocA1);   
        insert lCA;
        

        //build Case
        
        list<Case> lCase = new list<Case>();
        
        Case oCase = new Case();
        oCase.Tier__c = 'Tier 1';
        oCase.Origin = 'Usage Adjustment';
        oCase.Status = 'Received';
        lCase.add(oCase);

      
        Case oCase1 = new Case();
        oCase1.Tier__c = 'Tier 2';
        oCase1.Origin = 'Contract Admin';
        oCase1.Status = 'In-Progress';
        lCase.add(oCase1);
        
        insert lCase;
        
        //build Contract_Admin_Entry__c
        
        list<Contract_Admin_Entry__c> lCAE = new list<Contract_Admin_Entry__c>();
        
        Contract_Admin_Entry__c oCAE = new Contract_Admin_Entry__c();
     	oCAE.Case_Type__c = 'Canada ADP';
  //   	oCAE.Id = 'CA-00000009';
     	lCAE.add(oCAE);
     	
     	Contract_Admin_Entry__c oCAE1 = new Contract_Admin_Entry__c();
     	oCAE1.Case_Type__c = 'Canada Transfer';
  //   	oCAE1.Id = 'CA-00000010';
     	lCAE.add(oCAE1);
     	
     	insert lCAE;
     	
     	// build Account
     	
     	list<Account> lACC = new list<Account>();
        
        Account oACC = new Account();
     	oACC.Name = 'Ryans Training Center';
     	lACC.add(oACC);
     	
     	Account oACC1 = new Account();
     	oACC1.Name = 'RPM Inc';
     	lACC.add(oACC1);
     	
     	Account oACC2 = new Account();
     	oACC2.Name = 'LDE2';
     	lACC.add(oACC2);
     	
     	insert lACC;
     	
     	
     	// build Contact
     	
     	list<Contact> lCON = new list<Contact>();
        
        Contact oCON = new Contact();
    	oCON.FirstName = 'Anne';
    	oCON.LastName = 'McGraw';
//	   	oCON.Name;
     	lCON.add(oCON);
     	
     	Contact oCON1 = new Contact();
     	oCON1.FirstName = 'Kelly';
     	oCON1.LastName = 'McGill';
//     	oCON1.Name;
     	lCON.add(oCON1);
     	
     	Contact oCON2 = new Contact();
     	oCON2.FirstName = 'Jeff';
     	oCON2.LastName = 'Althaus';
 //    	oCON2.Name;
     	lCON.add(oCON2);
     	
     	insert lCON;
     	
     //Test coverage for the CaseTypeProcess visualforce page
		PageReference pageRef = Page.CaseTypeProcess;
		Test.setCurrentPageReference(pageRef);
		
	// create an instance of the controller
     	Test.startTest();
     	
     	Contract_Admin_Entry__c tCAE = new Contract_Admin_Entry__c();
   		ApexPages.Standardcontroller sc = new ApexPages.Standardcontroller(tCAE);
    	CustomSettingController csc = new CustomSettingController(sc);   	
  //   	List nextPage = csc.getCaseTypeProcesses();
     	
     	
     	Test.stopTest();
    }
     
}