• Peter Yohanna
  • NEWBIE
  • 145 Points
  • Member since 2015
  • Accenture

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
Hi

i have created a VF page on which i will be search record and after thar i want to delete the record on the slected checkbox

error

[Error] Error: Invalid field selected for SObject BankBook__c
 
<apex:page controller="AccountMultipleSearchWithPagenationCLS1" action="{!searchAcc}" sidebar="false" showHeader="true">
 <apex:define name="body">
            
            <div style="width:900px;margin: 0px auto 10px auto;background-color:Gray;border: 1px solid black;">
               <apex:image id="theImage" value="{!$Resource.Emami}" width="100" height="100" style="background-color:Gray;"/> 
<script>

function checkAll(cb)

{

var inputElem = document.getElementsByTagName("input");

for(var i=0; i<inputElem.length; i++)

{

if(inputElem[i].id.indexOf("checkedone")!=-1)

inputElem[i].checked = cb.checked;

}

}

</script>

 <apex:form >
  <apex:pageBlock id="thePb" title="Dynamic BankBook Search:">
   <apex:pageblockSection id="thepbs">
    <apex:inputField value="{!acc.From_Date__c}" />
     <apex:inputField value="{!acc.To_Date__c}"/>
    <apex:inputField value="{!acc.Group_FUP__c}" required="false" id="accName"/>
     <apex:inputfield value="{!acc.Party_CodeFUP__c}"/>
   </apex:pageblockSection>
   <apex:pageblockButtons location="bottom">
      <apex:commandButton value="Search" action="{!searchAcc}" />
      <apex:commandButton value="Delete" action="{!searchAcc}" />
     </apex:pageblockButtons>  
  </apex:pageBlock>
  
   <apex:pageBlock title="BankBook Details" id="noRec" rendered="{! IF( accountList != null && accountList.size ==0 , true, false)}" >
  <apex:outputPanel >
    <h1>No Records Found </h1>
</apex:outputPanel>
  </apex:pageBlock>

  
  <apex:pageBlock title="BankBook Details" id="details" rendered="{! IF( accountList != null && accountList.size >0, true, false)}" >
    <apex:dataTable value="{!accountList}" var="a" columnswidth="50px,50px" cellpadding="4" border="1">
  <apex:column >

<apex:facet name="header">

<apex:inputCheckbox >

<apex:actionSupport event="onclick" action="{!GetSelected}" onsubmit="checkAll(this)"/>

</apex:inputCheckbox>

</apex:facet>

<apex:inputCheckbox value="{!a.selected}" id="checkedone">

<apex:actionSupport event="onclick" action="{!GetSelected}" rerender="Selected_PBS"/>

</apex:inputCheckbox>

</apex:column>
        
   
<apex:column headervalue="Date" value="{!a.Txn_Date__c}" />
<apex:column headervalue="Related Bank Account" value="{!a.Related_Bank_Acc__c}" />
<apex:column headervalue="Payment Type" value="{!a.Credit_Debit__c}" />
<apex:column headervalue="Master Code" value="{!a.Entries_Code__c}" />
<apex:column headervalue="Master Name" value="{!a.Debtor_Name_formula__c}" />
<apex:column headervalue="Amount" value="{!a.Amount__c}" />
<apex:column headervalue="Debit" value="{!a.Credit__c}" />
<apex:column headervalue="Credit" value="{!a.Debit__c}" />

<apex:column headervalue="Narration" value="{!a.Narration__c }" />
 
   </apex:dataTable>
   
    <apex:pageblockButtons >
 <apex:commandButton value="First Page" rerender="details" action="{!FirstPage}" disabled="{!prev}"/>
<apex:commandButton value="Previous" rerender="details" action="{!previous}" disabled="{!prev}"/>
<apex:commandButton value="Next" rerender="details" action="{!next}" disabled="{!nxt}"/>
<apex:commandButton value="Last Page" rerender="details" action="{!LastPage}" disabled="{!nxt}"/>
</apex:pageblockButtons>
   
  </apex:pageBlock>
