- Vincent van Drunen Littel
- NEWBIE
- 125 Points
- Member since 2015
-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
13Questions
-
42Replies
Do not create Case (web-to-case) if Contact does not exist
Hi everyone!
I have a question about web-to-case.
What I'm trying to do is using web-to-case for a small personal project, where I receive information from my web-to-case HTML.
Now my problem is that Salesforce automatically creates a case even though the contact doesn't exist. I want to prevent this so no unneccesarry cases are created.
Has anyone has any ideas how i prevent Salesforce from creating cases when Contact records do not exist?
Would be a great help, and thank you in advance for the help!!
Vincent
- Vincent van Drunen Littel
- September 22, 2015
- Like
- 0
Why is my "add Target" button not working?
Hi all,
I'm completely lost on why the "add Target" button within my VisualForce page is not working.
Error Code after clicking "add Target"
Invalid id: [object Object]
Error is in expression '{!addTargets}' in component <apex:commandButton> in page custompaginationvf: External entry point
If anyone would have any idea please help me!
ApexClass
public with sharing class CustomPaginationController { public Contact acc {get;set;} public ApexPages.StandardSetController con{get; set;} public string selectedlstAccounts {get; set;} Map<Id, Contact> contactMap {get; set;} String parentAccountId; String parentContactId; public CustomPaginationController () { acc = new Contact(); lstAccount = new List<Contact>(); selectedlstAccounts=''; contactMap = new Map<Id, Contact>([select Id, Name from Contact]); parentContactId = ApexPages.currentPage().getParameters().get('conId'); } 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 ) { system.debug('yyyyyyy22222222222222'); system.debug('parentContactId: ' + parentContactId ); system.debug('contactMap.get(s).Name: ' + contactMap.get(s).Name ); Target__c newtarget = new Target__c (Target__c = Id.valueOf(parentContactId), Name = contactMap.get(s).Name); system.debug('yyyyyyy333333333333333333'); 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(); } }
VFpage
<apex:page controller="CustomPaginationController" sidebar="false"> <apex:form > <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" /> <apex:pageBlock > <apex:pageMessages ></apex:pageMessages> <apex:pageBlockButtons > <apex:commandButton action="{!Search}" value="Search" /> </apex:pageBlockButtons> <apex:pageblockSection > <apex:inputText value="{!acc.Name}" label="Name"/> </apex:pageblockSection> </apex:pageBlock> <apex:pageBlock id="resultId" rendered="{!if(lstAccount != null && lstAccount.size > 0, true,false )}"> <apex:pageBlockButtons > <div style="text-align:right"> Total Records Found: {!Con.resultSize} <apex:image url="/img/search_prevarrow_disabled.gif" styleClass="prevArrow" rendered="{!NOT(Con.HasPrevious)}"/> <apex:image url="/img/search_prevarrow.gif" title="Previous Page" styleClass="prevArrow" rendered="{!Con.HasPrevious}"/> <apex:commandLink action="{!Previous}" title="Previous Page" value="Previous Page" rendered="{!Con.HasPrevious}"/> <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasPrevious)}">Previous Page</apex:outputPanel> <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasNext)}">Next Page</apex:outputPanel> <apex:commandLink title="Next Page" value="Next Page" rendered="{!Con.HasNext}" action="{!Next}"/> <apex:image url="/img/search_nextarrow.gif" title="Next Page" styleClass="nextArrow" rendered="{!Con.HasNext}"/> <apex:image url="/img/search_nextarrow_disabled.gif" rendered="{!NOT(Con.HasNext)}"/> <img src="/s.gif" title="Last Page" alt="Last Page" class="last"/> </div> <apex:commandButton value="Add Target" action="{!addTargets}"/> </apex:pageBlockButtons> <apex:inputHidden value="{!selectedlstAccounts}" id="lstAccounts"/> <apex:pageBlockSection columns="1"> <apex:pageBlockTable value="{!lstAccount}" var="contato" > <apex:column headerValue="Select" width="100px;"><apex:inputCheckbox onclick="Select1stAccounts(this, '{!contato.Id}');"/></apex:column> <apex:column value="{!contato.Name}"/> <apex:column value="{!contato.Account.Name}"/> <apex:column value="{!contato.Cargo__c}"/> </apex:PageblockTable> </apex:pageBlockSection> </apex:pageBlock> <script type="text/javascript"> $ = jQuery.noConflict(); function Select1stAccounts(chk, lstAccounts) { //alert( '1' ); //alert( lstAccounts[1] ); var lstAccounts = $('input[id$="lstAccounts"]'); var selectedlstAccounts = lstAccounts.val(); if (chk.checked == true) { //alert( '2A' ); if (selectedlstAccounts == '') { //alert( '2A1' ); selectedlstAccounts = lstAccounts; } else { //alert( '2A2' ); selectedlstAccounts = selectedlstAccounts + ',' + lstAccounts; } } else { //alert( '2B' ); var accountIndex = selectedlstAccounts.indexOf(lstAccounts); var accountToRemove = ''; if (selectedlstAccounts.length == lstAccounts.length) { accountToRemove = lstAccounts; } else { if (accountIndex == 0){ accountToRemove = lstAccounts+ ','; } else{ accountToRemove = ',' + lstAccounts; } } selectedlstAccounts = selectedlstAccounts.replace(accountToRemove, ''); } //alert( 'B' ); lstAccounts.val(selectedlstAccounts); //alert (lstAccounts.val()); } </script> </apex:form> </apex:page>
Apex trigger
trigger TargetsContacts on Contact (after insert, after update) { List<Contact> contacts = [select Id, Name, AccountId, Account.Name from Contact Where Id in :Trigger.new]; List<Target__c> targetList = new List<Target__c>(); for(Contact con : contacts){ Target__c target = new Target__c(); target.Target_del__c = con.AccountId; target.Name = con.Name; target.Target__c = con.Id; targetList.add(target); } if(!targetList.IsEmpty()){ try{ insert targetList; } catch(DMLException e){ system.debug('Following Exceptions occurred'+e.getmessage()); } } }Button on related list
window.mypopup = window.open('/apex/CustomPaginationVF?contId={!Target__c.Target__c}','mypopup','top=150,left=200,location=1,status=1,scrollbars=1, width=1000,height=600'); window.onfocus = function() { if (window.mypopup.closed) { window.location.reload(); } };
- Vincent van Drunen Littel
- June 26, 2015
- Like
- 0
Need some help with Error Attempt to de-reference a null object ?
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(); } }
- Vincent van Drunen Littel
- June 26, 2015
- Like
- 0
Add function not working in code *urgent*
the button "add target"
Error: Compile Error: Variable does not exist: selectedlstAccounts at line 27 column 40
Can someone give me a hand fixing this one??
Controler
public with sharing class CustomPaginationController { public Contact acc {get;set;} public ApexPages.StandardSetController con{get; set;} 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 addTarget() { //system.debug('sssssssss'); List<Contact> lstAccountsIds = selectedlstAccounts.split(','); List<Target__c> lstAccount = new List<Target__c>(); //system.debug('rrrrrrr'); for (string s : lstAccountsIds ) { //system.debug('lstAccountsIds: ' + lstAccountsIds); system.debug('s: ' + s); system.debug('Name: ' + accountMap.get(s).Name); Target__c newtarget = new Target__c (Target__c = lstAccount, Name = lstAccountsMap.get(s).Name); Target.add(newtarget); } //system.debug('yyyyyyy'); if (Target.size() > 0) { //system.debug('ppppppp'); insert lstAccount; } 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(); } }VFpage
<apex:page controller="CustomPaginationController" sidebar="false"> //I added this <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" /> <script type="text/javascript"> $ = jQuery.noConflict(); function Select1stAccounts(chk, contactId, Account.Name) { alert( '1' ); var lstAccounts = $('input[id$="lstAccounts"]'); var selectedlstAccounts = lstAccounts.val(); if (chk.checked == true) { alert( '2A' ); if (selectedlstAccounts == '') { alert( '2A1' ); selectedlstAccounts = lstAccounts; } else { alert( '2A2' ); selectedlstAccounts = selectedlstAccounts + ',' + lstAccounts; } } else { alert( '2B' ); var accountIndex = selectedlstAccounts.indexOf(contactId); var accountToRemove = ''; if (selectedlstAccounts.length == lstAccounts.length) { accountToRemove = lstAccounts; } else { if (accountIndex == 0){ accountToRemove = lstAccounts+ ','; } else{ accountToRemove = ',' + lstAccounts; } } selectedlstAccounts = selectedlstAccounts.replace(accountToRemove, ''); } alert( 'B' ); lstAccounts.val(selectedlstAccounts); alert (lstAccounts.val()); } </script> //Orignal Code <apex:form > <apex:inputHidden value="{!selectedlstAccounts}" id="lstAccountsIds"/> <apex:pageBlock > <apex:pageMessages ></apex:pageMessages> <apex:pageBlockButtons > <apex:commandButton action="{!Search}" value="Search" /> </apex:pageBlockButtons> <apex:pageblockSection > <apex:inputText value="{!acc.Name}" label="Name"/> </apex:pageblockSection> </apex:pageBlock> <apex:pageBlock id="resultId" rendered="{!if(lstAccount != null && lstAccount.size > 0, true,false )}"> <apex:pageBlockButtons > <div style="text-align:right"> Total Records Found: {!Con.resultSize} <apex:image url="/img/search_prevarrow_disabled.gif" styleClass="prevArrow" rendered="{!NOT(Con.HasPrevious)}"/> <apex:image url="/img/search_prevarrow.gif" title="Previous Page" styleClass="prevArrow" rendered="{!Con.HasPrevious}"/> <apex:commandLink action="{!Previous}" title="Previous Page" value="Previous Page" rendered="{!Con.HasPrevious}"/> <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasPrevious)}">Previous Page</apex:outputPanel> <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasNext)}">Next Page</apex:outputPanel> <apex:commandLink title="Next Page" value="Next Page" rendered="{!Con.HasNext}" action="{!Next}"/> <apex:image url="/img/search_nextarrow.gif" title="Next Page" styleClass="nextArrow" rendered="{!Con.HasNext}"/> <apex:image url="/img/search_nextarrow_disabled.gif" rendered="{!NOT(Con.HasNext)}"/> <img src="/s.gif" title="Last Page" alt="Last Page" class="last"/> </div> </apex:pageBlockButtons> <apex:pageBlockSection columns="1"> <apex:pageBlockTable value="{!lstAccount}" var="acc" > <apex:column headerValue="Select" width="100px;"> <apex:inputCheckbox onclick="javascript:SelectAccounts(this, '{!acc.Id}');"/> </apex:column> <apex:column value="{!acc.Name}"/> <apex:column value="{!acc.Account.Name}"/> <apex:column value="{!acc.Cargo__c}"/> </apex:PageblockTable> <apex:commandButton value="Add Target" action="{!addTargets}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
- Vincent van Drunen Littel
- June 25, 2015
- Like
- 0
Create a simple searchbox in VisualForcePage
Could anyone help with this?
- Vincent van Drunen Littel
- June 25, 2015
- Like
- 0
Sort a VisualForce Page Alphabetically
Hi,
I have a visualforce page that provides me a list with accounts and their contacts. But it is a mess and all over the place, I need to get it to be sorted alphabetically.
And if possible a search box that would search within this page
Please let me know !
- Vincent van Drunen Littel
- June 24, 2015
- Like
- 0
Problems with a visualforce page
what I need is to have a page that displays all contacts and their account next to each other.
with checkbox next to them to select them and add them as target (custom object) which has a trigger when contact is created a target is created with basic info.
the controller is
public class ContactsController { public String selectedContactsIds { get; set; } public PageReference addContact() { return null; } public List contacts {get; set;} Map contactMap {get; set;} public string selectedContactIds {get; set;} string parentContactId; public ContactsController() // CHANGE THIS (SelectConcorrenteController TO ConcorrenteController) { parentContactId = ApexPages.currentPage().getParameters().get('accId'); contactMap = new Map([select Id, Name from Contact]); contacts = contactMap.Values(); } public PageReference addTargets() { List contactIds = selectedContactIds.split(','); List Targets = new List(); for (string s : contactIds) { Target__c Target = new Target__c(Target__c = parentContactId, Name = contactMap.get(s).Name); Targets.add(target); } if (Targets.size() > 0) { insert Targets; } string strPageRef = '"javascript:window.close();"'; return new PageReference(strPageRef); } }Visual force is
When i added it gives me the error
SObject row was retrieved via SOQL without querying the requested field: Contact.Account
When I added to Account.Name
contactMap = new Map([select Id, Name, Account.Name from Contact])
I received this error
Expression value does not resolve to a field
Error is in expression '{!con.Account}' in component in page contactsvf
If anyone would know how to fix this??
- Vincent van Drunen Littel
- June 24, 2015
- Like
- 0
How to change Salesforce logo in Chatter Invitations?
see picture below;
is this possible, if so how?
thank you
- Vincent van Drunen Littel
- June 23, 2015
- Like
- 0
Trigger that uses fields of different objects to create a new record on custom object
Hi,
I was hoping someone would be able to help me on this one..
What I´m trying to do here is to create a new record on object targets using basic information from account and contact.
I need the trigger to create upon creation of a new contact to create a new record on object "target". But this contact is linked to an account and I'm unable to retrieve this information (contact name and account name) I've been checking out SOQL query
select id, Name, email, Cargo__c,
(select Name from Accounts)
Which on workbench retrieved the exact info i needed.
Now trying to implement this in my trigger is the problem, anyone has any idea??
trigger TestTarget on Contact(after insert, after update){
List targets = new List();
for (Contact t : trigger.new){
Target__c newtar = new Target__c();
select id, Name, email, Cargo__c,
(select Name from Accounts)
from contact;
newtar.Target__c = acc.Name;
newtar.Name = con.Name;
insert tarlist;
}
}
- Vincent van Drunen Littel
- June 23, 2015
- Like
- 0
Can someone please help me on this trigger
Hi,
I keep getting this error,
Error: Compile Error: Expression cannot be assigned at line -1 column -1
What im trying is when an Account is created it automatically creates a Concorrent with basic fields such as Name, Segmento, Tipo de Empresa, Telefone
API's for object Concorrent are -
Concorrent__c
Segmento__c
Telefone__c
Tipo_de__c
And Name is a default field
API's on Account
Segmento__c
Tipo_de_empresa__c
Phone and Account name are default.
I'm probably doing a bunch of things wrong... Please o Please help me!!
trigger Concorrent on Account (before insert) {
List<Concorrent__c> conList = new List<Concorrent__c>();
for(Account acc : Trigger.New){
if(acc.Type == 'Individual'){
Concorrent__c con = new Concorrent__c();
Concorrent__c.Name = acc.Name;
Concorrent__c.Segmento__c = acc.Segmento__c;
Concorrent__c.Telefone__c = acc.Phone;
Concorrent__c.Tipo_de__c = acc.Tipo_de_empresa__c;
conList.add(con);
}
}
if(!conList.IsEmpty()){
try{
insert conList;
} catch(Exception e){
system.debug('Following Exceptions occured'+e.getmessage());
}
}
}
- Vincent van Drunen Littel
- June 12, 2015
- Like
- 0
Tweaking a script!
Could anybody "tweak"/ adjust this script accordingly!? ]
("Test Competitors are competition of the accounts, not from the organization, they can be clients(accounts) while being competition of other clients(accounts))
What I believe is that the "add competition" button should trigger a creation of record in object "Test Competitors" unless this record already exist within the object, but also it needs to be added on the related list within accounts (if that makes sense)
If more information is required please let me know!! Thank you!
public class AccountSelectClassController{
//Our collection of the class/wrapper objects wrapAccount
public List<wrapAccount> wrapAccountList {get; set;}
public List<Account> selectedAccounts{get;set;}
public AccountSelectClassController(){
if(wrapAccountList == null) {
wrapAccountList = new List<wrapAccount>();
for(Account a: [select Id, Name,BillingState, Website, Phone from Account limit 50]) {
// As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
wrapAccountList.add(new wrapAccount(a));
}
}
}
public void processSelected() {
selectedAccounts = new List<Account>();
for(wrapAccount wrapAccountObj : wrapAccountList) {
if(wrapAccountObj.selected == true) {
selectedAccounts.add(wrapAccountObj.acc);
}
}
}
<apex:page controller="AccountSelectClassController" sidebar="false">
<script type="text/javascript">
function selectAllCheckboxes(obj,receivedInputID){
var inputCheckBox = document.getElementsByTagName("input");
for(var i=0; i<inputCheckBox.length; i++){
if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
inputCheckBox[i].checked = obj.checked;
}
}
}
</script>
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Add to Competition" action="{!processSelected}" rerender="table2"/>
</apex:pageBlockButtons>
<apex:pageblockSection title="All Accounts" collapsible="false" columns="2">
<apex:pageBlockTable value="{!wrapAccountList}" var="accWrap" id="table" title="All Accounts">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
</apex:facet>
<apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
</apex:column>
<apex:column value="{!accWrap.acc.Name}" />
<apex:column value="{!accWrap.acc.BillingState}" />
<apex:column value="{!accWrap.acc.Phone}" />
</apex:pageBlockTable>
<apex:pageBlockTable value="{!selectedAccounts}" var="c" id="table2" title="Selected Accounts">
<apex:column value="{!c.Name}" headerValue="Account Name"/>
<apex:column value="{!c.BillingState}" headerValue="Billing State"/>
<apex:column value="{!c.Phone}" headerValue="Phone"/>
</apex:pageBlockTable>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Also I need this VF page to be popping up when clicking "new test competition" on the related list as picture below
If need anymore info please let me know.. I really appreciate the help!!
Thanks Vincent
- Vincent van Drunen Littel
- June 12, 2015
- Like
- 0
sdf
Could anybody "tweak"/ adjust this script accordingly!?
Also I need this VF page to be popping up when clicking "new test competition" on the related list as picture below
If need anymore info please let me know.. I really appreciate the help!!
Thanks Vincent
- Vincent van Drunen Littel
- June 10, 2015
- Like
- 0
Creating a add button that calls a VF page with a related list where I could add account names to a related list on Accounts
Long story short, in my org. when adding new accounts I need to add competition of the account. These competitors can already be existing accounts within my org.
To facilitate and speed up process I need to create a button that summons a Pop-up window with a list of all existing accounts where I would be able to check all accounts appropriate, then be able by using a "add" button that will pull all the checked info to my newly created account under competition.
If you need more info please let me know...
I have tried many different ways and have not been able to get at the right place.
If anyone would be able to help me on this one I would be very very very happy as this is a major problem.
- Vincent van Drunen Littel
- June 10, 2015
- Like
- 0
Why is my "add Target" button not working?
Hi all,
I'm completely lost on why the "add Target" button within my VisualForce page is not working.
Error Code after clicking "add Target"
Invalid id: [object Object]
Error is in expression '{!addTargets}' in component <apex:commandButton> in page custompaginationvf: External entry point
If anyone would have any idea please help me!
ApexClass
public with sharing class CustomPaginationController { public Contact acc {get;set;} public ApexPages.StandardSetController con{get; set;} public string selectedlstAccounts {get; set;} Map<Id, Contact> contactMap {get; set;} String parentAccountId; String parentContactId; public CustomPaginationController () { acc = new Contact(); lstAccount = new List<Contact>(); selectedlstAccounts=''; contactMap = new Map<Id, Contact>([select Id, Name from Contact]); parentContactId = ApexPages.currentPage().getParameters().get('conId'); } 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 ) { system.debug('yyyyyyy22222222222222'); system.debug('parentContactId: ' + parentContactId ); system.debug('contactMap.get(s).Name: ' + contactMap.get(s).Name ); Target__c newtarget = new Target__c (Target__c = Id.valueOf(parentContactId), Name = contactMap.get(s).Name); system.debug('yyyyyyy333333333333333333'); 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(); } }
VFpage
<apex:page controller="CustomPaginationController" sidebar="false"> <apex:form > <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" /> <apex:pageBlock > <apex:pageMessages ></apex:pageMessages> <apex:pageBlockButtons > <apex:commandButton action="{!Search}" value="Search" /> </apex:pageBlockButtons> <apex:pageblockSection > <apex:inputText value="{!acc.Name}" label="Name"/> </apex:pageblockSection> </apex:pageBlock> <apex:pageBlock id="resultId" rendered="{!if(lstAccount != null && lstAccount.size > 0, true,false )}"> <apex:pageBlockButtons > <div style="text-align:right"> Total Records Found: {!Con.resultSize} <apex:image url="/img/search_prevarrow_disabled.gif" styleClass="prevArrow" rendered="{!NOT(Con.HasPrevious)}"/> <apex:image url="/img/search_prevarrow.gif" title="Previous Page" styleClass="prevArrow" rendered="{!Con.HasPrevious}"/> <apex:commandLink action="{!Previous}" title="Previous Page" value="Previous Page" rendered="{!Con.HasPrevious}"/> <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasPrevious)}">Previous Page</apex:outputPanel> <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasNext)}">Next Page</apex:outputPanel> <apex:commandLink title="Next Page" value="Next Page" rendered="{!Con.HasNext}" action="{!Next}"/> <apex:image url="/img/search_nextarrow.gif" title="Next Page" styleClass="nextArrow" rendered="{!Con.HasNext}"/> <apex:image url="/img/search_nextarrow_disabled.gif" rendered="{!NOT(Con.HasNext)}"/> <img src="/s.gif" title="Last Page" alt="Last Page" class="last"/> </div> <apex:commandButton value="Add Target" action="{!addTargets}"/> </apex:pageBlockButtons> <apex:inputHidden value="{!selectedlstAccounts}" id="lstAccounts"/> <apex:pageBlockSection columns="1"> <apex:pageBlockTable value="{!lstAccount}" var="contato" > <apex:column headerValue="Select" width="100px;"><apex:inputCheckbox onclick="Select1stAccounts(this, '{!contato.Id}');"/></apex:column> <apex:column value="{!contato.Name}"/> <apex:column value="{!contato.Account.Name}"/> <apex:column value="{!contato.Cargo__c}"/> </apex:PageblockTable> </apex:pageBlockSection> </apex:pageBlock> <script type="text/javascript"> $ = jQuery.noConflict(); function Select1stAccounts(chk, lstAccounts) { //alert( '1' ); //alert( lstAccounts[1] ); var lstAccounts = $('input[id$="lstAccounts"]'); var selectedlstAccounts = lstAccounts.val(); if (chk.checked == true) { //alert( '2A' ); if (selectedlstAccounts == '') { //alert( '2A1' ); selectedlstAccounts = lstAccounts; } else { //alert( '2A2' ); selectedlstAccounts = selectedlstAccounts + ',' + lstAccounts; } } else { //alert( '2B' ); var accountIndex = selectedlstAccounts.indexOf(lstAccounts); var accountToRemove = ''; if (selectedlstAccounts.length == lstAccounts.length) { accountToRemove = lstAccounts; } else { if (accountIndex == 0){ accountToRemove = lstAccounts+ ','; } else{ accountToRemove = ',' + lstAccounts; } } selectedlstAccounts = selectedlstAccounts.replace(accountToRemove, ''); } //alert( 'B' ); lstAccounts.val(selectedlstAccounts); //alert (lstAccounts.val()); } </script> </apex:form> </apex:page>
Apex trigger
trigger TargetsContacts on Contact (after insert, after update) { List<Contact> contacts = [select Id, Name, AccountId, Account.Name from Contact Where Id in :Trigger.new]; List<Target__c> targetList = new List<Target__c>(); for(Contact con : contacts){ Target__c target = new Target__c(); target.Target_del__c = con.AccountId; target.Name = con.Name; target.Target__c = con.Id; targetList.add(target); } if(!targetList.IsEmpty()){ try{ insert targetList; } catch(DMLException e){ system.debug('Following Exceptions occurred'+e.getmessage()); } } }Button on related list
window.mypopup = window.open('/apex/CustomPaginationVF?contId={!Target__c.Target__c}','mypopup','top=150,left=200,location=1,status=1,scrollbars=1, width=1000,height=600'); window.onfocus = function() { if (window.mypopup.closed) { window.location.reload(); } };
- Vincent van Drunen Littel
- June 26, 2015
- Like
- 0
Need some help with Error Attempt to de-reference a null object ?
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(); } }
- Vincent van Drunen Littel
- June 26, 2015
- Like
- 0
Add function not working in code *urgent*
the button "add target"
Error: Compile Error: Variable does not exist: selectedlstAccounts at line 27 column 40
Can someone give me a hand fixing this one??
Controler
public with sharing class CustomPaginationController { public Contact acc {get;set;} public ApexPages.StandardSetController con{get; set;} 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 addTarget() { //system.debug('sssssssss'); List<Contact> lstAccountsIds = selectedlstAccounts.split(','); List<Target__c> lstAccount = new List<Target__c>(); //system.debug('rrrrrrr'); for (string s : lstAccountsIds ) { //system.debug('lstAccountsIds: ' + lstAccountsIds); system.debug('s: ' + s); system.debug('Name: ' + accountMap.get(s).Name); Target__c newtarget = new Target__c (Target__c = lstAccount, Name = lstAccountsMap.get(s).Name); Target.add(newtarget); } //system.debug('yyyyyyy'); if (Target.size() > 0) { //system.debug('ppppppp'); insert lstAccount; } 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(); } }VFpage
<apex:page controller="CustomPaginationController" sidebar="false"> //I added this <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" /> <script type="text/javascript"> $ = jQuery.noConflict(); function Select1stAccounts(chk, contactId, Account.Name) { alert( '1' ); var lstAccounts = $('input[id$="lstAccounts"]'); var selectedlstAccounts = lstAccounts.val(); if (chk.checked == true) { alert( '2A' ); if (selectedlstAccounts == '') { alert( '2A1' ); selectedlstAccounts = lstAccounts; } else { alert( '2A2' ); selectedlstAccounts = selectedlstAccounts + ',' + lstAccounts; } } else { alert( '2B' ); var accountIndex = selectedlstAccounts.indexOf(contactId); var accountToRemove = ''; if (selectedlstAccounts.length == lstAccounts.length) { accountToRemove = lstAccounts; } else { if (accountIndex == 0){ accountToRemove = lstAccounts+ ','; } else{ accountToRemove = ',' + lstAccounts; } } selectedlstAccounts = selectedlstAccounts.replace(accountToRemove, ''); } alert( 'B' ); lstAccounts.val(selectedlstAccounts); alert (lstAccounts.val()); } </script> //Orignal Code <apex:form > <apex:inputHidden value="{!selectedlstAccounts}" id="lstAccountsIds"/> <apex:pageBlock > <apex:pageMessages ></apex:pageMessages> <apex:pageBlockButtons > <apex:commandButton action="{!Search}" value="Search" /> </apex:pageBlockButtons> <apex:pageblockSection > <apex:inputText value="{!acc.Name}" label="Name"/> </apex:pageblockSection> </apex:pageBlock> <apex:pageBlock id="resultId" rendered="{!if(lstAccount != null && lstAccount.size > 0, true,false )}"> <apex:pageBlockButtons > <div style="text-align:right"> Total Records Found: {!Con.resultSize} <apex:image url="/img/search_prevarrow_disabled.gif" styleClass="prevArrow" rendered="{!NOT(Con.HasPrevious)}"/> <apex:image url="/img/search_prevarrow.gif" title="Previous Page" styleClass="prevArrow" rendered="{!Con.HasPrevious}"/> <apex:commandLink action="{!Previous}" title="Previous Page" value="Previous Page" rendered="{!Con.HasPrevious}"/> <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasPrevious)}">Previous Page</apex:outputPanel> <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasNext)}">Next Page</apex:outputPanel> <apex:commandLink title="Next Page" value="Next Page" rendered="{!Con.HasNext}" action="{!Next}"/> <apex:image url="/img/search_nextarrow.gif" title="Next Page" styleClass="nextArrow" rendered="{!Con.HasNext}"/> <apex:image url="/img/search_nextarrow_disabled.gif" rendered="{!NOT(Con.HasNext)}"/> <img src="/s.gif" title="Last Page" alt="Last Page" class="last"/> </div> </apex:pageBlockButtons> <apex:pageBlockSection columns="1"> <apex:pageBlockTable value="{!lstAccount}" var="acc" > <apex:column headerValue="Select" width="100px;"> <apex:inputCheckbox onclick="javascript:SelectAccounts(this, '{!acc.Id}');"/> </apex:column> <apex:column value="{!acc.Name}"/> <apex:column value="{!acc.Account.Name}"/> <apex:column value="{!acc.Cargo__c}"/> </apex:PageblockTable> <apex:commandButton value="Add Target" action="{!addTargets}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
- Vincent van Drunen Littel
- June 25, 2015
- Like
- 0
Create a simple searchbox in VisualForcePage
Could anyone help with this?
- Vincent van Drunen Littel
- June 25, 2015
- Like
- 0
Sort a VisualForce Page Alphabetically
Hi,
I have a visualforce page that provides me a list with accounts and their contacts. But it is a mess and all over the place, I need to get it to be sorted alphabetically.
And if possible a search box that would search within this page
Please let me know !
- Vincent van Drunen Littel
- June 24, 2015
- Like
- 0
Problems with a visualforce page
what I need is to have a page that displays all contacts and their account next to each other.
with checkbox next to them to select them and add them as target (custom object) which has a trigger when contact is created a target is created with basic info.
the controller is
public class ContactsController { public String selectedContactsIds { get; set; } public PageReference addContact() { return null; } public List contacts {get; set;} Map contactMap {get; set;} public string selectedContactIds {get; set;} string parentContactId; public ContactsController() // CHANGE THIS (SelectConcorrenteController TO ConcorrenteController) { parentContactId = ApexPages.currentPage().getParameters().get('accId'); contactMap = new Map([select Id, Name from Contact]); contacts = contactMap.Values(); } public PageReference addTargets() { List contactIds = selectedContactIds.split(','); List Targets = new List(); for (string s : contactIds) { Target__c Target = new Target__c(Target__c = parentContactId, Name = contactMap.get(s).Name); Targets.add(target); } if (Targets.size() > 0) { insert Targets; } string strPageRef = '"javascript:window.close();"'; return new PageReference(strPageRef); } }Visual force is
When i added it gives me the error
SObject row was retrieved via SOQL without querying the requested field: Contact.Account
When I added to Account.Name
contactMap = new Map([select Id, Name, Account.Name from Contact])
I received this error
Expression value does not resolve to a field
Error is in expression '{!con.Account}' in component in page contactsvf
If anyone would know how to fix this??
- Vincent van Drunen Littel
- June 24, 2015
- Like
- 0
Trigger that uses fields of different objects to create a new record on custom object
Hi,
I was hoping someone would be able to help me on this one..
What I´m trying to do here is to create a new record on object targets using basic information from account and contact.
I need the trigger to create upon creation of a new contact to create a new record on object "target". But this contact is linked to an account and I'm unable to retrieve this information (contact name and account name) I've been checking out SOQL query
select id, Name, email, Cargo__c,
(select Name from Accounts)
Which on workbench retrieved the exact info i needed.
Now trying to implement this in my trigger is the problem, anyone has any idea??
trigger TestTarget on Contact(after insert, after update){
List targets = new List();
for (Contact t : trigger.new){
Target__c newtar = new Target__c();
select id, Name, email, Cargo__c,
(select Name from Accounts)
from contact;
newtar.Target__c = acc.Name;
newtar.Name = con.Name;
insert tarlist;
}
}
- Vincent van Drunen Littel
- June 23, 2015
- Like
- 0