• mahesh padigela 1
  • NEWBIE
  • 30 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 3
    Likes Given
  • 3
    Questions
  • 7
    Replies
Hi,
I am newbie to salesforce, I am trying to design a visualforce page, which contains a checkbox and list of account details. when the required accounts are checked and custom button is clicked i wanted to display the details of accounts and contact details on the right side of the page.

I am unable to acheieve it. Below is my code.
Please help me,Thanks in Advance.
public class accountcontactwrap {
 public list<accountwrap> warpacc{get;set;}
 public list<account> selectedAccounts{get;set;}
 public list<contact> cont{get;set;}
 public list<contactwrap> wrapcon{get;set;}
  public accountcontactwrap(){
   warpacc=new list<accountwrap>();
   for(account ab:[select id,name,phone from account limit 10]){
    warpacc.add(new accountwrap(ab));
   }
  }
  
public void showcontacts(){
cont=new list<contact>();
 for(accountwrap warpobj:warpacc)
 {
  if(warpobj.isSelected==true){
    cont=[select lastname from contact where accountid=:warpobj.acc.id];
    wrapcon.add(new contactwrap(warpobj,cont));
   
  }
 }
}

 public class accountwrap{
 public account acc{get;set;}
 public boolean isSelected{get;set;}
  public accountwrap(account a){
   acc=a;
   isSelected=false; 
  }
 }
 public class contactwrap{
  public accountwrap accw{get;set;}
  public list<contact> conwrap{get;set;}
  public contactwrap(accountwrap asd,list<contact> ctc){
  accw=asd;
  conwrap=ctc;     
  }
 }
}
The VF Code:
<apex:page sidebar="false" controller="accountcontactwrap" >
<apex:form >
 <apex:pageblock >
   <apex:pageBlockButtons >
     <apex:commandButton action="{!showcontacts}" value="Show contacts for selected accounts" reRender="block2"/>
   </apex:pageBlockButtons>  
 <apex:pageBlockSection columns="2">
   <apex:pageblockTable value="{!warpacc}" var="wc">
    <apex:column >
     <apex:inputcheckbox />
    </apex:column>
    <apex:column value="{!wc.acc.name}"/>
   </apex:pageblockTable>
   <td>
  <apex:repeat value="{!wrapcon}" var="c" id="block2">
  <tr><td>
   <apex:outputText value="{!c.accw.acc.name}"/></td>
<td>   <apex:outputText value="{!c.conwrap}"/></td></tr>
  </apex:repeat>  
  </td>
  </apex:pageBlockSection>   
 </apex:pageblock>
</apex:form>  
</apex:page>


 
Hi,
I am need to to salesforce, I am writing a visualforce page to display check boxes and list of accounts with a process button. Upon slecting the accounts and the check boxes the process button should contain a method which displays the list of contacts related to selected accounts.
I am unable to retrieve the list of contact names using the selected accounts.I am getting an error when i use a soql query to retrieve the contacts using the account id.

Below is my apex code for above requirment.
Please let me know if my question is not clear.


public class accountcontactwrap {
 public list<accountwrap> warpacc{get;set;}
 public list<account> selectedAccounts{get;set;}
 public list<contact> cont{get;set;}
// public list<contactwrap> wrapcon{get;set;}
  public accountcontactwrap(){
   warpacc=new list<accountwrap>();
   for(account ab:[select id,name,phone from account limit 10]){
    warpacc.add(new accountwrap(ab));
   }
  }
  
public void showcontacts(){
cont=new list<contact>();
 for(accountwrap warpobj:warpacc)
 {
  if(warpobj.isSelected==true){
  cont=[select lastname from contact where account.id=warpobj.acc.id];
   
  }
 }
}