<apex:messages />
 </apex:form>
  </div>
        </apex:define>
      
        <center><br/>
        <b><i style="font-size:10px;color:red;">Developed By GlobalNest IT Solution Pvt.Ltd. <a href="http://www.globalnest.com" target="_blank">[http://www.Globalnest.com]</a> (2015)</i></b>
    </center><br/>

</apex:page>

---------------------------------------------------------------------------------------------------
public with sharing class AccountMultipleSearchWithPagenationCLS1 {

    
public BankBook__c acc{get;set;}
public List<accountwrapper> accountList1 {get;set;}
public List<BankBook__c> accountList {get;set;}
List<string> conditions = new List<string>();
private integer totalRecs = 0;
private integer OffsetSize = 0;
private integer LimitSize= 10;
public List<BankBook__c> selectedAccounts = new List<BankBook__c>();

public List<accountwrapper> getAccounts()

{
return accountList1;

}

public AccountMultipleSearchWithPagenationCLS1()
{

accountList1 = new List<accountwrapper>();

for(BankBook__c a: [select Id, Txn_Date__c, Related_Bank_Acc__c, Credit_Debit__c,Entries_Code__c,Amount__c,Credit__c,Debit__c,
Debtor_Name_formula__c,Narration__c from BankBook__c])

accountList1.add(new accountwrapper(a));

//return accountList;

system.debug('==>AccountMultipleSearchWithPagenationCLS  is calling==>');
 acc = new BankBook__c();
 //accountList  = new List<Account>();
}

public PageReference getSelected()

{

selectedAccounts.clear();

for(accountwrapper accwrapper: accountList1)

if(accwrapper.selected == true)

selectedAccounts.add(accwrapper.acc);

return null;

}

public List<BankBook__c> GetSelectedAccounts()

{

if(selectedAccounts.size()>0)

return selectedAccounts;

else

return null;

}


public PageReference deleteAll()

{

try{

List<BankBook__c> selAccounts=GetSelectedAccounts();

if(selAccounts.size()>0){

for(BankBook__c ac:selAccounts){

 

delete ac;

System.debug('###########Data Deleted Successfully###########');
 

}

}
ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR, 'Deleted successfully'));

PageReference pageref=new PageReference('/apex/BulkDelete');

return pageref;

}

Catch(Exception e){

ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR, 'Data Base Error'));

return null;

}

 

 

}

public void searchAcc(){
totalRecs = 0;
OffsetSize = 0;
if(accountList !=null && accountList.size()>0){
 accountList=null;
}
searchAccounts ();
conditions.clear();
}


public Void searchAccounts(){

System.debug('Total Records is ==>'+totalRecs);
System.debug('OffsetSize is ==>'+OffsetSize);

if(accountList != null && !accountList.isEmpty()){
  accountList.clear();
}
 String strQuery ='SELECT Id,Txn_Date__c,From_Date__c,To_Date__c,Related_Bank_Acc__c,CreatedDate,Credit_Debit__c,Entries_Code__c,Debtor_Name_formula__c ,Debit__c,Credit__c,Amount__c,Narration__c From BankBook__c';
 if(acc.From_Date__c!=null){
  String fromDate = acc.From_Date__c+'';
  fromDate = fromDate.split(' ',0)[0]+'T00:00:00.000Z';
   conditions.add('CreatedDate >='+fromDate);
 }

if(acc.To_Date__c!=null){
 String toDate = acc.To_Date__c+'';
  toDate = toDate.split(' ',0)[0]+'T23:59:59.000Z';
   conditions.add('createdDate <='+toDate);
 }

 if(acc.Party_CodeFUP__c!=null && acc.Party_CodeFUP__c!=''){
   conditions.add('Party_CodeFUP__c Like \'%' +acc.Party_CodeFUP__c+'%\' ');
 }
  if(acc.Group_FUP__c!=null && acc.Group_FUP__c!=''){
   conditions.add('Group_FUP__c Like\'%' +acc.Group_FUP__c+'%\' ');
 }

  if (conditions.size() > 0) {
   strQuery += '  WHERE ' + conditions[0];
   for (Integer i = 1; i < conditions.size(); i++)
            strQuery += '  AND ' + conditions[i];
  }
 if(totalRecs !=null && totalRecs ==0){
    List<BankBook__c> accTemp = Database.query(strQuery);
    totalRecs = (accTemp !=null &&accTemp.size()>0)?accTemp.size():0;
 }

 system.debug('strQuery ==>'+strQuery );
 // add sort and limits at the end  
  strQuery += ' ORDER BY Name  ASC, CreatedDate DESC LIMIT :LimitSize OFFSET :OffsetSize';
  
  accountList  =Database.query(strQuery);
  
   

  //conditions.clear();
  //return accountList.size();
}

