You need to sign in to do that
Don't have an account?
Vincent van Drunen Littel
Need some help with Error Attempt to de-reference a null object ?
Hi, Im trying with this controller that when a record has been selected and when you add target it should actually add the record to the target object.
For some reason i get this error... could anyone give me a hand on thsi one?
For some reason i get this error... could anyone give me a hand on thsi one?
public with sharing class CustomPaginationController { public Contact acc {get;set;} public ApexPages.StandardSetController con{get; set;} public string selectedlstAccounts {get; set;} Map<Id, Account> contactMap {get; set;} string parentAccountId; public CustomPaginationController () { acc = new Contact(); lstAccount = new List<Contact>(); } public List<Contact> lstAccount { get { if(con != null) return (List<Contact>)con.getRecords(); else return null ; } set; } //added by me to test public PageReference addTargets() { system.debug('jjjjj'); List<String> lstAccountsIds = selectedlstAccounts.split(','); List<Target__c> Target = new List<Target__c>(); system.debug('oooo'); for (string s : lstAccountsIds ) { Target__c newtarget = new Target__c (Target__c = parentAccountId, Name = contactMap.get(s).Name); Target.add(newtarget); } system.debug('yyyyyyy'); if (Target.size() > 0) { system.debug('ppppppp'); insert Target; } string strPageRef = '"javascript:window.close();"'; return new PageReference(strPageRef); } public PageReference Search() { String query= ''; String strFilter = ''; if(acc.Name != null && (acc.Name ).trim() !='') { strFilter = strFilter + ' where Name Like \''+acc.Name+'%\'' ; } if(acc.Account.Name != null && (acc.Account.Name).trim() !='' ) { strFilter = strFilter + ' where Name Like \''+acc.Account.Name+'%\'' ; } if(strFilter != '') { query = 'Select name ,id, Account.Name, Cargo__c from Contact '+strFilter+ ' limit 1000'; System.debug('Query ---->'+ query ); con = new ApexPages.StandardSetController(Database.getQueryLocator(query)); con.setPageSize(10); } else { } return null; } public Boolean hasNext { get { return con.getHasNext(); } set; } public Boolean hasPrevious { get { return con.getHasPrevious(); } set; } public Integer pageNumber { get { return con.getPageNumber(); } set; } public void previous() { con.previous(); } public void next() { con.next(); } }
NOTE:- you need to pass ContID in URL like below :-
https://ap1.salesforce.com/apex/YOUR_PAGE_NAME?ContID=0039000001Z5QEU
Please pass ID and base URL according to your org
Please mark this as solution if this will solved ur issue.
Thanks
Amit chaudhary
amit.salesforce21@gmail.com
All Answers
line 32: List<String> lstAccountsIds = selectedlstAccounts.split(',');
should be :
List<String> lstAccountsIds = new List<String>();
if(String.isNotBlank(selectedlstAccounts))
lstAccountsIds = selectedlstAccounts.split(',');
Hope its help!!
I do not get an error anymore, but it does not add the selected record to object Target!?
I did debug but doesnt show any errors to, :/
Would you have any idea why its not adding the selected records to Target?
Thanks
Please let us know if that will help you
Invalid id:
Error is in expression '{!addTargets}' in component <apex:commandButton> in page custompaginationvf: External entry point
Any suggestions?
Thanks!
var lstAccounts = $('input[id$="lstAccounts"]');
TO
var lstAccounts = $('input[id$="lstAccountsIds"]');
Still the same error
Invalid id:
Error is in expression '{!addTargets}' in component <apex:commandButton> in page custompaginationvf: External entry point
Correct, the error is after clicking the button.
I used the code from your blog to create this search box (thanks) altough i needed to make my customizations, therefore have checkbox and "add target" button, I used another code i already in place (working) to try to make the button to work.
I guess merging the 2 is creating some problem.
The thoughts and needs behind all this is to be able to search contacts, with account name then to be able to select them and add them to a custom object called Target.
to answer you question of parentAccountId, this comes from the code below.. but not sure what significance it has.
This is the "original code" that i used (very basic), but the add target button works
Hope this helps..
string parentContactId
To
public String parentContactId { get; set; }
Are you want to use Account or Contact Object ?
Please check code on below post. That will help you.
https://developer.salesforce.com/page/Wrapper_Class
Here is a screenshot of all fields..
you are pointing to create a wrapper class, right?
I believed it was not necesarry as i have pretty much the same controllers/vfpages for 3 other objects..
I have a trigger that creates a "target" upon creation of a contact --> Also i have a function code that creates a new "target" when added on a related list on for example contact, which is then shown in the related list on contact and account.
(i used target to make it easier to explain)
I just wanted to make the VFpage more accessible by using a searchbox (from your blog) So I wanted to combine my old code (funcioning) with your code of searchbox to have this.
i posted above my functioning code which has no searchbox
NOTE:- you need to pass ContID in URL like below :-
https://ap1.salesforce.com/apex/YOUR_PAGE_NAME?ContID=0039000001Z5QEU
Please pass ID and base URL according to your org
Please mark this as solution if this will solved ur issue.
Thanks
Amit chaudhary
amit.salesforce21@gmail.com