 public class accountwrap{
 public account acc{get;set;}
 public boolean isSelected{get;set;}
  public accountwrap(account a){
   acc=a;
   isSelected=false; 
  }
I Have customer obj with field IsPrimary(checkbox) and addrText(textarea)
I also have an obj Addresses with field Addr_type(picklist with valuse 'Primery' and 'Secondery') and Addr_Line_1
if IspPrimary is checked, addrText should get populated with Addresses record Addr_Line_1 having  having picklist value as primary 
else adresses record with secondery value of addressLine_1
Hi,
I am newbie to salesforce, I am trying to design a visualforce page, which contains a checkbox and list of account details. when the required accounts are checked and custom button is clicked i wanted to display the details of accounts and contact details on the right side of the page.

I am unable to acheieve it. Below is my code.
Please help me,Thanks in Advance.
public class accountcontactwrap {
 public list<accountwrap> warpacc{get;set;}
 public list<account> selectedAccounts{get;set;}
 public list<contact> cont{get;set;}
 public list<contactwrap> wrapcon{get;set;}
  public accountcontactwrap(){
   warpacc=new list<accountwrap>();
   for(account ab:[select id,name,phone from account limit 10]){
    warpacc.add(new accountwrap(ab));
   }
  }
  
public void showcontacts(){
cont=new list<contact>();
 for(accountwrap warpobj:warpacc)
 {
  if(warpobj.isSelected==true){
    cont=[select lastname from contact where accountid=:warpobj.acc.id];
    wrapcon.add(new contactwrap(warpobj,cont));
   
  }
 }
}