public void FirstPage()
{
OffsetSize = 0;
searchAccounts();
}
public void previous()
{
OffsetSize = (OffsetSize-LimitSize);
searchAccounts();
}
public void next()
{
OffsetSize = OffsetSize + LimitSize;
searchAccounts();
}
public void LastPage()
{
OffsetSize = totalrecs - math.mod(totalRecs,LimitSize);
searchAccounts();
}
public boolean getprev()
{

if(OffsetSize == 0){

return true;
}
else {

return false;
}
}
public boolean getnxt()
{
if((OffsetSize + LimitSize) > totalRecs){

return true;
}
else {

return false;
}
}

public class accountwrapper

{

public BankBook__c acc{get; set;}

public Boolean selected {get; set;}

public accountwrapper(BankBook__c a)

{

acc = a;

selected = false;

}

}


}

User-added image

 
When attempting to create my Apex trigger for this Trailhead development exercise, I receive an error. I don't understand how this is possible, because the records haven't been updated, and still aren't updating.
"Challenge not yet complete... here's what's wrong:
Setting 'Match_Billing_Address__c' to false updated the records anyway. The trigger should only act when Match_Billing_Address__c is true."


Here's my code:
trigger AccountAddressTrigger on Account (before insert, before update) {

    for(Account a : Trigger.new){
        If (a.Match_Billing_Address__c = true) {
            a.ShippingPostalCode = a.BillingPostalCode;
        }   
    }

}


 
Hi

i have created a VF page on which i will be search record and after thar i want to delete the record on the slected checkbox

error

[Error] Error: Invalid field selected for SObject BankBook__c
 
<apex:page controller="AccountMultipleSearchWithPagenationCLS1" action="{!searchAcc}" sidebar="false" showHeader="true">
 <apex:define name="body">
            
            <div style="width:900px;margin: 0px auto 10px auto;background-color:Gray;border: 1px solid black;">
               <apex:image id="theImage" value="{!$Resource.Emami}" width="100" height="100" style="background-color:Gray;"/> 
<script>

function checkAll(cb)

{

var inputElem = document.getElementsByTagName("input");

for(var i=0; i<inputElem.length; i++)

{

if(inputElem[i].id.indexOf("checkedone")!=-1)

inputElem[i].checked = cb.checked;

}

}

</script>

 <apex:form >
  <apex:pageBlock id="thePb" title="Dynamic BankBook Search:">
   <apex:pageblockSection id="thepbs">
    <apex:inputField value="{!acc.From_Date__c}" />
     <apex:inputField value="{!acc.To_Date__c}"/>
    <apex:inputField value="{!acc.Group_FUP__c}" required="false" id="accName"/>
     <apex:inputfield value="{!acc.Party_CodeFUP__c}"/>
   </apex:pageblockSection>
   <apex:pageblockButtons location="bottom">
      <apex:commandButton value="Search" action="{!searchAcc}" />
      <apex:commandButton value="Delete" action="{!searchAcc}" />
     </apex:pageblockButtons>  
  </apex:pageBlock>
  
   <apex:pageBlock title="BankBook Details" id="noRec" rendered="{! IF( accountList != null && accountList.size ==0 , true, false)}" >
  <apex:outputPanel >
    <h1>No Records Found </h1>
</apex:outputPanel>
  </apex:pageBlock>

  
  <apex:pageBlock title="BankBook Details" id="details" rendered="{! IF( accountList != null && accountList.size >0, true, false)}" >
    <apex:dataTable value="{!accountList}" var="a" columnswidth="50px,50px" cellpadding="4" border="1">
  <apex:column >

<apex:facet name="header">

<apex:inputCheckbox >

<apex:actionSupport event="onclick" action="{!GetSelected}" onsubmit="checkAll(this)"/>

</apex:inputCheckbox>

</apex:facet>

<apex:inputCheckbox value="{!a.selected}" id="checkedone">

<apex:actionSupport event="onclick" action="{!GetSelected}" rerender="Selected_PBS"/>

</apex:inputCheckbox>