 public class accountwrap{
 public account acc{get;set;}
 public boolean isSelected{get;set;}
  public accountwrap(account a){
   acc=a;
   isSelected=false; 
  }
 }
 public class contactwrap{
  public accountwrap accw{get;set;}
  public list<contact> conwrap{get;set;}
  public contactwrap(accountwrap asd,list<contact> ctc){
  accw=asd;
  conwrap=ctc;     
  }
 }
}
The VF Code:
<apex:page sidebar="false" controller="accountcontactwrap" >
<apex:form >
 <apex:pageblock >
   <apex:pageBlockButtons >
     <apex:commandButton action="{!showcontacts}" value="Show contacts for selected accounts" reRender="block2"/>
   </apex:pageBlockButtons>  
 <apex:pageBlockSection columns="2">
   <apex:pageblockTable value="{!warpacc}" var="wc">
    <apex:column >
     <apex:inputcheckbox />
    </apex:column>
    <apex:column value="{!wc.acc.name}"/>
   </apex:pageblockTable>
   <td>
  <apex:repeat value="{!wrapcon}" var="c" id="block2">
  <tr><td>
   <apex:outputText value="{!c.accw.acc.name}"/></td>
<td>   <apex:outputText value="{!c.conwrap}"/></td></tr>
  </apex:repeat>  
  </td>
  </apex:pageBlockSection>   
 </apex:pageblock>
</apex:form>  
</apex:page>


 

I have an Id for a record I am getting from a trigger and I want to compare it to an Id in my SOQL Where clause. What I am doing wrong

trigger UpdateTest on Test__c (before insert) {
    
    List<Test__c> testList = new List<Test__c>();
   
	System.debug(Trigger.New);
    ID accNo;
    for(Test__c a : Trigger.New) {
        accNo = a.Account__c;
    }  
    
     testList = [SELECT Id, Status__c, Account__c FROM Test__c WHERE Account__c = accNo];
    
    List<Test__c> updateList = new List<Test__c>();
    
    for(Test__c contract : testList){

           contract.Status__c = 'Past';
        updateList.add(contract);

        
    }
    
    update updateList;


    
}
Error:
Error Occurred: This error occurred when the flow tried to create records: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: PlacementTrigger: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PlacementTrigger: execution of AfterUpdate caused by: System.QueryException: Non-selective query against large object type (more than 200000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times) Trigger.PlacementTrigger: line 43, column 1: [] Trigger.PlacementTrigger: line 33, column 1. You can look up ExceptionCode values in the SOAP API Developer Guide.

APEX:
1    trigger PlacementTrigger on Placement__c (after insert, after update) {
2        
3        List<Placement_Schedule__c> schedules = new List<Placement_Schedule__c>();
4        Date start = date.today();
5        Integer scheduleLength = 0;
6        Decimal value = 0;
7        Decimal units = 0;
8        
9        if(Trigger.isInsert){
10            for(Placement__c P : Trigger.New){
11                if(P.IO__r.Opportunity__r.StageName != 'Closed Won'){
12                    Start = P.Start_Date__c;
13                scheduleLength = Start.daysBetween(P.End_Date__c)+1;
14                    System.debug('Placement schedule is ' + scheduleLength +' days long.');
15                value = P.Total_Amount__c;
16                units = P.Quantity__c;
17                
18                // create new revenue schedules for date range specified 
19                for(integer i = 0; i<scheduleLength; i++){
20                   Placement_Schedule__c PS = new Placement_Schedule__c(
21                       Revenue__c = value/scheduleLength,
22                       Forecast_Amount__c = value/scheduleLength,
23                       Quantity__c = units/scheduleLength,
24                       Placement__c = P.Id,
25                       Date__c = P.Start_Date__c + i,
26                       Name__c = null
27                   );
28                    schedules.add(PS);  
29                } // end loop to build Revenue Schedules
30              }// end check for closed won
31            } // end for loop over Placement__c
32            
33            insert schedules;
34            
35        } // end if insert check
36       
37        if(Trigger.isUpdate){
38            // Boolean to check if any of the Revenue Schedules have been actualized. If TRUE then code will later be blocked
39            Boolean actualized = FALSE;
40            
41            // Set to hold IDs of all placements with actualized revenue schedules
42            Set<Placement__c> actualizedPlacements = new Set<Placement__c>();
43        List<Placement__c> actualizedPlacementList = new List<Placement__c>([
44                        SELECT Id FROM Placement__c WHERE Id IN (
45                                        SELECT Placement__c FROM Placement_Schedule__c
46                                        WHERE Actualized__c = TRUE)]);
47           
48            for(Placement__c placement : actualizedPlacementList){
49                actualizedPlacements.add(placement);
50            }                                                         
51            // list for what the new schedule should be to check if an insert is necessary
52            List<Placement_Schedule__c> newSchedules = new List<Placement_Schedule__c>();
53            // list for revenue schedules that need to be deleted
54            List<Placement_Schedule__c> forDelete = new List<Placement_Schedule__c>();  
55            
56            // loop through Placements to look for valid edits
57            for(Placement__c PN : Trigger.New){
58               actualized = actualizedPlacementList.contains(PN);
59               Placement__c PO = Trigger.oldmap.get(PN.Id); 
60              // check if there is a delay and that the delay is not prior to the original start date
61               if(PN.Delayed_Start_Date__c != null && PN.Delayed_Start_Date__c > PN.Start_Date__c){
62                   Start = PN.Delayed_Start_Date__c;
63               } else {
64                   Start = PN.Start_Date__c;
65               }
66                
67               Integer originalLength = 0;
68               originalLength = PN.Start_Date__c.daysBetween(PN.End_Date__c)+1;
69               scheduleLength = Start.daysBetween(PN.End_Date__c)+1;
70                    System.debug('Placement schedule is ' + scheduleLength +' days long.');
71               value = PN.Total_Amount__c;
72               units = PN.Quantity__c;
73                
74            // checks if changes need to be made to the Revenue Schedules   
75                if(actualized == FALSE && PN.IO__r.Opportunity__r.StageName != 'Closed Won' &&
76                   (PN.Start_Date__c != PO.Start_Date__c || 
77                   PN.Delayed_Start_Date__c != PO.Delayed_Start_Date__c ||
78                   PN.Total_Amount__c != PO.Total_Amount__c ||
79                   PN.End_Date__c != PO.End_Date__c               )){
80    
81            // build list of new proper schedule in order to ensure there are no edits required
82                 for(integer i = 0; i<originalLength; i++){
83                   Placement_Schedule__c PSNew = new Placement_Schedule__c(
84                       Revenue__c = value/originalLength,
85                       Forecast_Amount__c = value/scheduleLength,
86                       Quantity__c = units/scheduleLength,
87                       Placement__c = PN.Id,
88                       Date__c = PN.Start_Date__c + i,
89                       Name__c = null
90                   );
91                    newSchedules.add(PSNew);  
92                 } // end loop to build proper schedule
93                            
94                       
95              // get schedules already generated
96              List<Placement_Schedule__c> oldSchedules = new List<Placement_Schedule__c>(
97              [SELECT Id, Date__c, Revenue__c, Forecast_Amount__c FROM Placement_Schedule__c
98              WHERE Placement__c =: PN.Id]
99              );        
100                       
101                for(Placement_Schedule__c OS : oldSchedules){
102                  
103                    // check for deletes
104                    if(OS.Date__c < PN.Start_Date__c || OS.Date__c > PN.End_Date__c){
105                       forDelete.add(OS); 
106                    }
107                    // check for valid delays
108                    if(OS.Date__c < Start){
109                       OS.Forecast_Amount__c = 0;
110                       OS.Revenue__c = value/originalLength;
111                       OS.Quantity__c = 0;
112                       schedules.add(OS);
113                     } else {
114                       OS.Forecast_Amount__c = value/scheduleLength;
115                       OS.Revenue__c = value/originalLength;
116                       OS.Quantity__c = units/scheduleLength;
117                       schedules.add(OS);
118                     }// check for if revenue schedule is no longer in placement date range
119                   
120                 
121                   } // end loop over schedules  
122                       
123                // check for inserts needed
124                Set<Placement_Schedule__c> alreadyExist = new Set<Placement_Schedule__c>();
125                       for(Placement_Schedule__c RS : newSchedules){
126                           for(Placement_Schedule__c RSOld : oldSchedules){
127                               if(RS.Date__c == RSOld.Date__c){
128                                   alreadyExist.add(RS);
129                                   System.debug('Revenue Schedule already exists with date '+RSOld.Date__c);
130                               } // end if check
131                           } // end loop over old schedules
132                           if(!alreadyExist.contains(RS)){
133                           schedules.add(RS);     
134                           }
135                       } // end loop over new schedules
136                       
137                } // end if valid update check       
138            } // end loop over Placement__c 
139            
140          upsert schedules;
141            
142            try{ 
143            delete forDelete;
144            System.debug('Deleting '+ forDelete.size() +' Revenue Schedules.');
145            } catch (Exception e) {
146            System.debug('Unable to delete Revenue Schedules: '+e);
147            }
148            
149        } // end of update check 
150        
151    } // end class
 
Hi,
I am need to to salesforce, I am writing a visualforce page to display check boxes and list of accounts with a process button. Upon slecting the accounts and the check boxes the process button should contain a method which displays the list of contacts related to selected accounts.
I am unable to retrieve the list of contact names using the selected accounts.I am getting an error when i use a soql query to retrieve the contacts using the account id.

Below is my apex code for above requirment.
Please let me know if my question is not clear.


public class accountcontactwrap {
 public list<accountwrap> warpacc{get;set;}
 public list<account> selectedAccounts{get;set;}
 public list<contact> cont{get;set;}
// public list<contactwrap> wrapcon{get;set;}
  public accountcontactwrap(){
   warpacc=new list<accountwrap>();
   for(account ab:[select id,name,phone from account limit 10]){
    warpacc.add(new accountwrap(ab));
   }
  }
  
public void showcontacts(){
cont=new list<contact>();
 for(accountwrap warpobj:warpacc)
 {
  if(warpobj.isSelected==true){
  cont=[select lastname from contact where account.id=warpobj.acc.id];
   
  }
 }
}

 public class accountwrap{
 public account acc{get;set;}
 public boolean isSelected{get;set;}
  public accountwrap(account a){
   acc=a;
   isSelected=false; 
  }
I have been building a VF page that updates child and parent records 

The error that I get back after inputting is
​​​​​​
Visualforce Error
Help for this Page

System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!insertChild}' in component <apex:commandButton> in page updatechild: Class.AddingChildController.insertChild: line 23, column 1


User-added image
​​​​​​This is the VF page
 
<apex:page controller="AddingChildController" >
<apex:form >
    <apex:variable var="rowNum" value="{!0}" />
    <apex:pageBlock >
        <apex:variable var="rowNum" value="{!0}" />
        <apex:PageBlockTable value="{!childList}" var="int">
        <apex:facet name="footer">
            <apex:commandLink value="Add" action="{!insertRow}"/>
            </apex:facet>
            <apex:column headerValue="Lead Generator">
                <apex:inputField value="{!int.Lead_Gen__c}"/>                                      
            </apex:column>
            
            
            
            <apex:column headerValue="Monday">
            <apex:inputField value="{!int.Monday__c}"/>
            </apex:column>
            <apex:column headerValue="Tuesday">
            <apex:inputField value="{!int.Tuesday__c}"/>
            </apex:column>
            <apex:column headerValue="Wednesday">
            <apex:inputField value="{!int.Wednesday__c}"/>
            </apex:column>
            <apex:column headerValue="Thursday">
            <apex:inputField value="{!int.Thursday__c}"/>
            </apex:column>
            <apex:column headerValue="Friday">
            <apex:inputField value="{!int.Friday__c}"/>
            </apex:column>
             <apex:column headerValue="Delete">
            <apex:commandLink style="font-size:15px; font-weight:bold; text-align:center;color:red;" value="X" action="{!delRow}">
                <apex:param value="{!rowNum}" name="index"/>
                </apex:commandLink>
                <apex:variable var="rowNum" value="{!rowNum+1}"/>
            </apex:column>
        </apex:PageBlockTable>
    <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!insertChild}"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>