</apex:column>
        
   
<apex:column headervalue="Date" value="{!a.Txn_Date__c}" />
<apex:column headervalue="Related Bank Account" value="{!a.Related_Bank_Acc__c}" />
<apex:column headervalue="Payment Type" value="{!a.Credit_Debit__c}" />
<apex:column headervalue="Master Code" value="{!a.Entries_Code__c}" />
<apex:column headervalue="Master Name" value="{!a.Debtor_Name_formula__c}" />
<apex:column headervalue="Amount" value="{!a.Amount__c}" />
<apex:column headervalue="Debit" value="{!a.Credit__c}" />
<apex:column headervalue="Credit" value="{!a.Debit__c}" />

<apex:column headervalue="Narration" value="{!a.Narration__c }" />
 
   </apex:dataTable>
   
    <apex:pageblockButtons >
 <apex:commandButton value="First Page" rerender="details" action="{!FirstPage}" disabled="{!prev}"/>
<apex:commandButton value="Previous" rerender="details" action="{!previous}" disabled="{!prev}"/>
<apex:commandButton value="Next" rerender="details" action="{!next}" disabled="{!nxt}"/>
<apex:commandButton value="Last Page" rerender="details" action="{!LastPage}" disabled="{!nxt}"/>
</apex:pageblockButtons>
   
  </apex:pageBlock>
<apex:messages />
 </apex:form>
  </div>
        </apex:define>
      
        <center><br/>
        <b><i style="font-size:10px;color:red;">Developed By GlobalNest IT Solution Pvt.Ltd. <a href="http://www.globalnest.com" target="_blank">[http://www.Globalnest.com]</a> (2015)</i></b>
    </center><br/>

</apex:page>

---------------------------------------------------------------------------------------------------
public with sharing class AccountMultipleSearchWithPagenationCLS1 {

    
public BankBook__c acc{get;set;}
public List<accountwrapper> accountList1 {get;set;}
public List<BankBook__c> accountList {get;set;}
List<string> conditions = new List<string>();
private integer totalRecs = 0;
private integer OffsetSize = 0;
private integer LimitSize= 10;
public List<BankBook__c> selectedAccounts = new List<BankBook__c>();

public List<accountwrapper> getAccounts()

{
return accountList1;

}

public AccountMultipleSearchWithPagenationCLS1()
{

accountList1 = new List<accountwrapper>();

for(BankBook__c a: [select Id, Txn_Date__c, Related_Bank_Acc__c, Credit_Debit__c,Entries_Code__c,Amount__c,Credit__c,Debit__c,
Debtor_Name_formula__c,Narration__c from BankBook__c])

accountList1.add(new accountwrapper(a));

//return accountList;

system.debug('==>AccountMultipleSearchWithPagenationCLS  is calling==>');
 acc = new BankBook__c();
 //accountList  = new List<Account>();
}

public PageReference getSelected()

{

selectedAccounts.clear();

for(accountwrapper accwrapper: accountList1)

if(accwrapper.selected == true)

selectedAccounts.add(accwrapper.acc);

return null;

}

public List<BankBook__c> GetSelectedAccounts()

{

if(selectedAccounts.size()>0)

return selectedAccounts;

else

return null;

}


public PageReference deleteAll()

{

try{

List<BankBook__c> selAccounts=GetSelectedAccounts();

if(selAccounts.size()>0){

for(BankBook__c ac:selAccounts){

 

delete ac;

System.debug('###########Data Deleted Successfully###########');
 

}

}
ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR, 'Deleted successfully'));

PageReference pageref=new PageReference('/apex/BulkDelete');

return pageref;

}

Catch(Exception e){

ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR, 'Data Base Error'));

return null;

}

 

 

}

public void searchAcc(){
totalRecs = 0;
OffsetSize = 0;
if(accountList !=null && accountList.size()>0){
 accountList=null;
}
searchAccounts ();
conditions.clear();
}