  </apex:form>
</apex:page>

And this is the controller

 
public class AddingChildController {
Id parentId;
public List<Time_Sheets__c> childList {get;set;}
public Integer rowNum{get;set;}

public Lead_Gen__c Parent {get;set;}
 
 
 


public AddingChildController(){
    Id childId = ApexPages.currentPage().getParameters().get('childId');
    childList = new List<Time_Sheets__c>();
    childList.add(new Time_Sheets__c());
    ParentId=ApexPages.currentPage().getParameters().get('ParentId');   
      
}

public pagereference insertChild(){
    insert childList;

    Parent.Id=parentId;
    update Parent;

    Pagereference page=new pagereference('/'+parentId);
    Return page;

       
}    

public void insertRow(){
    childList.add(new Time_Sheets__c());
    
    
}

public void delRow(){
    rowNum = 
Integer.valueof(apexpages.currentpage().getparameters().get('index'));

childList.remove(rowNum);
}
}

​​​​​​Could someone assist with what I am missing

cheers 
I am trying to fetch Duplicate Records based on certain field but hitting below error. Please help me if my query is wrong.

Query:-  SELECT MHC2__MHC_Project_ID__c, count(Id) FROM MHC2__Project__c GROUP BY MHC2__MHC_Project_ID__c HAVING count(Id)>1 limit 1000


Error:- EXCEEDED_ID_LIMIT: Aggregate query does not support queryMore(), use LIMIT to restrict the results to a single batch

when i tried to get them to CSV then hitting below error

Failed: InvalidBatch : Failed to process query: FUNCTIONALITY_NOT_ENABLED: Aggregate Relationships not supported in Bulk Query


Thanks,
Chandra

I have an Id for a record I am getting from a trigger and I want to compare it to an Id in my SOQL Where clause. What I am doing wrong

trigger UpdateTest on Test__c (before insert) {
    
    List<Test__c> testList = new List<Test__c>();
   
	System.debug(Trigger.New);
    ID accNo;
    for(Test__c a : Trigger.New) {
        accNo = a.Account__c;
    }  
    
     testList = [SELECT Id, Status__c, Account__c FROM Test__c WHERE Account__c = accNo];
    
    List<Test__c> updateList = new List<Test__c>();
    
    for(Test__c contract : testList){

           contract.Status__c = 'Past';
        updateList.add(contract);

        
    }
    
    update updateList;


    
}