public Void searchAccounts(){

System.debug('Total Records is ==>'+totalRecs);
System.debug('OffsetSize is ==>'+OffsetSize);

if(accountList != null && !accountList.isEmpty()){
  accountList.clear();
}
 String strQuery ='SELECT Id,Txn_Date__c,From_Date__c,To_Date__c,Related_Bank_Acc__c,CreatedDate,Credit_Debit__c,Entries_Code__c,Debtor_Name_formula__c ,Debit__c,Credit__c,Amount__c,Narration__c From BankBook__c';
 if(acc.From_Date__c!=null){
  String fromDate = acc.From_Date__c+'';
  fromDate = fromDate.split(' ',0)[0]+'T00:00:00.000Z';
   conditions.add('CreatedDate >='+fromDate);
 }

if(acc.To_Date__c!=null){
 String toDate = acc.To_Date__c+'';
  toDate = toDate.split(' ',0)[0]+'T23:59:59.000Z';
   conditions.add('createdDate <='+toDate);
 }

 if(acc.Party_CodeFUP__c!=null && acc.Party_CodeFUP__c!=''){
   conditions.add('Party_CodeFUP__c Like \'%' +acc.Party_CodeFUP__c+'%\' ');
 }
  if(acc.Group_FUP__c!=null && acc.Group_FUP__c!=''){
   conditions.add('Group_FUP__c Like\'%' +acc.Group_FUP__c+'%\' ');
 }

  if (conditions.size() > 0) {
   strQuery += '  WHERE ' + conditions[0];
   for (Integer i = 1; i < conditions.size(); i++)
            strQuery += '  AND ' + conditions[i];
  }
 if(totalRecs !=null && totalRecs ==0){
    List<BankBook__c> accTemp = Database.query(strQuery);
    totalRecs = (accTemp !=null &&accTemp.size()>0)?accTemp.size():0;
 }

 system.debug('strQuery ==>'+strQuery );
 // add sort and limits at the end  
  strQuery += ' ORDER BY Name  ASC, CreatedDate DESC LIMIT :LimitSize OFFSET :OffsetSize';
  
  accountList  =Database.query(strQuery);
  
   

  //conditions.clear();
  //return accountList.size();
}

public void FirstPage()
{
OffsetSize = 0;
searchAccounts();
}
public void previous()
{
OffsetSize = (OffsetSize-LimitSize);
searchAccounts();
}
public void next()
{
OffsetSize = OffsetSize + LimitSize;
searchAccounts();
}
public void LastPage()
{
OffsetSize = totalrecs - math.mod(totalRecs,LimitSize);
searchAccounts();
}
public boolean getprev()
{

if(OffsetSize == 0){

return true;
}
else {

return false;
}
}
public boolean getnxt()
{
if((OffsetSize + LimitSize) > totalRecs){

return true;
}
else {

return false;
}
}

public class accountwrapper

{

public BankBook__c acc{get; set;}

public Boolean selected {get; set;}

public accountwrapper(BankBook__c a)

{

acc = a;

selected = false;

}

}


}

User-added image

 
SCENARIO: If Lead Status is "Open - Not Contacted" add to Account else if it is "Working - Contacted" add to Opportunity
trigger AutoQualifyLead2 on Lead (after insert) {
    List<Account> accs=new List<Account> ();
    List<Opportunity> opps=new List<Opportunity> ();
    for(Lead l:Trigger.New)
    {
        if(l.Status=='Open - Not Contacted'){
            Account a=new Account();
            a.Fax=l.Fax;
            a.Phone=l.Phone;
            a.Industry=l.Industry;
            accs.add(a);
        }
        else{
            if(l.Status=='Working - Contacted'){
                Opportunity op=new Opportunity();
                op.Name=l.Name;
                op.Description=l.Description;
                opps.add(op);
            }
        }
    }
    if(accs.size()>0){    insert accs;    }
    if(opps.size()>0){    insert opps;    }
}
ERROR: As seen in attached Image
User-added image
I need some help figuring out how to do the following. I have a custom button sitting on an account page layout. The custom button is currently set to open a VF page in a new window. that currently works fine. Our users use the service console view and they would like the VF page to open in a sub-tab instead of a new window. So after clicking the button the current account page (that the button is sitting on) should remain and a new sub-tab should open up showing the new VF page. They need to copy info from the acount page and paste it into the new VF page which is why they want it in a sub-tab so they can go back and forth between the two tabs. If you can help please provide example code. I am fairly new so the more explanation you can give the better :-) Thank you.
When attempting to create my Apex trigger for this Trailhead development exercise, I receive an error. I don't understand how this is possible, because the records haven't been updated, and still aren't updating.
"Challenge not yet complete... here's what's wrong:
Setting 'Match_Billing_Address__c' to false updated the records anyway. The trigger should only act when Match_Billing_Address__c is true."


Here's my code:
trigger AccountAddressTrigger on Account (before insert, before update) {

    for(Account a : Trigger.new){
        If (a.Match_Billing_Address__c = true) {
            a.ShippingPostalCode = a.BillingPostalCode;
        }   
    }

}