• Amita Tatar
  • NEWBIE
  • 40 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 64
    Questions
  • 72
    Replies
Hi All,

I have created a scratch org and after enabling communities, I tried to create community but i am getting and error which sayd. An expected error occured. Can someone help me on this ?
Its really urgent. 

Thanks,
Amita
Hi Guys,

I have below test class and i am not able to cover the part after OLI id field as it is coming blank.
Its a formula field haveing opportunitylineitem.id as formula in it. 

User-added image

Regards,
Amita Tatar
Hi,

I have written following apex code to import data from csv using vf page.
but it is importing only 200 records. If i insert more than 200 , it ignores first 200 records.
Can you please help me here
Apex Code:

/* File Name : importDataFromCSVControllerMandE.apxc
 * Description : This apex controller reads imported CSV file and creates Guests and Delegates for contact.
 *              It also creates new Contact record if that particular Contact is not present in the system.
 * @@Author : Aress Software and Education Technologies Pvt. Ltd.
 * Created Date : 27/07/2017
 * Last Modified Date : 28/08/2017
*/

public class importDataFromCSVControllerMandE {
	
    //constructor
    public importDataFromCSVControllerMandE(ApexPages.StandardController controller) {
    }
    
    public string OppId;
    public string AcctId;
    public Blob csvFileBody{get;set;}
    public String csvAsString{get;set;}
    public String[] csvFileLines{get;set;}
    public List<Guests_Delegate__c> gdlist{get;set;}
    Set<String> oIds = new Set<String>();
    Set<String> emailIds = new Set<String>();
    
    Map<String,Id> accounts = new Map<String,Id>();
    // Map<String,Id> accountsFromCSV = new Map<String,Id>();
    List<Contact> newContactList = new List<Contact>();
    
    Set<String> CSVNames = new Set<String>();
    Map<String,Id> ContMap = new Map<String,Id>();
    
    //constructor
    public importDataFromCSVControllerMandE(){
        csvFileLines = new String[]{};
        gdlist= New List<Guests_Delegate__c>();
    }
    /*
* Method Name - importCSVFile()
* Description - This method invokes when "Import Guests & Delegates" button is clicked. 
*				It reads the imported CSV file and creates Guests and Delegates accordingly.
*				If the system come across new Email in the CSV template, then it is able to create new Contact for that record.
*				The method can able to handle the exception, if any type of error occurs.
*/
    public void importCSVFile(){
        try{
            OppId = apexpages.currentpage().getparameters().get('oppId');
            system.debug('Opportunity Id - > '+OppId);
            AcctId = apexpages.currentpage().getparameters().get('acctId');
            system.debug('Account Id - > '+AcctId);
            
            // Read CSV file body and store it in variable
            csvAsString = csvFileBody.toString();
            system.debug(' csvAsString******************* '+ csvAsString);
            
            List<Guests_Delegate__c> PrevGuestList = [SELECT Id FROM Guests_Delegate__c WHERE Booking__c =: OppId];
            if(csvAsString!='' || csvAsString != NULL){
                if(PrevGuestList.size() > 0){
                	delete PrevGuestList;   //Delete the previous Guest and Delegates and then add latest uploaded ones.
                }
            }
            
            // Split CSV String to lines
            csvFileLines = csvAsString.split('\n');
            system.debug(' csvFileLines******************* '+ csvFileLines.size());
            
            //************************** To check for contact ******************************
            //for(Integer i=1;i< csvFileLines.size() ; i++){
            //    String[] csvRecordDataCheck = csvFileLines[i].split(',');
            //    emailIds.add(csvRecordDataCheck[5]);
            //    system.debug('emailIds-------'+emailIds);
            //}
            
            // Mapping by first name and last name
            for(Integer i=1 ; i< csvFileLines.size() ; i++){
                system.debug('In first name and last name mapping loop');
                String[] csvRecordData = csvFileLines[i].split(',');
                system.debug('csvRecordData -> '+csvRecordData);
                string names = csvRecordData[1]+ ' ' +csvRecordData[2];
                CSVNames.add(names);
            }
            system.debug('CSVNames -> '+CSVNames);
            
            // getting account Id from the records who are already present in contact
            List<Contact> cList = [SELECT id, name, firstname, lastname, email, AccountId FROM contact WHERE name in : CSVNames];
            system.debug('cList********'+cList);
            
            //Map<String, Id> contactMap = new Map<String, Id>();
            //for(Contact c : cList){
            //contactMap.put(c.Email, c.Id);
            //}
            
            ContMap = new Map<String,Id>();
            for(Contact c : cList){
                ContMap.put(c.Name, c.id);
            }
            system.debug('ContMap -> '+ContMap);
            
             Id gDRecTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('Guest & Delegate Contact').getRecordTypeId();
            system.debug('G and D Record Type -> '+gDRecTypeId);
            
            for(Integer i=1; i < csvFileLines.size(); i++){
                String[] csvRecordDatacon = csvFileLines[i].split(',');
                string names = csvRecordDatacon[1]+ ' ' +csvRecordDatacon[2];
                if(!ContMap.containsKey(names)){
                    Contact con = new Contact();
                    //record type here
                    //con.RecordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('VIP Client Contact').getRecordTypeId();
                    //system.debug(' con.RecordTypeId'+ con.RecordTypeId);
                    //con.AccountId = csvRecordDatacon[3];
                    con.AccountId = AcctId;
                    con.Guest__c = TRUE;
                    con.MobilePhone = csvRecordDatacon[4];
                    con.Email = csvRecordDatacon[5];
                    con.Salutation = csvRecordDatacon[0];
                    con.FirstName = csvRecordDatacon[1];
                    con.LastName = csvRecordDatacon[2];
                    con.Title = csvRecordDatacon[3];
                    con.RecordTypeId = gDRecTypeId;
                    newContactList.add(con);
                    system.debug('Contact added'+newContactList);
                }
            }
            insert newContactList;
            system.debug('newContactList after ->'+newContactList);
            
            //All Contact List with new Contacts from CSV
            cList = [select id,name,firstname, lastname, email, AccountId from contact where name in : CSVNames];
            system.debug('cList********'+cList);
            
            ContMap = new Map<String, Id>();
            for(Contact c : cList){
                ContMap.put(c.Name, c.Id);
            }
            system.debug('*******ContMap*****'+ContMap);
            
            // Iterate CSV file lines and retrieve one column at a time.
            system.debug(' csvFileLines.size()****************'+ csvFileLines.size());
            for(Integer i=1; i < csvFileLines.size(); i++){
               
                
                Guests_Delegate__c gdObj = new Guests_Delegate__c();
                String[] csvRecordData = csvFileLines[i].split(',');
                system.debug('csvRecordData765-------------------'+csvRecordData);
                
                gdObj.Work_Phone__c = csvRecordData[4];
                system.debug(' gdObj.Work_Phone__c*************'+ gdObj.Work_Phone__c);
              
                //gdObj.Booking__c = csvRecordData[1];
                //system.debug('gdObj.Booking__c==========='+ gdObj.Booking__c );
                //Updated and fetched from URL
                gdObj.Booking__c = OppId;
                system.debug('gdObj.Booking__c==========='+ gdObj.Booking__c );
                
                //gdObj.Account__c =  csvRecordData[3]; 
                //system.debug(' gdObj.Account__c*************'+ gdObj.Account__c);
                //Updated and fetched from URL
                gdObj.Account__c =  AcctId;
                system.debug(' gdObj.Account__c*************'+ gdObj.Account__c);
                
                gdObj.Email__c = csvRecordData[5];
                
                system.debug('csvRecordData[6] -> '+csvRecordData[6]);
                
                //Accepting data in DD-MM-YYYY from csv file and changing it to YYYY-MM-DD as salesforce accepts this date format.
                string a  = csvRecordData[6];
                String a_date = a.substring(0,2);
                system.debug('String a_date----------'+a_date);
                String a_month = a.substring(3,5);
                system.debug('String a_month----------'+a_month);
                string a_year = a.substring(6,10);
                system.debug('String a_year----------'+a_year);
                string arrival_date = a_year+'-'+a_month+'-'+a_date; //modifying the date as per Salesforce's convensions.
                system.debug('String arrival_date----------'+arrival_date);
                
                gdObj.Arrival_Date__c = date.valueOf(arrival_date);
                system.debug('gdObj.Arrival_Date__c*************'+ gdObj.Arrival_Date__c);
                
                //Accepting data in DD-MM-YYYY from csv file and changing it to YYYY-MM-DD as salesforce accepts this date format.
                //string d  = csvRecordData[7];
                //String d_date = a.substring(0,2);
                //String d_month = a.substring(3,5);
                //string d_year = a.substring(6,10);
                //string departure_date = a_year+'-'+a_month+'-'+a_date;
                
              //  gdObj.Departure_Date__c= date.valueOf(departure_date);
               // system.debug('gdObj.Departure_Date__c*************'+ gdObj.Departure_Date__c);
               decimal nights = decimal.ValueOf(csvRecordData[7]); 
               system.debug('nights--------'+nights);
               gdObj.No_of_Nights__c= nights;
               system.debug('gdObj.No_of_Nights__c*************'+ gdObj.No_of_Nights__c);
                
                //adding Departure date
                gdObj.Departure_Date__c = gdObj.Arrival_Date__c.addDays(Integer.valueOf(gdObj.No_of_Nights__c));
                
                Decimal rooms = Decimal.valueOf(csvRecordData[8]);
                gdObj.No_of_Rooms__c = rooms;
                system.debug('gdObj.No_of_Rooms__c*************'+ gdObj.No_of_Rooms__c);
                
                gdObj.Room_Type__c= csvRecordData[9];
                system.debug('gdObj.Room_Type__c==========='+  gdObj.Room_Type__c);
                
                gdObj.Occupancy__c= csvRecordData[10]; 
                system.debug(' gdObj.Occupancy__c*************'+ gdObj.Occupancy__c); 
                
                gdObj.Sharing_With__c = csvRecordData[11];
                gdObj.Meal_Plan__c =  csvRecordData[12];
                system.debug(' gdObj.Meal_Plan__c*************'+ gdObj.Meal_Plan__c); 
                
               // gdObj.Contact__c = contactMap.get(csvRecordData[11]);
                
                gdObj.Allowancesv2__c= csvRecordData[13];
                system.debug('gdObj.Allowances__c==========='+gdObj.Allowancesv2__c);
				
                gdObj.Parking_Required__c = boolean.valueOf(csvRecordData[14]);
                system.debug('gdObj.Parking_Required__c*************'+ gdObj.Parking_Required__c);
                
                gdObj.Number_Plate__c = csvRecordData[15];
                system.debug('gdObj.Number_Plate__c*************'+ gdObj.Number_Plate__c);
                
                gdObj.Notes__c = csvRecordData[16];
                system.debug('gdObj.Notes__c*************'+ gdObj.Notes__c);
                
                gdObj.Special_Food_Requirements__c = csvRecordData[18];
                system.debug('gdObj.Special_Food_Requirements__c*************'+ gdObj.Special_Food_Requirements__c);
                
                Decimal rate = Decimal.valueOf(csvRecordData[17]);
                gdObj.Rate__c = rate;
                system.debug('gdObj.Rate__c*************'+ gdObj.Rate__c);
                
                gdObj.Contact_Type__c = csvRecordData[19];
                system.debug('gdObj.Contact_Type__c*************'+ gdObj.Contact_Type__c);
                
                gdObj.Shift__c = csvRecordData[20];
                system.debug('gdObj.Shift__c*************'+ gdObj.Shift__c);
                
                gdObj.Commissionable__c = csvRecordData[21];
                system.debug('gdObj.Commissionable__c*************'+ gdObj.Commissionable__c);
                
                gdObj.Non_Commissionable_Reasons__c = csvRecordData[22];
                system.debug('gdObj.Non_Commissionable_Reasons__c*************'+ gdObj.Non_Commissionable_Reasons__c);
                
                gdObj.VAT_on_Commission__c = csvRecordData[24];
                system.debug('gdObj.VAT_on_Commission__c*************'+ gdObj.VAT_on_Commission__c);
                
                Decimal commPerAct = Decimal.valueOf(csvRecordData[23]);
                gdObj.Commission_Percentage_Actual__c = commPerAct;
                system.debug('gdObj.Commission_Percentage_Actual__c*************'+ gdObj.Commission_Percentage_Actual__c);
                
                string fullname = csvRecordData[1] + ' ' + csvRecordData[2];
                gdObj.Contact__c = ContMap.get(fullname);
                
                gdlist.add(gdObj);
            }
            
            if(gdlist.size()>0){
                insert gdlist;
                system.debug('GD list -> '+gdlist);
                system.debug('Size -----------------'+ gdlist.size());
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Confirm,'Data Imported Successfully'));
            }
            else{
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please Import Valid Data'));
            }
        }
        catch(Exception e){
            //ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importing data into Salesforce. Please make sure input csv file is correct');
            //ApexPages.addMessage(errorMessage);
            system.debug('Error - >>>>'+e); 
        }
    }
}

 
Hi all,

I am pasting below my apex class and test class. I am getting accID as null. Please help me where i am going wrong.
apex class----------------------

public class DisplayNotesNew{

public List<WrapperClass> listWrapper {get;set;}
public List<ContactWrapper> listWrapper1 {get;set;}
public List<OpportunityWrapper> listWrapper2 {get;set;}
public Id accId;
Public Account acc;
public List<Note> selectedNotes{get;set;}
public List<Contact> selectedContacts{get;set;}
public List<opportunity> selectedOpps{get;set;}
List<note> contactNote = new List<note>();
List<note> oppNote = new List<note>();
public ID noteID {get;set;}
Public String getRadioValue{get;set;}

public void assignNoteId() {
   Id note = ApexPages.currentPage().getParameters().get('note');
   system.debug('18-->'+note );
   if(note != null) {
      noteID = note;
   }
}    

public DisplayNotesNew(){
        
}
public DisplayNotesNew(ApexPages.StandardController Controller) {

accId = ApexPages.currentPage().getParameters().get('id');
system.debug('********accId************'+accId);
  
List<Note> listAcct = [SELECT Id,Title, Body,Parent.Id,CreatedDate FROM Note where Parent.Id =: accId order by ID DESC];
    system.debug('listAcct--------------------'+listAcct);
  if(listAcct.size() > 0) {  
      listWrapper = new List<WrapperClass>();      
      for(Note a : listAcct) {        
          listWrapper.add(new WrapperClass(a));
        }
    }
List<Contact> listContact = [Select Id, FirstName, LastName,name From Contact where AccountId =: accId order by name DESC];
    if(listContact.size() > 0){     
        listWrapper1 = new List<ContactWrapper>();          
        for(Contact c : listContact){            
            listWrapper1.add(new ContactWrapper(c));
        }
   }

List<Opportunity> listOpp = [select id,name,closeDate from Opportunity where AccountId =: accId order by closeDate ASC];
    if(listOpp.size() > 0){  
        listWrapper2 = new List<OpportunityWrapper>();             
        for(Opportunity o : listOpp){              
            listWrapper2.add(new OpportunityWrapper(o));
       }
   }
}
public pagereference assignNotes(){
system.debug('******noteID******'+noteID);
Note no = [select id,title,body,parentId from Note where id=:noteID limit 1];
system.debug('********no******'+no);

/*selectedNotes = new List<Note>();
system.debug('*********listWrapper ********'+listWrapper);
for(WrapperClass wrapAccountObj : listWrapper ) {
     if(wrapAccountObj.checkBool == true) {
        selectedNotes.add(wrapAccountObj.acct);
        system.debug('*********selectedNotes********'+selectedNotes);
     }  
}  */

selectedContacts = new List<Contact>();
 for(ContactWrapper wrapContactObj : listWrapper1){   
     if(wrapContactObj.checkBool == true){
         Note nt = new Note();  
         nt.Title = no.title;
         nt.Body = no.body;
         nt.ParentId = wrapContactObj.cons.Id; 
         contactNote.add(nt);
         //selectedContacts.add(wrapContactObj.cons);
         //system.debug('*********selectedContacts******'+selectedContacts);
       }
    }
insert contactNote;
    
selectedOpps = new List<Opportunity>();
  for(OpportunityWrapper wrapOppObj : listWrapper2){  
      if(wrapOppObj.checkBool == true){  
          Note nt = new Note(); 
          nt.Title = no.title;  
          nt.Body = no.Body;
          nt.parentId = wrapOppObj.ops.Id;
          oppNote.add(nt);
          //selectedOpps.add(wrapOppObj.ops);
         // system.debug('******selectedOpps*********'+selectedOpps);
     }
  }
insert oppNote;
  PageReference pg = new PageReference('/apex/DisplayAccountNotes?id='+accId);  /*Redirect on the same page*/  pg.setRedirect(true); return pg; 
}
public class WrapperClass{
   public Boolean checkBool {get;set;}
   public Note acct {get;set;}
   public WrapperClass(Note acct){
        this.acct = acct;
        checkBool = false;
       }        
    }
public class ContactWrapper{
   public Boolean checkBool {get;set;}
   public Contact cons {get;set;}
   public ContactWrapper(Contact cons){
        this.cons = cons;
        checkBool = false;
        }    
     }
public Class OpportunityWrapper{
   public Boolean checkBool {get;set;}
   public Opportunity ops {get;set;}
   public OpportunityWrapper(Opportunity ops){
        this.ops = ops;
        checkBool = false;
        }   
     }
}

Test Class-----------------------------------------

@isTest
public class DisplayNotesNewTestClass {

  static testmethod void test1(){
    
    Account acc = new Account(name='vivek112');
    insert acc;
   
    Note ne = new Note(parentid = acc.Id,body ='hi',title = 'Bye');
    insert ne;

    Contact con = new Contact(FirstName='vivek112', AccountId = acc.Id);
    List<Contact> lstcon = new List<Contact>();
    lstcon.add(con);   
        
    Opportunity opp = new opportunity(name = 'a',stageName = 'Closed Won',closedate = date.today(),Renewal_Date__c = date.today(),AccountId = acc.Id);
    List<Opportunity> lstopp = new List<Opportunity>();
    lstopp.add(opp);  
    system.debug('lstopp'+lstopp);
     
     Note note1 = new Note(parentid = acc.Id,title='test',body= 'hi');
    List<note> nList = new List<Note>();
    nList.add(note1);
   
    Note note2 = new Note(parentId = acc.Id,title = 'Hi',body = 'Hi');
    insert note2;
    system.debug('note2-------------'+note2);
    
  
    
    PageReference pageRef = Page.DisplayAccountNotes;
    Test.setCurrentPage(pageRef);      
    DisplayNotesNew obj = new DisplayNotesNew(new ApexPages.StandardController(acc));
    ApexPages.currentPage().getParameters().put('accId',acc.Id);
   // DisplayNotesNew controller = new DisplayNotesNew();
  	  Test.startTest();
 
    ApexPages.CurrentPage().getparameters().put('note',note2.Id);

    DisplayNotesNew objCustom = new DisplayNotesNew ();
    DisplayNotesNew.ContactWrapper objwrap = new DisplayNotesNew.ContactWrapper(con);
    DisplayNotesNew.OpportunityWrapper objwrap1 = new  DisplayNotesNew.OpportunityWrapper(opp); 
    DisplayNotesNew.WrapperClass objwrap2 = new DisplayNotesNew.WrapperClass(note1);
    Id accId = acc.Id;
    id note = note2.id;
    objCustom.assignNoteId();
    id noteID = note;
    objCustom.assignNotes();
    Test.stopTest();
    }
}

-Amita
Hi all,

I have a test class and i am not able to increase its code coverage.
I am posting my apex class and test class code.
Apex Class----------------------------------------

public class DisplayNotesNew{

public List<WrapperClass> listWrapper {get;set;}
public List<ContactWrapper> listWrapper1 {get;set;}
public List<OpportunityWrapper> listWrapper2 {get;set;}
public Id accId;
Public Account acc;
public List<Note> selectedNotes{get;set;}
public List<Contact> selectedContacts{get;set;}
public List<opportunity> selectedOpps{get;set;}
List<note> contactNote = new List<note>();
List<note> oppNote = new List<note>();
public ID noteID {get;set;}
Public String getRadioValue{get;set;}

public void assignNoteId() {
   Id note = ApexPages.currentPage().getParameters().get('note');
   system.debug('18-->'+note );
   if(note != null) {
      noteID = note;
   }
}    

public DisplayNotesNew(){
        
}
public DisplayNotesNew(ApexPages.StandardController Controller) {

accId = ApexPages.currentPage().getParameters().get('id');
system.debug('********************'+accId);
  
List<Note> listAcct = [SELECT Id,Title, Body,Parent.Id,CreatedDate FROM Note where Parent.Id =: accId order by ID DESC];
  if(listAcct.size() > 0) {
    listWrapper = new List<WrapperClass>();
       for(Note a : listAcct) {
          listWrapper.add(new WrapperClass(a));
        }
    }
List<Contact> listContact = [Select Id, FirstName, LastName,name From Contact where AccountId =: accId order by name DESC];
    if(listContact.size() > 0){
        listWrapper1 = new List<ContactWrapper>();
            for(Contact c : listContact){
                listWrapper1.add(new ContactWrapper(c));
        }
   }

List<Opportunity> listOpp = [select id,name,closeDate from Opportunity where AccountId =: accId order by closeDate ASC];
    if(listOpp.size() > 0){
        listWrapper2 = new List<OpportunityWrapper>();
            for(Opportunity o : listOpp){
                listWrapper2.add(new OpportunityWrapper(o));
       }
   }
}
public pagereference assignNotes(){
system.debug('******noteID******'+noteID);
Note no = [select id,title,body,parentId from Note where id=:noteID limit 1];
system.debug('********no******'+no);

/*selectedNotes = new List<Note>();
system.debug('*********listWrapper ********'+listWrapper);
for(WrapperClass wrapAccountObj : listWrapper ) {
     if(wrapAccountObj.checkBool == true) {
        selectedNotes.add(wrapAccountObj.acct);
        system.debug('*********selectedNotes********'+selectedNotes);
     }  
}  */

selectedContacts = new List<Contact>();
 for(ContactWrapper wrapContactObj : listWrapper1){
     if(wrapContactObj.checkBool == true){
         Note nt = new Note();
         nt.Title = no.title;
         nt.Body = no.body;
         nt.ParentId = wrapContactObj.cons.Id;
         contactNote.add(nt);
         //selectedContacts.add(wrapContactObj.cons);
         //system.debug('*********selectedContacts******'+selectedContacts);
       }
    }
insert contactNote;
    
selectedOpps = new List<Opportunity>();
  for(OpportunityWrapper wrapOppObj : listWrapper2){
      if(wrapOppObj.checkBool == true){
          Note nt = new Note();
          nt.Title = no.title;
          nt.Body = no.Body;
          nt.parentId = wrapOppObj.ops.Id;
          oppNote.add(nt);
          //selectedOpps.add(wrapOppObj.ops);
         // system.debug('******selectedOpps*********'+selectedOpps);
     }
  }
insert oppNote;
  PageReference pg = new PageReference('/apex/DisplayAccountNotes?id='+accId);  //Redirect on the same page
       pg.setRedirect(true);
       return pg; 
}
public class WrapperClass{
   public Boolean checkBool {get;set;}
   public Note acct {get;set;}
   public WrapperClass(Note acct){
        this.acct = acct;
        checkBool = false;
       }        
    }
public class ContactWrapper{
   public Boolean checkBool {get;set;}
   public Contact cons {get;set;}
   public ContactWrapper(Contact cons){
        this.cons = cons;
        checkBool = false;
        }    
     }
public Class OpportunityWrapper{
   public Boolean checkBool {get;set;}
   public Opportunity ops {get;set;}
   public OpportunityWrapper(Opportunity ops){
        this.ops = ops;
        checkBool = false;
        }   
     }
}




Test Class-----------------------------------------------------------------------

@isTest
public class DisplayNotesNewTestClass {

  static testmethod void test1(){

    PageReference pageRef = Page.DisplayAccountNotes;
    Test.setCurrentPage(pageRef);
    Account acc = new Account(name='vivek112');
    insert acc;
    DisplayNotesNew obj = new DisplayNotesNew(new ApexPages.StandardController(acc));
    ApexPages.CurrentPage().getparameters().put('id',acc.id);
     
    Contact con = new Contact(FirstName='vivek112', AccountId = acc.Id);
    List<Contact> lstcon = new List<Contact>();
    lstcon.add(con);   
        
    Opportunity opp = new opportunity(name = 'a',stageName = 'Closed Won',closedate = date.today(),Renewal_Date__c = date.today(),AccountId = acc.Id);
    List<Opportunity> lstopp = new List<Opportunity>();
    lstopp.add(opp);  
    system.debug('lstopp'+lstopp);
      
 	Note note = new Note(parentid = acc.Id,title='test',body= 'hi');
    List<note> nList = new List<Note>();
    nList.add(note);
    
    boolean RadioValue = true;
    Id noteID = note.Id;
    system.debug('noteID--------'+noteID);
 
    DisplayNotesNew objCustom = new DisplayNotesNew ();
    DisplayNotesNew.ContactWrapper objwrap = new DisplayNotesNew.ContactWrapper(con);
    DisplayNotesNew.OpportunityWrapper objwrap1 = new  DisplayNotesNew.OpportunityWrapper(opp); 
    DisplayNotesNew.WrapperClass objwrap2 = new DisplayNotesNew.WrapperClass(note);
     
 
    
    objCustom.assignNoteId();
    objCustom.assignNotes();
   
    }
}
I am getting an error in noteID and it is throwing error 'List has no rows for assignment'.Please help.

-Amita
 
I have a VF page from where i create opportunity. I want that whenever the opportunity is created, it should get populated in the standard look up field. How can i achieve that ? Please help
 
Hi,

I have a requirement where i want to insert selected notes to the selected contacts & opportunities using wrapper class.
How  can i achieve this. Here is my code:
Apex class------

public class DisplayNotesNew{

public List<WrapperClass> listWrapper {get;set;}
public List<ContactWrapper> listWrapper1 {get;set;}
public List<OpportunityWrapper> listWrapper2 {get;set;}
public Id accId;
Public Account acc;
public List<Note> selectedNotes{get;set;}
public List<Contact> selectedContacts{get;set;}
public List<opportunity> selectedOpps{get;set;}
    
public DisplayNotesNew(ApexPages.StandardController Controller) {
accId = ApexPages.currentPage().getParameters().get('id');
system.debug('********************'+accId);

List<Note> listAcct = [SELECT Id,Title, Body,Parent.Id FROM Note where Parent.Id =: accId];
  if(listAcct.size() > 0) {
    listWrapper = new List<WrapperClass>();
       for(Note a : listAcct) {
          listWrapper.add(new WrapperClass(a));
        }
    }
List<Contact> listContact = [Select Id, FirstName, LastName,name From Contact where AccountId =: accId];
    if(listContact.size() > 0){
        listWrapper1 = new List<ContactWrapper>();
            for(Contact c : listContact){
                listWrapper1.add(new ContactWrapper(c));
    }
}

List<Opportunity> listOpp = [select id,name from Opportunity where AccountId =: accId];
    if(listOpp.size() > 0){
        listWrapper2 = new List<OpportunityWrapper>();
            for(Opportunity o : listOpp){
                listWrapper2.add(new OpportunityWrapper(o));
    }
}
}
public pagereference assignNotes(){
selectedNotes = new List<Note>();
  for(WrapperClass wrapAccountObj : listWrapper ) {
     if(wrapAccountObj.checkBool == true) {
        selectedNotes.add(wrapAccountObj.acct);
        system.debug('*********selectedNotes********'+selectedNotes);
      }         
   }

selectedContacts = new List<Contact>();
 for(ContactWrapper wrapContactObj : listWrapper1){
     if(wrapContactObj.checkBool == true){
         selectedContacts.add(wrapContactObj.cons);
         system.debug('*********selectedContacts******'+selectedContacts);
    }
 }
selectedOpps = new List<Opportunity>();
  for(OpportunityWrapper wrapOppObj : listWrapper2){
      if(wrapOppObj.checkBool == true){
          selectedOpps.add(wrapOppObj.ops);
          system.debug('******selectedOpps*********'+selectedOpps);
     }
  }
   
return null;
}


public class WrapperClass{
   public Boolean checkBool {get;set;}
   public Note acct {get;set;}
   public WrapperClass(Note acct) {
        this.acct = acct;
        }        
    }
public class ContactWrapper{
   public Boolean checkBool {get;set;}
   public Contact cons {get;set;}
   public ContactWrapper(Contact cons) {
        this.cons = cons;
        }    

}
public Class OpportunityWrapper{
   public Boolean checkBool {get;set;}
   public Opportunity ops {get;set;}
   public OpportunityWrapper(Opportunity ops) {
        this.ops = ops;
        }   

}
}


VF Page-----------------------

<apex:page standardController="Account" extensions="DisplayNotesNew" tabStyle="Account">
<apex:form >

<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:pageMessages />
<apex:pageBlock id="pg">
<apex:pageblockButtons >
<apex:commandButton value="Assign Notes"/>
</apex:pageblockButtons>

<apex:pageBlockSection title="ACCOUNT NOTES">
<apex:pageBlockTable value="{!listWrapper}" var="a">
<apex:column >
<!-- <apex:facet name="header">
<apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
</apex:facet> -->
<input type="radio" name="selection" value="{!a.checkBool}"/> 
<!-- <apex:inputCheckbox value="{!a.checkBool}" id="inputId"/> -->
</apex:column>
<apex:column value="{!a.acct.Title}"/>
<apex:column value="{!a.acct.Body}"/>  
</apex:pageBlockTable>
</apex:pageBlockSection>
<br/>
<br/>
<apex:pageBlockSection TITle="CONTACTS & OPPORTUNITIES">
<apex:pageblockTable value="{!listWrapper1}" var="a">
<apex:column >
<apex:inputCheckbox value="{!a.checkBool}" id="inputId"/>
</apex:column>
<apex:column value="{!a.cons.name}" headerValue="Related Contacts"/>
</apex:pageblockTable>
<Apex:pageblockTable value="{!listWrapper2}" var="a">
<apex:column >
<apex:inputCheckbox value="{!a.checkBool}" id="inputId"/>
</apex:column>
<apex:column value="{!a.ops.name}" headerValue="Related Opportunities"/>
</Apex:pageblockTable>
</apex:pageBlockSection>
     
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks,
Amita
 
Hi all,
 I have below code. My VF page records are not getting saved in the database. I have used standard save.
Can you tell me where i am going wrong>?
class------------------------------------------------

public with sharing class createOpportunityClass{

public Lead lead {get;set;}
public List<Existing_Policies__c> exLst{get;set;}
public List<Existing_Policies__c> eList{get;set;}
public Id lId;
public String parameter {get;set;}

public createOpportunityClass(ApexPages.StandardSetController controller){
   lId = ApexPages.CurrentPage().getParameters().get('id');
   exLst = controller.getRecords();
   system.debug('***************exLst**********'+exLst);
   eList = [select Lead__r.Company, Lead__r.Name, Chose_not_to_take_cover__c, Cover_not_applicable__c, 
           Current_Broker__c, Current_Insurer__c, Insured_Elsewhere__c, Insured_via_Gauntlet__c,Renewal_Date__c,
            Lead__c, Notes_Comments__c, Policy_Type__c, Product_Cover_Type__c, Quotation_Requested__c from Existing_Policies__c where Lead__c =: lId];                               
}

public pagereference createOpportunity(){

Existing_Policies__c policy = [select Lead__r.Company, Lead__r.Name, Chose_not_to_take_cover__c, Cover_not_applicable__c, Current_Broker__c, 
                                 Current_Insurer__c, Insured_Elsewhere__c, Insured_via_Gauntlet__c,
                                 Lead__c, Notes_Comments__c, Policy_Type__c,Renewal_Date__c, Product_Cover_Type__c, Quotation_Requested__c from Existing_Policies__c where id =: parameter];                               
 
for(Existing_Policies__c ex : eList){
    if(ex.id == parameter){
        Opportunity o = new Opportunity();
        Account a = [select Id from Account where Name =: policy.Lead__r.Company limit 1];
        o.AccountId = a.Id;
        
        o.name = policy.Lead__r.Company + ' - ' + policy.Product_Cover_Type__c;
        o.Stagename = 'Pre-Qualification';
        o.CloseDate = date.Today();
        o.Chose_not_to_take_cover__c  = policy.Chose_not_to_take_cover__c;
        o.Cover_not_applicable__c  = policy.Cover_not_applicable__c ;
        o.Policy_Type3__c = policy.Policy_Type__c;
        o.Insured_via_Gauntlet__c  = policy.Insured_via_Gauntlet__c;
        o.Insured_Elsewhere__c = policy.Insured_Elsewhere__c;
        o.Notes_Comments__c = policy.Notes_Comments__c;
        o.Current_Broker__c = policy.Current_Broker__c;
        o.Product_Cover_Type__c = policy.Product_Cover_Type__c;
        o.Quotation_Requested__c = policy.Quotation_Requested__c ;
        o.Current_Insurer__c = policy.Current_Insurer__c;
        o.Renewal_Date__c = policy.Renewal_Date__c;
        insert o;
        PageReference pageRef = new PageReference('/' + o.id); 
        pageRef.setRedirect(true);
        return pageRef;
    } 
}    
return null;
}

}


PAGE---------------------------------------------------------

<apex:page standardController="Existing_Policies__c" recordSetVar="Existing_Policies__c"
tabStyle="Existing_Policies__c" sidebar="false" extensions="createOpportunityClass">

<apex:form >
<apex:pageBlock >
<apex:pageMessages />
    
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!eList}" var="a">

<apex:column value="{!a.Product_Cover_Type__c}"/>
<apex:column headerValue="Policy Type">
<apex:inputfield value="{!a.Policy_Type__c}"/>
</apex:column>

<apex:column headerValue="Insured via Gauntlet">
      <apex:inputfield value="{!a.Insured_via_Gauntlet__c}"/>
  </apex:column>
  <apex:column headerValue="Insured Elsewhere">
      <apex:inputfield value="{!a.Insured_Elsewhere__c}"/>
  </apex:column>
  <apex:column headerValue="Current Broker">
      <apex:inputfield value="{!a.Current_Broker__c}"/>
  </apex:column>
  <apex:column headerValue="Current Insurer">
      <apex:inputfield value="{!a.Current_Insurer__c}"/>
  </apex:column>
  <apex:column headerValue="Renewal Date">
      <apex:inputfield value="{!a.Renewal_Date__c}"/>
  </apex:column>
  <apex:column headerValue="Quotation Requested">
      <apex:inputfield value="{!a.Quotation_Requested__c}"/>
  </apex:column>
  <apex:column headerValue="Chose Not to take Cover">
      <apex:inputfield value="{!a.Chose_not_to_take_cover__c}"/>
  </apex:column>
  <apex:column headerValue="Cover Not Applicable" width="10PX">
      <apex:inputfield value="{!a.Cover_not_applicable__c }"/>
  </apex:column>
  <apex:column headerValue="Notes & Comments">
      <apex:inputfield value="{!a.Notes_Comments__c}"/>
  </apex:column>
  
  <apex:column style="width:150px" headerValue="Create Opportunity">
  <!--<apex:commandButton action="{!createOpportunity}" value="Create Opportunity"/>-->
      <apex:commandLink action="{!createOpportunity}" styleClass="btn" value="Create">
         <apex:param name="test" assignTo="{!parameter}" value="{!a.id}"/>
      </apex:commandLink> 
  </apex:column>
  
</apex:pageBlockTable>
<!-- <apex:panelGrid columns="2">
<apex:commandLink action="{!previous}">Previous</apex:commandlink>
<apex:commandLink action="{!next}">Next</apex:commandlink>
</apex:panelGrid>  -->

</apex:pageBlock>
</apex:form>
</apex:page>
Please help me out with what is wrong in my code.

Thanks,
Amita Tatar
 
Hi all,

I have lead object and its child object.I want to create new opportunity from each record in the related list of child object. How can i do that ?
While creation of opportunity, i want to check if Account for that lead exists or not,else create it first and then create opportunity and insert data from the child object.How can i do so? I have started writing below trigger for the same.

Thanks,
Amita Tatar
trigger CreateOpportunity on Existing_Policies__c (before update) {

 public List<Opportunity> oppList= new List<Opportunity>();
 
    for(Existing_Policies__c e: trigger.new){
       
            Opportunity o = new Opportunity(); 
            o.Name = e.Lead__c;
            o.AccountId = e.Lead__r.Company;
            o.CloseDate = Date.Today();
            o.Loss_Reason__c = 'Closed Lost';
            o.StageName= 'Closed Won';
            o.Insured_via_Gauntlet__c = e.Insured_via_Gauntlet__c;
            o.Cover_not_applicable__c = e.Cover_not_applicable__c;
            o.Chose_not_to_take_cover__c = e.Chose_not_to_take_cover__c;
            o.Policy_Type3__c = e.Policy_type__c; 
            o.Insured_Elsewhere__c = e.Insured_Elsewhere__c;
            o.Notes_Comments__c = e.Notes_Comments__c;
            o.Current_Broker__c = e.Current_Broker__c;
            o.Current_Insurer__c = e.Current_Insurer__c;
            o.Quotation_Requested__c = e.Quotation_Requested__c;
            o.Renewal_Date__c = e.Renewal_Date__c;
            oppList.add(o);  
    }
      insert oppList;   
    
}

 
Hi all,

I have a requirement where i want to update my account name field along with its parent account name. I want to display parent account name in the bracket of the child account name. I wrote below trigger
. It Is getting updated with id of parent account and i want name. Please tell me whats wrong
trigger UpdateAccount on Account (before insert) {


for(Account a:Trigger.New){

if( a.Parent2__c != null){
   
  a.ParentId = a.Parent2__c;
  
  string parentName = a.Parent.Name;
  a.Name = a.Name +'(' + parentName + ')'; 
  system.debug('*******************'+parentName );
  

}
}



}
Thanks,
Amita
 
Hi all,

I have a requirement where i want to save the fieldset displayed fields and their values in an object on save functionality.
But this can be like multiple records. I will post my code here. Please help me for save part.
Apex class:

public with sharing class SurveyClass{

Public Account acc{get;set;}
Public List<Proposal_Form__c>pfc;
Public Proposal_Form__c pfc1 {get;set;}
public ProposalFields__c pf {get;set;}
public List<String> fieldSet {get;set;}
public List<string> fieldnames{get;set;} 
Public ID rid;
public string msg {get;set;}
public Responses__c r {get;set;}
public Response_Details__c rd{get;set;}
public Id responseId;
private ApexPages.StandardController standardController;
    
public SurveyClass(ApexPages.StandardController controller) {
    this.standardController = standardController;
    rid = ApexPages.currentPage().getParameters().get('id');
    system.debug('*****rId****'+rid);
    acc = new Account();
    pfc1 = new Proposal_Form__c();
  }

public void Selected(){
    system.debug(pfc1.Service_Family__c +'------------'+pfc1.Sub_Service_Category__c);
    
   /* try{
        pfc = [SELECT Fields_Associated__c FROM Proposal_Form__c where Service_Family__c =: pfc1.Service_Family__c and Sub_Service_Category__c =: pfc1.Sub_Service_Category__c LIMIT 1];
        
    } catch(NullPointerException ex){
        
          Apexpages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.FATAL,'No such combination exists'+ex));
      
    } */
  
    pfc = new List<Proposal_Form__c>();
    pfc = [SELECT Fields_Associated__c FROM Proposal_Form__c where Service_Family__c =: pfc1.Service_Family__c and Sub_Service_Category__c =: pfc1.Sub_Service_Category__c LIMIT 1];

    if(!pfc.isEmpty())
    {
    fieldSet = new List<String>();
    List<String> fields = new List<String>();
     
    if(pfc[0].Fields_Associated__c != null && pfc[0].Fields_Associated__c != ''){
        fields = String.valueof(pfc[0].Fields_Associated__c).split(',');
        system.debug('*********Fields******'+fields);
    }
    else{
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'NO QUESTION SET FOUND'));
    }
   
    Map<String,String> labelMap = new Map<String,String>();
    labelMap = getLabel.retLabelMap('ProposalFields__c');
    system.debug(labelMap);
    system.debug(labelMap);
    for(String s : fields){
        fieldSet.add(labelMap.get(s));
        system.debug('********fieldset*******'+fieldSet);
    }    
  }
  else {
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'NO QUESTION SET FOUND'));
   }
 }  
 
  /*public List<Schema.FieldSetMember> getFields() {
        return SObjectType.ProposalFields__c.FieldSets.Red_Items.getFields();
    }*/
 
 
/* This method will store response of survey*/
public PageReference submitForm(){
    system.debug('Inside submitForm');
    acc = [SELECT Id, Name FROM Account where id =:rid];
    system.debug('*******acc****'+acc);
    Responses__c response = new Responses__c();
    response.Account__c = acc.Id;
    response.Service_Family__c = pfc1.Service_Family__c;
    response.Sub_Service_Category__c = pfc1.Sub_Service_Category__c;
    try{
        insert response;
        
        List<Response_Details__c> responseDetailsList = new List<Response_Details__c>();
        for(String s : fieldset){
             Response_Details__c rdetail = new Response_Details__c();
             //rdetail.Response__c = responseId;
             //fieldnames = new List<String>();
             //fieldnames.add(s.getFieldPath());  
             //rdetail.Question__c = fieldnames;
             responseDetailsList.add(rdetail);
        }
        insert responseDetailsList;
        PageReference pg = new PageReference('/'+response.id);     
        return pg;
    }
    catch(dmlexception e){
        apexpages.addmessages(e);
        return null;
}
}

/*public void getResponseDetails(Id responseId){

List<Response_Details__c> rDetail = new List<Response_Details__c>();
Response_Details__c responseDetail = new Response_Details__c();
responseDetail.Response__c = responseId;
for (Integer f=0; f< fieldSet.size();f++){
    responseDetail.Question__c = fieldSet[f];
    system.debug( responseDetail.Question__c);
}
rDetail.add(responseDetail);
insert rDetail;
} */ 

}


PagE:



<apex:page standardController="Account" extensions="SurveyClass" sidebar="false" showHeader="false" tabStyle="Account">
<apex:form >
<apex:pageMessages rendered="true" id="errMsg" showDetail="false"/>
<apex:pageBlock title="Customer Survey Form"> 

<apex:pageBlockSection title="Service Requirements" >
<apex:inputField value="{!pfc1.Service_Family__c}"/>
<apex:pageblocksectionItem >
<apex:outputLabel value="Sub Service Category"/>
<apex:outputPanel >
        
<apex:inputfield value="{!pfc1.Sub_Service_Category__c}">
<apex:actionSupport event="onchange" action="{!Selected}" rerender="fieldst,errMsg" />
</apex:inputField>
       
</apex:outputPanel>
</apex:pageblocksectionItem>
</apex:pageBlockSection> 

<apex:pageblockSection title="Question Set" id="fieldst">
<apex:repeat value="{!fieldSet}" var="f">
<apex:inputField value="{!pf[f]}"/> 
</apex:repeat>
</apex:pageblockSection>

<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Submit" action="{!submitForm}"/>
<apex:commandButton value="Edit" action="{!edit}"/>
</apex:pageBlockButtons>

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

I want to save the particular fieldset fields and user entered values from vf page to response detail object in a question and answer field.
Please help.

Amita Tatar
Hi all,

I have a VF page survey form for account which has certain questions. Each account can have multiple survey forms as per services availed.
I want to save these survey forms in a child object of Account.
How i should achieve this part?
Here is my code.
Class:


public with sharing class SurveyClass{

Public Account acc{get;set;}
Public List<Proposal_Form__c>pfc;
Public Proposal_Form__c pfc1 {get;set;}
public ProposalFields__c pf {get;set;}
public List<String> fieldSet {get;set;}
Public ID rid;
public string msg {get;set;}
private ApexPages.StandardController standardController;
    
public SurveyClass(ApexPages.StandardController controller) {
    this.standardController = standardController;
    pfc1 = new Proposal_Form__c();
  }

public void Selected(){
    system.debug(pfc1.Service_Family__c +'------------'+pfc1.Sub_Service_Category__c);
    
   /* try{
        pfc = [SELECT Fields_Associated__c FROM Proposal_Form__c where Service_Family__c =: pfc1.Service_Family__c and Sub_Service_Category__c =: pfc1.Sub_Service_Category__c LIMIT 1];
        
    } catch(NullPointerException ex){
        
          Apexpages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.FATAL,'No such combination exists'+ex));
      
    } */
  
    pfc = new List<Proposal_Form__c>();
    pfc = [SELECT Fields_Associated__c FROM Proposal_Form__c where Service_Family__c =: pfc1.Service_Family__c and Sub_Service_Category__c =: pfc1.Sub_Service_Category__c LIMIT 1];

    if(!pfc.isEmpty())
    {
    fieldSet = new List<String>();
    List<String> fields = new List<String>();
     
    if(pfc[0].Fields_Associated__c != null && pfc[0].Fields_Associated__c != ''){
        fields = String.valueof(pfc[0].Fields_Associated__c).split(',');
        system.debug('*********Fields******'+fields);
    }
    else{
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'NO QUESTION SET FOUND'));
    }
   
    Map<String,String> labelMap = new Map<String,String>();
    labelMap = getLabel.retLabelMap('ProposalFields__c');
    system.debug(labelMap);
    system.debug(labelMap);
    for(String s : fields){
        fieldSet.add(labelMap.get(s));
        system.debug('********fieldset*******'+fieldSet);
    }    
  }
  else {
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'NO QUESTION SET FOUND'));
   }
 }  
}


VF Page:;;


<apex:page standardController="Account" extensions="SurveyClass" sidebar="false" showHeader="false" tabStyle="Account">
<apex:form >
<apex:pageMessages rendered="true" id="errMsg" showDetail="false"/>
<apex:pageBlock title="Customer Survey Form"> 

<apex:pageBlockSection title="Service Requirements" >
<apex:inputField value="{!pfc1.Service_Family__c}"/>
 <apex:pageblocksectionItem >
    <apex:outputLabel value="Sub Service Category"/>
    <apex:outputPanel >
        
            <apex:inputfield value="{!pfc1.Sub_Service_Category__c}">
                <apex:actionSupport event="onchange" action="{!Selected}" rerender="fieldst,errMsg" />
             </apex:inputField>
       
    </apex:outputPanel>
</apex:pageblocksectionItem>
</apex:pageBlockSection> 

<apex:pageblockSection title="Question Set" id="fieldst">
    <apex:repeat value="{!fieldSet}" var="f">
      <apex:inputField value="{!pf[f]}"/> 
    </apex:repeat>
</apex:pageblockSection>

<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Submit" action="{!save}"/>
<apex:commandButton value="Edit" action="{!edit}"/>
</apex:pageBlockButtons>

</apex:pageBlock>
</apex:form> 
</apex:page>
Thanks,
Amita
 
Hi all,

I have below code. I want to show error on VF page when particular condition not met and records not found.I have added my code in try catch block and added apex:messages as well.
Please suggest me what is wrong.
The error should be displayed when combination of service family and sub service category is not found in database.
 
Class:


public with sharing class SurveyClass{

Public Account acc{get;set;}
Public Proposal_Form__c pfc;
Public Proposal_Form__c pfc1 {get;set;}
public ProposalFields__c pf {get;set;}
public List<String> fieldSet {get;set;}
Public ID rid;
private ApexPages.StandardController standardController;
    
public SurveyClass(ApexPages.StandardController controller) {
    this.standardController = standardController;
    pfc1 = new Proposal_Form__c();
  }

public void Selected(){
    system.debug(pfc1.Service_Family__c +'------------'+pfc1.Sub_Service_Category__c);
    
    try{
        pfc = [SELECT Fields_Associated__c FROM Proposal_Form__c where Service_Family__c =: pfc1.Service_Family__c and Sub_Service_Category__c =: pfc1.Sub_Service_Category__c LIMIT 1];
        
    } catch(Exception ex){
     ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No such combination exists');
     ApexPages.addMessage(myMsg);
      
    }
     
    fieldSet = new List<String>();
    List<String> fields = new List<String>();
    if(pfc.Fields_Associated__c != null && pfc.Fields_Associated__c != ''){
        fields = String.valueof(pfc.Fields_Associated__c).split(',');
        system.debug('*********Fields******'+fields);
    }
    else{
        Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,''+'No questions to Display"'));
    
    }
    Map<String,String> labelMap = new Map<String,String>();
    labelMap = getLabel.retLabelMap('ProposalFields__c');
    system.debug(labelMap);
    system.debug(labelMap);
    for(String s : fields){
        fieldSet.add(labelMap.get(s));
        system.debug('********fieldset*******'+fieldSet);
    }
    
}
}


VF Page:;


<apex:page standardController="Account" extensions="SurveyClass" sidebar="false" showHeader="false" tabStyle="Account">

<apex:form >
<apex:pageMessages rendered="true"/>
<apex:pageBlock title="Client Survey Form"> 
<apex:pageBlockSection title="Service Requirements" >

<apex:inputField value="{!pfc1.Service_Family__c}"/>
 
<apex:pageblocksectionItem >
    <apex:outputLabel value="Sub Service Category"/>
    <apex:outputPanel >
        
            <apex:inputfield value="{!pfc1.Sub_Service_Category__c}">
                <apex:actionSupport event="onchange" action="{!Selected}" rerender="fieldst" />
                <apex:pageMessages rendered="true"/>
            </apex:inputField>
       
    </apex:outputPanel>
</apex:pageblocksectionItem>
</apex:pageBlockSection> 

<apex:pageblockSection title="Question Set" id="fieldst">
    <apex:repeat value="{!fieldSet}" var="f">
      <apex:inputField value="{!pf[f]}"/> 
    </apex:repeat>
</apex:pageblockSection>

<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Submit" action="{!Save}"/>
</apex:pageBlockButtons>



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


 
Hi all,

I have following code: Scenario is that i have two objects Account and Proposal Form with look up relationship..
I have some standard forms already stored in Proposal Form object which has service family and service category drop down.

On Account i want to rerender field from proposal form on matching of certain conditions,but it is not working. can you please help me out here.
Class::

public with sharing class SurveyClass{

Public Account acc{get;set;}
Public Proposal_Form__c pfc {get;set;}
Public ID rid;
private ApexPages.StandardController standardController;
    
public SurveyClass(ApexPages.StandardController controller) {
    this.standardController = standardController;
    acc = (Account)controller.getRecord();
  }

public void Selected(){
//acc = [SELECT Id, Name, Proposal_Form__r.Name, Proposal_Form__r.Fields_Associated__c, Proposal_Form__r.Service_Family__c, Proposal_Form__r.Sub_Service_Category__c FROM Account ];
pfc = [SELECT Fields_Associated__c FROM Proposal_Form__c where Service_Family__c =: acc.Proposal_Form__r.Service_Family__c and Sub_Service_Category__c =: acc.Proposal_Form__r.Sub_Service_Category__c];

}
}


VF Page:::


<apex:page standardController="Account" extensions="SurveyClass" sidebar="false" showHeader="false" tabStyle="Account">
<apex:form >
<apex:pageBlock title="Client Survey Form"> 
<apex:pageBlockSection title="Service Requirements" >
<apex:inputField value="{!acc.Proposal_Form__r.Service_Family__c}"/>
<apex:inputfield value="{!acc.Proposal_Form__r.Sub_Service_Category__c}"/> 
</apex:pageBlockSection> 

<apex:outputPanel id="form">
<apex:pageblockSection title="Question Set" >
<apex:inputField value="{!acc.Proposal_Form__r.Fields_Associated__c}">
<apex:actionSupport event="onchange" action="{!Selected}" oncomplete="alert('Hello');" rerender="form"  rendered="true"/>
</apex:inputField>
</apex:pageblockSection>
</apex:outputPanel>

</apex:pageBlock>
</apex:form> 
</apex:page>
Please help me out here.

Thanks,
Amita
 
Hi all,

I have a Map in which i have Sobject fields and labels and i am adding these labels to my wraper list and showing it on VF page.
I want to show only the custom field labels here. So i am trying to add condition while adding the labels in wrapper list...but cannot do it.
Can you help? Here is my code:
APEX class::



public class getLabel{

Public Proposal_Form__c pfc = new Proposal_Form__c();
public List<WrapperClass> listWrapper {get;set;}
public Map<String,String> labelMap;
public String resultString {get;set;} 
public ApexPages.StandardController controller; 

public getLabel(ApexPages.StandardController Controller) {
    pfc = (Proposal_Form__c)Controller.getRecord(); 
    this.controller = Controller;  
    listWrapper = new List<WrapperClass>();
    labelMap = new Map<String,String>();
    labelMap = retLabelMap('ProposalFields__c');
    system.debug('******LabelMap***'+labelMap);
        for(String s : labelMap.values()){
            listWrapper.add(new WrapperClass(s,false));
        }
       
   }

public class WrapperClass {  
    public Boolean checkBool {get;set;}
    public String fieldNme{get;set;}  
    public WrapperClass(String prop,Boolean checkBool ){  
        this.fieldNme = prop;  
        this.checkBool = checkBool ;  
    }  
}

public Static Map<String,String> retLabelMap(String type){
    Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe();
    Schema.SObjectType s= m.get(type);
    Map<String, Schema.SObjectField> fieldMap = s.getDescribe().fields.getMap();
    Map<String,String> aMap = new Map<String,String>();
    for (String fieldName: fieldMap.keySet()) {
        aMap.put(fieldName,fieldMap.get(fieldName).getDescribe().getLabel());
    }
    return aMap;
}

public PageReference saveCheckboxValue(){
   if(listWrapper!=null && listWrapper.size()>0){
        for(WrapperClass w : listWrapper){
            if(w.checkBool == true){
              
                   if(resultString!=null){
                        resultString = resultString + '\n'+ w.fieldNme;
                   }
                   else{
                        resultString = w.fieldNme;
                   }
            }
          }
        }
     
     pfc.Fields_Associated__c = resultString; 
     try
     {
         insert pfc;
         PageReference pg = new PageReference('/'+pfc.id);
         return pg;
     }
     catch(dmlexception e)
     {
           apexpages.addmessages(e);
           return null;
     }

}
}
I am trying to add some if condition in the bold part of my code.

Thanks,
Amita
 
Hi all,

I have custom save method in my code and two inputfields.
This save functionality is working,but the two inputfields are not getting saved.
I will paste my code here. Please help.Its urgent.

Thanks,
Amita Tatar
class::


public class getLabel{

Proposal_Form__c pfc;
public List<WrapperClass> listWrapper {get;set;}
public Map<String,String> labelMap;
public String resultString {get;set;} 
private ApexPages.StandardController std;

public getLabel(ApexPages.StandardController controller) {
    
    //std = controller;
    pfc = (Proposal_Form__c)controller.getRecord();
    listWrapper = new List<WrapperClass>();
    labelMap = new Map<String,String>();
    labelMap = retLabelMap('ProposalFields__c');
    for(String s : labelMap.values()){
        listWrapper.add(new WrapperClass(s,false));
    }
   
}

public class WrapperClass {  
    public Boolean checkBool {get;set;}
    public String fieldNme{get;set;}  
    public WrapperClass(String prop,Boolean checkBool ){  
        this.fieldNme = prop;  
        this.checkBool = checkBool ;  
    }  
}

public Static Map<String,String> retLabelMap(String type){
    Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe();
    Schema.SObjectType s= m.get(type);
    Map<String, Schema.SObjectField> fieldMap = s.getDescribe().fields.getMap();
    Map<String,String> aMap = new Map<String,String>();
    for (String fieldName: fieldMap.keySet()) {
        aMap.put(fieldName,fieldMap.get(fieldName).getDescribe().getLabel());
    }

    return aMap;
}

public PageReference saveCheckboxValue(){
    List<String> selectedRec = new List<String>();
    if(listWrapper!=null && listWrapper.size()>0){
        for(WrapperClass w : listWrapper){
            if(w.checkBool == true){
              // selectedRec.add(w.fieldNme);
               system.debug('**********'+ selectedRec.add(w.fieldNme));
               resultString = resultString + '  '+ w.fieldNme;
               
        }
       }
    }
     Proposal_Form__c pf = new Proposal_Form__c();
    
     pf.Fields_Associated__c = resultString; 
     insert pf;
   
     PageReference pg = new PageReference('/'+pf.id);
     return pg;
       
     }
 
}


VF



<apex:page showHeader="false" sidebar="false" standardController="Proposal_Form__c" extensions="getLabel">
<apex:form >
<style>
.panelWrapper .mainTitle {
   text-align :center;
    
}
</style>
<apex:outputPanel styleClass="panelWrapper" layout="block">
<apex:pageBlock title="Proposal Form">
<apex:pageBlockSection title="Service Requirements">
<apex:inputField value="{!Proposal_Form__c.Service_Family__c}"/>
<apex:inputField value="{!Proposal_Form__c.Service_Type__c}"/>
<apex:inputField value="{!Proposal_Form__c.Sub_Service_Category__c}"/>

</apex:pageBlockSection>

<apex:pageBlockButtons location="Bottom">
<apex:commandButton value="Save" action="{!saveCheckboxValue}"/>
</apex:pageBlockButtons>

<apex:pageBlockSection title="Available fields">
<apex:repeat var="lab" value="{!listWrapper}">
<apex:pageblockSectionItem >
<apex:outputlabel value="{!lab.fieldNme}"/>
<apex:inputCheckbox value="{!lab.checkBool}"/>
</apex:pageblockSectionItem> 
</apex:repeat>

</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>

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

 
Hi all,

I have a VF page where i have displayed sObject labels dynamically on this VF page. These field labels are associated with checkboxes.
I want that whichever checkboxes are selected , there labels should get stored in a text area field at the backend.
I will paste my code below. Please help me for the same.
APEX CLASS::::

public class getLabel{

public List<WrapperClass> listWrapper {get;set;}
public Map<String,String> labelMap;
public String resultString {get;set;}  

public getLabel(ApexPages.StandardController controller) {
    listWrapper = new List<WrapperClass>();
    labelMap = new Map<String,String>();
    labelMap = retLabelMap('ProposalFields__c');
    for(String s : labelMap.values()){
        listWrapper.add(new WrapperClass(s,false));
    }
}

public class WrapperClass {  
    public Boolean checkBool {get;set;}
    public String fieldNme{get;set;}  
    public WrapperClass(String prop,Boolean checkBool ){  
        this.fieldNme = prop;  
        this.checkBool = checkBool ;  
    }  
}

public Static Map<String,String> retLabelMap(String type){
    Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe();
    Schema.SObjectType s= m.get(type);
    Map<String, Schema.SObjectField> fieldMap = s.getDescribe().fields.getMap();
    Map<String,String> aMap = new Map<String,String>();
    for (String fieldName: fieldMap.keySet()) {
        aMap.put(fieldName,fieldMap.get(fieldName).getDescribe().getLabel());
    }

    return aMap;
}

public void saveCheckboxValue(){
     Proposal_Form__c p = new Proposal_Form__c();
     p.Fields_Associated__c = resultString;
     insert p;
 }
 
public PageReference getSelected(){
   return null;
}



}



VF PAGE:


<apex:page showHeader="false" sidebar="false" standardController="Proposal_Form__c" extensions="getLabel">
<apex:form >
<style>
.panelWrapper .mainTitle {
   text-align :center;
    
}
</style>
<apex:outputPanel styleClass="panelWrapper" layout="block">
<apex:pageBlock title="Proposal Form">
<apex:pageBlockSection title="Service Requirements">
<apex:inputField value="{!Proposal_Form__c.Service_Family__c}"/>
<apex:inputfield value="{!Proposal_Form__c.Service_Type__c}"/>
<apex:inputField value="{!Proposal_Form__c.Sub_Service_Category__c}"/>
</apex:pageBlockSection>

<apex:pageBlockButtons location="Bottom">
<apex:commandButton value="Save" action="{!Save}"/>
</apex:pageBlockButtons>

<apex:pageBlockSection title="Available fields">
<apex:repeat var="lab" value="{!listWrapper}">
    <apex:pageblockSectionItem >
        <apex:outputlabel value="{!lab.fieldNme}"/>
        <apex:inputCheckbox value="{!lab.checkBool}"/>
    </apex:pageblockSectionItem> 
</apex:repeat>

</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>

</apex:form> 
</apex:page>
Thanks,
Amita Tatar
 
Hi,

I have a requirement where i want to save the labels of selected checkboxes in a textarea field.
I am pasting my code below. Please help me for the same
My Class:

public class getLabel{

public List<sObjectWrapper> wrappers{get;set;}  
public List<String> AllLabels{get;set;}
public getLabel(ApexPages.StandardController controller) {
AllLabels = new List<String>();

String type = 'ProposalFields__c';
Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe();
system.debug('Map is --------------->'+m);

Schema.SObjectType s= m.get(type);
system.debug('Type is--------->'+s);

Map<String, Schema.SObjectField> fieldMap = s.getDescribe().fields.getMap();
system.debug('FieldMap is------------->'+fieldMap);

for (String fieldName: fieldMap.keySet()) {
System.debug('Field API Name*********'+fieldName);       // list of all field API name
String label = fieldMap.get(fieldName).getDescribe().getLabel();   //It provides to get the object fields label.
system.debug('Label is----------------->'+label);
AllLabels.add(label);
}
}

public class sObjectWrapper{  
    public boolean isSelected{get;set;}  
    public ProposalFields__c prop{get;set;}  
    public sObjectWrapper(ProposalFields__c prop,Boolean isSelected){  
    this.prop= prop;  
    this.isSelected = isSelected;  
 }  
 }

}


VF Page

<apex:page showHeader="false" sidebar="false" standardController="Proposal_Form__c" extensions="getLabel">
<apex:form >
<style>
.panelWrapper .mainTitle {
   
    
}
</style>
<apex:outputPanel styleClass="panelWrapper" layout="block">
<apex:pageBlock title="Proposal Form">
<apex:pageBlockSection title="Service Requirements">
<apex:inputField value="{!Proposal_Form__c.Service_Family__c}"/>
<apex:inputfield value="{!Proposal_Form__c.Service_Type__c}"/>
<apex:inputField value="{!Proposal_Form__c.Sub_Service_Category__c}"/>
</apex:pageBlockSection>

<apex:pageBlockButtons location="Bottom">
<apex:commandButton value="Save" action="{!Save}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Available fields">
<apex:pageBlockTable var="lab" value="{!AllLabels}">
<apex:column headerValue="Labels">{!lab}</apex:column>

<apex:column >   
<apex:inputCheckbox />
</apex:column> 

</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>

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

 
Hi all,

I have a requirement where i want to display field labels from an object on VF page form with checkboxes.
I  developed following code
Apex Class:


public class getLabel{

public List<String> AllLabels{get;set;}
public getLabel(ApexPages.StandardController controller) {
AllLabels = new List<String>();
}


String type = 'ProposalFields__c';
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType leadSchema = schemaMap.get(type);
Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();
//system.debug('fieldmap:'+fieldMap.values());
//AllLabels.add(fieldMap.get(fieldName).getDescribe().getLabel());

}


VF page:


<apex:page showHeader="false" sidebar="false" standardController="Proposal_Form__c" extensions="getLabel">
<apex:form >
<style>
.panelWrapper .mainTitle {
   
    
}
</style>
<apex:outputPanel styleClass="panelWrapper" layout="block">
<apex:pageBlock title="Proposal Form">
<apex:pageBlockSection title="Service Requirements">
<apex:inputField value="{!Proposal_Form__c.Service_Family__c}"/>
<apex:inputfield value="{!Proposal_Form__c.Service_Type__c}"/>
<apex:inputField value="{!Proposal_Form__c.Sub_Service_Category__c}"/>
</apex:pageBlockSection>

<apex:pageBlockButtons location="Bottom">
<apex:commandButton value="Save" action="{!Save}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Available fields">
<apex:pageBlockTable var="lab" value="{!AllLabels}">
<apex:column headerValue="Labels">
  {!lab}
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>

<!--<apex:pageblockSection title="Fields Selected">
<apex:inputcheckbox label="First Name" />
<apex:inputCheckbox label="Last Name"/>
<apex:inputcheckbox label="Mobile Number"/>
<apex:inputCheckbox label="State"/>
<apex:inputCheckbox label="City"/>
<apex:inputcheckbox label="Pincode"/>
</apex:pageblockSection>-->
</apex:pageBlock>
</apex:outputPanel>

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

for it,but it is giving error. Please help me for the same.

Thanks & Regards,
Amita Tatar
8805077410
 
Hi all,

I have a requirement where i want to create a list button and give Visualforce page as a content. But when i do this, i am not able to select vf page as a content while creation of this button. Why is it so? Can anyone help me out here.

Regards,
Amita Tatar
Hi all,

I am pasting below my apex class and test class. I am getting accID as null. Please help me where i am going wrong.
apex class----------------------

public class DisplayNotesNew{

public List<WrapperClass> listWrapper {get;set;}
public List<ContactWrapper> listWrapper1 {get;set;}
public List<OpportunityWrapper> listWrapper2 {get;set;}
public Id accId;
Public Account acc;
public List<Note> selectedNotes{get;set;}
public List<Contact> selectedContacts{get;set;}
public List<opportunity> selectedOpps{get;set;}
List<note> contactNote = new List<note>();
List<note> oppNote = new List<note>();
public ID noteID {get;set;}
Public String getRadioValue{get;set;}

public void assignNoteId() {
   Id note = ApexPages.currentPage().getParameters().get('note');
   system.debug('18-->'+note );
   if(note != null) {
      noteID = note;
   }
}    

public DisplayNotesNew(){
        
}
public DisplayNotesNew(ApexPages.StandardController Controller) {

accId = ApexPages.currentPage().getParameters().get('id');
system.debug('********accId************'+accId);
  
List<Note> listAcct = [SELECT Id,Title, Body,Parent.Id,CreatedDate FROM Note where Parent.Id =: accId order by ID DESC];
    system.debug('listAcct--------------------'+listAcct);
  if(listAcct.size() > 0) {  
      listWrapper = new List<WrapperClass>();      
      for(Note a : listAcct) {        
          listWrapper.add(new WrapperClass(a));
        }
    }
List<Contact> listContact = [Select Id, FirstName, LastName,name From Contact where AccountId =: accId order by name DESC];
    if(listContact.size() > 0){     
        listWrapper1 = new List<ContactWrapper>();          
        for(Contact c : listContact){            
            listWrapper1.add(new ContactWrapper(c));
        }
   }

List<Opportunity> listOpp = [select id,name,closeDate from Opportunity where AccountId =: accId order by closeDate ASC];
    if(listOpp.size() > 0){  
        listWrapper2 = new List<OpportunityWrapper>();             
        for(Opportunity o : listOpp){              
            listWrapper2.add(new OpportunityWrapper(o));
       }
   }
}
public pagereference assignNotes(){
system.debug('******noteID******'+noteID);
Note no = [select id,title,body,parentId from Note where id=:noteID limit 1];
system.debug('********no******'+no);

/*selectedNotes = new List<Note>();
system.debug('*********listWrapper ********'+listWrapper);
for(WrapperClass wrapAccountObj : listWrapper ) {
     if(wrapAccountObj.checkBool == true) {
        selectedNotes.add(wrapAccountObj.acct);
        system.debug('*********selectedNotes********'+selectedNotes);
     }  
}  */

selectedContacts = new List<Contact>();
 for(ContactWrapper wrapContactObj : listWrapper1){   
     if(wrapContactObj.checkBool == true){
         Note nt = new Note();  
         nt.Title = no.title;
         nt.Body = no.body;
         nt.ParentId = wrapContactObj.cons.Id; 
         contactNote.add(nt);
         //selectedContacts.add(wrapContactObj.cons);
         //system.debug('*********selectedContacts******'+selectedContacts);
       }
    }
insert contactNote;
    
selectedOpps = new List<Opportunity>();
  for(OpportunityWrapper wrapOppObj : listWrapper2){  
      if(wrapOppObj.checkBool == true){  
          Note nt = new Note(); 
          nt.Title = no.title;  
          nt.Body = no.Body;
          nt.parentId = wrapOppObj.ops.Id;
          oppNote.add(nt);
          //selectedOpps.add(wrapOppObj.ops);
         // system.debug('******selectedOpps*********'+selectedOpps);
     }
  }
insert oppNote;
  PageReference pg = new PageReference('/apex/DisplayAccountNotes?id='+accId);  /*Redirect on the same page*/  pg.setRedirect(true); return pg; 
}
public class WrapperClass{
   public Boolean checkBool {get;set;}
   public Note acct {get;set;}
   public WrapperClass(Note acct){
        this.acct = acct;
        checkBool = false;
       }        
    }
public class ContactWrapper{
   public Boolean checkBool {get;set;}
   public Contact cons {get;set;}
   public ContactWrapper(Contact cons){
        this.cons = cons;
        checkBool = false;
        }    
     }
public Class OpportunityWrapper{
   public Boolean checkBool {get;set;}
   public Opportunity ops {get;set;}
   public OpportunityWrapper(Opportunity ops){
        this.ops = ops;
        checkBool = false;
        }   
     }
}

Test Class-----------------------------------------

@isTest
public class DisplayNotesNewTestClass {

  static testmethod void test1(){
    
    Account acc = new Account(name='vivek112');
    insert acc;
   
    Note ne = new Note(parentid = acc.Id,body ='hi',title = 'Bye');
    insert ne;

    Contact con = new Contact(FirstName='vivek112', AccountId = acc.Id);
    List<Contact> lstcon = new List<Contact>();
    lstcon.add(con);   
        
    Opportunity opp = new opportunity(name = 'a',stageName = 'Closed Won',closedate = date.today(),Renewal_Date__c = date.today(),AccountId = acc.Id);
    List<Opportunity> lstopp = new List<Opportunity>();
    lstopp.add(opp);  
    system.debug('lstopp'+lstopp);
     
     Note note1 = new Note(parentid = acc.Id,title='test',body= 'hi');
    List<note> nList = new List<Note>();
    nList.add(note1);
   
    Note note2 = new Note(parentId = acc.Id,title = 'Hi',body = 'Hi');
    insert note2;
    system.debug('note2-------------'+note2);
    
  
    
    PageReference pageRef = Page.DisplayAccountNotes;
    Test.setCurrentPage(pageRef);      
    DisplayNotesNew obj = new DisplayNotesNew(new ApexPages.StandardController(acc));
    ApexPages.currentPage().getParameters().put('accId',acc.Id);
   // DisplayNotesNew controller = new DisplayNotesNew();
  	  Test.startTest();
 
    ApexPages.CurrentPage().getparameters().put('note',note2.Id);

    DisplayNotesNew objCustom = new DisplayNotesNew ();
    DisplayNotesNew.ContactWrapper objwrap = new DisplayNotesNew.ContactWrapper(con);
    DisplayNotesNew.OpportunityWrapper objwrap1 = new  DisplayNotesNew.OpportunityWrapper(opp); 
    DisplayNotesNew.WrapperClass objwrap2 = new DisplayNotesNew.WrapperClass(note1);
    Id accId = acc.Id;
    id note = note2.id;
    objCustom.assignNoteId();
    id noteID = note;
    objCustom.assignNotes();
    Test.stopTest();
    }
}

-Amita
Hi all,

I have a test class and i am not able to increase its code coverage.
I am posting my apex class and test class code.
Apex Class----------------------------------------

public class DisplayNotesNew{

public List<WrapperClass> listWrapper {get;set;}
public List<ContactWrapper> listWrapper1 {get;set;}
public List<OpportunityWrapper> listWrapper2 {get;set;}
public Id accId;
Public Account acc;
public List<Note> selectedNotes{get;set;}
public List<Contact> selectedContacts{get;set;}
public List<opportunity> selectedOpps{get;set;}
List<note> contactNote = new List<note>();
List<note> oppNote = new List<note>();
public ID noteID {get;set;}
Public String getRadioValue{get;set;}

public void assignNoteId() {
   Id note = ApexPages.currentPage().getParameters().get('note');
   system.debug('18-->'+note );
   if(note != null) {
      noteID = note;
   }
}    

public DisplayNotesNew(){
        
}
public DisplayNotesNew(ApexPages.StandardController Controller) {

accId = ApexPages.currentPage().getParameters().get('id');
system.debug('********************'+accId);
  
List<Note> listAcct = [SELECT Id,Title, Body,Parent.Id,CreatedDate FROM Note where Parent.Id =: accId order by ID DESC];
  if(listAcct.size() > 0) {
    listWrapper = new List<WrapperClass>();
       for(Note a : listAcct) {
          listWrapper.add(new WrapperClass(a));
        }
    }
List<Contact> listContact = [Select Id, FirstName, LastName,name From Contact where AccountId =: accId order by name DESC];
    if(listContact.size() > 0){
        listWrapper1 = new List<ContactWrapper>();
            for(Contact c : listContact){
                listWrapper1.add(new ContactWrapper(c));
        }
   }

List<Opportunity> listOpp = [select id,name,closeDate from Opportunity where AccountId =: accId order by closeDate ASC];
    if(listOpp.size() > 0){
        listWrapper2 = new List<OpportunityWrapper>();
            for(Opportunity o : listOpp){
                listWrapper2.add(new OpportunityWrapper(o));
       }
   }
}
public pagereference assignNotes(){
system.debug('******noteID******'+noteID);
Note no = [select id,title,body,parentId from Note where id=:noteID limit 1];
system.debug('********no******'+no);

/*selectedNotes = new List<Note>();
system.debug('*********listWrapper ********'+listWrapper);
for(WrapperClass wrapAccountObj : listWrapper ) {
     if(wrapAccountObj.checkBool == true) {
        selectedNotes.add(wrapAccountObj.acct);
        system.debug('*********selectedNotes********'+selectedNotes);
     }  
}  */

selectedContacts = new List<Contact>();
 for(ContactWrapper wrapContactObj : listWrapper1){
     if(wrapContactObj.checkBool == true){
         Note nt = new Note();
         nt.Title = no.title;
         nt.Body = no.body;
         nt.ParentId = wrapContactObj.cons.Id;
         contactNote.add(nt);
         //selectedContacts.add(wrapContactObj.cons);
         //system.debug('*********selectedContacts******'+selectedContacts);
       }
    }
insert contactNote;
    
selectedOpps = new List<Opportunity>();
  for(OpportunityWrapper wrapOppObj : listWrapper2){
      if(wrapOppObj.checkBool == true){
          Note nt = new Note();
          nt.Title = no.title;
          nt.Body = no.Body;
          nt.parentId = wrapOppObj.ops.Id;
          oppNote.add(nt);
          //selectedOpps.add(wrapOppObj.ops);
         // system.debug('******selectedOpps*********'+selectedOpps);
     }
  }
insert oppNote;
  PageReference pg = new PageReference('/apex/DisplayAccountNotes?id='+accId);  //Redirect on the same page
       pg.setRedirect(true);
       return pg; 
}
public class WrapperClass{
   public Boolean checkBool {get;set;}
   public Note acct {get;set;}
   public WrapperClass(Note acct){
        this.acct = acct;
        checkBool = false;
       }        
    }
public class ContactWrapper{
   public Boolean checkBool {get;set;}
   public Contact cons {get;set;}
   public ContactWrapper(Contact cons){
        this.cons = cons;
        checkBool = false;
        }    
     }
public Class OpportunityWrapper{
   public Boolean checkBool {get;set;}
   public Opportunity ops {get;set;}
   public OpportunityWrapper(Opportunity ops){
        this.ops = ops;
        checkBool = false;
        }   
     }
}




Test Class-----------------------------------------------------------------------

@isTest
public class DisplayNotesNewTestClass {

  static testmethod void test1(){

    PageReference pageRef = Page.DisplayAccountNotes;
    Test.setCurrentPage(pageRef);
    Account acc = new Account(name='vivek112');
    insert acc;
    DisplayNotesNew obj = new DisplayNotesNew(new ApexPages.StandardController(acc));
    ApexPages.CurrentPage().getparameters().put('id',acc.id);
     
    Contact con = new Contact(FirstName='vivek112', AccountId = acc.Id);
    List<Contact> lstcon = new List<Contact>();
    lstcon.add(con);   
        
    Opportunity opp = new opportunity(name = 'a',stageName = 'Closed Won',closedate = date.today(),Renewal_Date__c = date.today(),AccountId = acc.Id);
    List<Opportunity> lstopp = new List<Opportunity>();
    lstopp.add(opp);  
    system.debug('lstopp'+lstopp);
      
 	Note note = new Note(parentid = acc.Id,title='test',body= 'hi');
    List<note> nList = new List<Note>();
    nList.add(note);
    
    boolean RadioValue = true;
    Id noteID = note.Id;
    system.debug('noteID--------'+noteID);
 
    DisplayNotesNew objCustom = new DisplayNotesNew ();
    DisplayNotesNew.ContactWrapper objwrap = new DisplayNotesNew.ContactWrapper(con);
    DisplayNotesNew.OpportunityWrapper objwrap1 = new  DisplayNotesNew.OpportunityWrapper(opp); 
    DisplayNotesNew.WrapperClass objwrap2 = new DisplayNotesNew.WrapperClass(note);
     
 
    
    objCustom.assignNoteId();
    objCustom.assignNotes();
   
    }
}
I am getting an error in noteID and it is throwing error 'List has no rows for assignment'.Please help.

-Amita
 
Hi all,

I have a VF page survey form for account which has certain questions. Each account can have multiple survey forms as per services availed.
I want to save these survey forms in a child object of Account.
How i should achieve this part?
Here is my code.
Class:


public with sharing class SurveyClass{

Public Account acc{get;set;}
Public List<Proposal_Form__c>pfc;
Public Proposal_Form__c pfc1 {get;set;}
public ProposalFields__c pf {get;set;}
public List<String> fieldSet {get;set;}
Public ID rid;
public string msg {get;set;}
private ApexPages.StandardController standardController;
    
public SurveyClass(ApexPages.StandardController controller) {
    this.standardController = standardController;
    pfc1 = new Proposal_Form__c();
  }

public void Selected(){
    system.debug(pfc1.Service_Family__c +'------------'+pfc1.Sub_Service_Category__c);
    
   /* try{
        pfc = [SELECT Fields_Associated__c FROM Proposal_Form__c where Service_Family__c =: pfc1.Service_Family__c and Sub_Service_Category__c =: pfc1.Sub_Service_Category__c LIMIT 1];
        
    } catch(NullPointerException ex){
        
          Apexpages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.FATAL,'No such combination exists'+ex));
      
    } */
  
    pfc = new List<Proposal_Form__c>();
    pfc = [SELECT Fields_Associated__c FROM Proposal_Form__c where Service_Family__c =: pfc1.Service_Family__c and Sub_Service_Category__c =: pfc1.Sub_Service_Category__c LIMIT 1];

    if(!pfc.isEmpty())
    {
    fieldSet = new List<String>();
    List<String> fields = new List<String>();
     
    if(pfc[0].Fields_Associated__c != null && pfc[0].Fields_Associated__c != ''){
        fields = String.valueof(pfc[0].Fields_Associated__c).split(',');
        system.debug('*********Fields******'+fields);
    }
    else{
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'NO QUESTION SET FOUND'));
    }
   
    Map<String,String> labelMap = new Map<String,String>();
    labelMap = getLabel.retLabelMap('ProposalFields__c');
    system.debug(labelMap);
    system.debug(labelMap);
    for(String s : fields){
        fieldSet.add(labelMap.get(s));
        system.debug('********fieldset*******'+fieldSet);
    }    
  }
  else {
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'NO QUESTION SET FOUND'));
   }
 }  
}


VF Page:;;


<apex:page standardController="Account" extensions="SurveyClass" sidebar="false" showHeader="false" tabStyle="Account">
<apex:form >
<apex:pageMessages rendered="true" id="errMsg" showDetail="false"/>
<apex:pageBlock title="Customer Survey Form"> 

<apex:pageBlockSection title="Service Requirements" >
<apex:inputField value="{!pfc1.Service_Family__c}"/>
 <apex:pageblocksectionItem >
    <apex:outputLabel value="Sub Service Category"/>
    <apex:outputPanel >
        
            <apex:inputfield value="{!pfc1.Sub_Service_Category__c}">
                <apex:actionSupport event="onchange" action="{!Selected}" rerender="fieldst,errMsg" />
             </apex:inputField>
       
    </apex:outputPanel>
</apex:pageblocksectionItem>
</apex:pageBlockSection> 

<apex:pageblockSection title="Question Set" id="fieldst">
    <apex:repeat value="{!fieldSet}" var="f">
      <apex:inputField value="{!pf[f]}"/> 
    </apex:repeat>
</apex:pageblockSection>

<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Submit" action="{!save}"/>
<apex:commandButton value="Edit" action="{!edit}"/>
</apex:pageBlockButtons>

</apex:pageBlock>
</apex:form> 
</apex:page>
Thanks,
Amita
 
Hi all,

I have below code. I want to show error on VF page when particular condition not met and records not found.I have added my code in try catch block and added apex:messages as well.
Please suggest me what is wrong.
The error should be displayed when combination of service family and sub service category is not found in database.
 
Class:


public with sharing class SurveyClass{

Public Account acc{get;set;}
Public Proposal_Form__c pfc;
Public Proposal_Form__c pfc1 {get;set;}
public ProposalFields__c pf {get;set;}
public List<String> fieldSet {get;set;}
Public ID rid;
private ApexPages.StandardController standardController;
    
public SurveyClass(ApexPages.StandardController controller) {
    this.standardController = standardController;
    pfc1 = new Proposal_Form__c();
  }

public void Selected(){
    system.debug(pfc1.Service_Family__c +'------------'+pfc1.Sub_Service_Category__c);
    
    try{
        pfc = [SELECT Fields_Associated__c FROM Proposal_Form__c where Service_Family__c =: pfc1.Service_Family__c and Sub_Service_Category__c =: pfc1.Sub_Service_Category__c LIMIT 1];
        
    } catch(Exception ex){
     ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No such combination exists');
     ApexPages.addMessage(myMsg);
      
    }
     
    fieldSet = new List<String>();
    List<String> fields = new List<String>();
    if(pfc.Fields_Associated__c != null && pfc.Fields_Associated__c != ''){
        fields = String.valueof(pfc.Fields_Associated__c).split(',');
        system.debug('*********Fields******'+fields);
    }
    else{
        Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,''+'No questions to Display"'));
    
    }
    Map<String,String> labelMap = new Map<String,String>();
    labelMap = getLabel.retLabelMap('ProposalFields__c');
    system.debug(labelMap);
    system.debug(labelMap);
    for(String s : fields){
        fieldSet.add(labelMap.get(s));
        system.debug('********fieldset*******'+fieldSet);
    }
    
}
}


VF Page:;


<apex:page standardController="Account" extensions="SurveyClass" sidebar="false" showHeader="false" tabStyle="Account">

<apex:form >
<apex:pageMessages rendered="true"/>
<apex:pageBlock title="Client Survey Form"> 
<apex:pageBlockSection title="Service Requirements" >

<apex:inputField value="{!pfc1.Service_Family__c}"/>
 
<apex:pageblocksectionItem >
    <apex:outputLabel value="Sub Service Category"/>
    <apex:outputPanel >
        
            <apex:inputfield value="{!pfc1.Sub_Service_Category__c}">
                <apex:actionSupport event="onchange" action="{!Selected}" rerender="fieldst" />
                <apex:pageMessages rendered="true"/>
            </apex:inputField>
       
    </apex:outputPanel>
</apex:pageblocksectionItem>
</apex:pageBlockSection> 

<apex:pageblockSection title="Question Set" id="fieldst">
    <apex:repeat value="{!fieldSet}" var="f">
      <apex:inputField value="{!pf[f]}"/> 
    </apex:repeat>
</apex:pageblockSection>

<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Submit" action="{!Save}"/>
</apex:pageBlockButtons>



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


 
Hi all,

I have following code: Scenario is that i have two objects Account and Proposal Form with look up relationship..
I have some standard forms already stored in Proposal Form object which has service family and service category drop down.

On Account i want to rerender field from proposal form on matching of certain conditions,but it is not working. can you please help me out here.
Class::

public with sharing class SurveyClass{

Public Account acc{get;set;}
Public Proposal_Form__c pfc {get;set;}
Public ID rid;
private ApexPages.StandardController standardController;
    
public SurveyClass(ApexPages.StandardController controller) {
    this.standardController = standardController;
    acc = (Account)controller.getRecord();
  }

public void Selected(){
//acc = [SELECT Id, Name, Proposal_Form__r.Name, Proposal_Form__r.Fields_Associated__c, Proposal_Form__r.Service_Family__c, Proposal_Form__r.Sub_Service_Category__c FROM Account ];
pfc = [SELECT Fields_Associated__c FROM Proposal_Form__c where Service_Family__c =: acc.Proposal_Form__r.Service_Family__c and Sub_Service_Category__c =: acc.Proposal_Form__r.Sub_Service_Category__c];

}
}


VF Page:::


<apex:page standardController="Account" extensions="SurveyClass" sidebar="false" showHeader="false" tabStyle="Account">
<apex:form >
<apex:pageBlock title="Client Survey Form"> 
<apex:pageBlockSection title="Service Requirements" >
<apex:inputField value="{!acc.Proposal_Form__r.Service_Family__c}"/>
<apex:inputfield value="{!acc.Proposal_Form__r.Sub_Service_Category__c}"/> 
</apex:pageBlockSection> 

<apex:outputPanel id="form">
<apex:pageblockSection title="Question Set" >
<apex:inputField value="{!acc.Proposal_Form__r.Fields_Associated__c}">
<apex:actionSupport event="onchange" action="{!Selected}" oncomplete="alert('Hello');" rerender="form"  rendered="true"/>
</apex:inputField>
</apex:pageblockSection>
</apex:outputPanel>

</apex:pageBlock>
</apex:form> 
</apex:page>
Please help me out here.

Thanks,
Amita
 
Hi all,

I have a Map in which i have Sobject fields and labels and i am adding these labels to my wraper list and showing it on VF page.
I want to show only the custom field labels here. So i am trying to add condition while adding the labels in wrapper list...but cannot do it.
Can you help? Here is my code:
APEX class::



public class getLabel{

Public Proposal_Form__c pfc = new Proposal_Form__c();
public List<WrapperClass> listWrapper {get;set;}
public Map<String,String> labelMap;
public String resultString {get;set;} 
public ApexPages.StandardController controller; 

public getLabel(ApexPages.StandardController Controller) {
    pfc = (Proposal_Form__c)Controller.getRecord(); 
    this.controller = Controller;  
    listWrapper = new List<WrapperClass>();
    labelMap = new Map<String,String>();
    labelMap = retLabelMap('ProposalFields__c');
    system.debug('******LabelMap***'+labelMap);
        for(String s : labelMap.values()){
            listWrapper.add(new WrapperClass(s,false));
        }
       
   }

public class WrapperClass {  
    public Boolean checkBool {get;set;}
    public String fieldNme{get;set;}  
    public WrapperClass(String prop,Boolean checkBool ){  
        this.fieldNme = prop;  
        this.checkBool = checkBool ;  
    }  
}

public Static Map<String,String> retLabelMap(String type){
    Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe();
    Schema.SObjectType s= m.get(type);
    Map<String, Schema.SObjectField> fieldMap = s.getDescribe().fields.getMap();
    Map<String,String> aMap = new Map<String,String>();
    for (String fieldName: fieldMap.keySet()) {
        aMap.put(fieldName,fieldMap.get(fieldName).getDescribe().getLabel());
    }
    return aMap;
}

public PageReference saveCheckboxValue(){
   if(listWrapper!=null && listWrapper.size()>0){
        for(WrapperClass w : listWrapper){
            if(w.checkBool == true){
              
                   if(resultString!=null){
                        resultString = resultString + '\n'+ w.fieldNme;
                   }
                   else{
                        resultString = w.fieldNme;
                   }
            }
          }
        }
     
     pfc.Fields_Associated__c = resultString; 
     try
     {
         insert pfc;
         PageReference pg = new PageReference('/'+pfc.id);
         return pg;
     }
     catch(dmlexception e)
     {
           apexpages.addmessages(e);
           return null;
     }

}
}
I am trying to add some if condition in the bold part of my code.

Thanks,
Amita
 
Hi all,

I have a VF page where i have displayed sObject labels dynamically on this VF page. These field labels are associated with checkboxes.
I want that whichever checkboxes are selected , there labels should get stored in a text area field at the backend.
I will paste my code below. Please help me for the same.
APEX CLASS::::

public class getLabel{

public List<WrapperClass> listWrapper {get;set;}
public Map<String,String> labelMap;
public String resultString {get;set;}  

public getLabel(ApexPages.StandardController controller) {
    listWrapper = new List<WrapperClass>();
    labelMap = new Map<String,String>();
    labelMap = retLabelMap('ProposalFields__c');
    for(String s : labelMap.values()){
        listWrapper.add(new WrapperClass(s,false));
    }
}

public class WrapperClass {  
    public Boolean checkBool {get;set;}
    public String fieldNme{get;set;}  
    public WrapperClass(String prop,Boolean checkBool ){  
        this.fieldNme = prop;  
        this.checkBool = checkBool ;  
    }  
}

public Static Map<String,String> retLabelMap(String type){
    Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe();
    Schema.SObjectType s= m.get(type);
    Map<String, Schema.SObjectField> fieldMap = s.getDescribe().fields.getMap();
    Map<String,String> aMap = new Map<String,String>();
    for (String fieldName: fieldMap.keySet()) {
        aMap.put(fieldName,fieldMap.get(fieldName).getDescribe().getLabel());
    }

    return aMap;
}

public void saveCheckboxValue(){
     Proposal_Form__c p = new Proposal_Form__c();
     p.Fields_Associated__c = resultString;
     insert p;
 }
 
public PageReference getSelected(){
   return null;
}



}



VF PAGE:


<apex:page showHeader="false" sidebar="false" standardController="Proposal_Form__c" extensions="getLabel">
<apex:form >
<style>
.panelWrapper .mainTitle {
   text-align :center;
    
}
</style>
<apex:outputPanel styleClass="panelWrapper" layout="block">
<apex:pageBlock title="Proposal Form">
<apex:pageBlockSection title="Service Requirements">
<apex:inputField value="{!Proposal_Form__c.Service_Family__c}"/>
<apex:inputfield value="{!Proposal_Form__c.Service_Type__c}"/>
<apex:inputField value="{!Proposal_Form__c.Sub_Service_Category__c}"/>
</apex:pageBlockSection>

<apex:pageBlockButtons location="Bottom">
<apex:commandButton value="Save" action="{!Save}"/>
</apex:pageBlockButtons>

<apex:pageBlockSection title="Available fields">
<apex:repeat var="lab" value="{!listWrapper}">
    <apex:pageblockSectionItem >
        <apex:outputlabel value="{!lab.fieldNme}"/>
        <apex:inputCheckbox value="{!lab.checkBool}"/>
    </apex:pageblockSectionItem> 
</apex:repeat>

</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>

</apex:form> 
</apex:page>
Thanks,
Amita Tatar
 
Hi all,

I have a requirement where i want to display field labels from an object on VF page form with checkboxes.
I  developed following code
Apex Class:


public class getLabel{

public List<String> AllLabels{get;set;}
public getLabel(ApexPages.StandardController controller) {
AllLabels = new List<String>();
}


String type = 'ProposalFields__c';
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType leadSchema = schemaMap.get(type);
Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();
//system.debug('fieldmap:'+fieldMap.values());
//AllLabels.add(fieldMap.get(fieldName).getDescribe().getLabel());

}


VF page:


<apex:page showHeader="false" sidebar="false" standardController="Proposal_Form__c" extensions="getLabel">
<apex:form >
<style>
.panelWrapper .mainTitle {
   
    
}
</style>
<apex:outputPanel styleClass="panelWrapper" layout="block">
<apex:pageBlock title="Proposal Form">
<apex:pageBlockSection title="Service Requirements">
<apex:inputField value="{!Proposal_Form__c.Service_Family__c}"/>
<apex:inputfield value="{!Proposal_Form__c.Service_Type__c}"/>
<apex:inputField value="{!Proposal_Form__c.Sub_Service_Category__c}"/>
</apex:pageBlockSection>

<apex:pageBlockButtons location="Bottom">
<apex:commandButton value="Save" action="{!Save}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Available fields">
<apex:pageBlockTable var="lab" value="{!AllLabels}">
<apex:column headerValue="Labels">
  {!lab}
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>

<!--<apex:pageblockSection title="Fields Selected">
<apex:inputcheckbox label="First Name" />
<apex:inputCheckbox label="Last Name"/>
<apex:inputcheckbox label="Mobile Number"/>
<apex:inputCheckbox label="State"/>
<apex:inputCheckbox label="City"/>
<apex:inputcheckbox label="Pincode"/>
</apex:pageblockSection>-->
</apex:pageBlock>
</apex:outputPanel>

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

for it,but it is giving error. Please help me for the same.

Thanks & Regards,
Amita Tatar
8805077410
 
Hi all,

I have a requirement where i want to create a list button and give Visualforce page as a content. But when i do this, i am not able to select vf page as a content while creation of this button. Why is it so? Can anyone help me out here.

Regards,
Amita Tatar
Hi Guys,
Location.href used in custom button, its working in firefox but not working in google chrome.


Thanks,
Gopi.

 

Hi,

 

Please help me with the below scenario, I have Visualforce page through which I can select a value from Picklist and based on the Picklist value particular Checkboxes will be displayed on the page. My Requirment is when a checkbox value is selected and Save botton is clicked, then the checkbox value need to be stored in a TextArea Field in the respective Object.

 

Selected Checkbox values should be displayed in a TextArea Field ' PlacesVisisted__c ' in the Contact Object.

 

Please help me on this scenario. ThankYou.

 

Below is my Visualforce Page.

 

<apex:page standardController="Contact">
<apex:form >
<apex:pageBlock title="Update Contact Details">
 <apex:pageBlockButtons location="bottom">
  <apex:commandButton action="{!save}" value="Save"/>
  <apex:commandButton action="{!cancel}" value="Cancel"/>
 </apex:pageBlockButtons>
<apex:pageBlockSection id="NewPage" title="Select The Country">
    <apex:inputField value="{!Contact.Country__c}">
    <apex:actionSupport event="onchange" reRender="IndiaBlock, USBlock, ChinaBlock, AusesBlock"/>
    </apex:inputField>
    <apex:inputText value="{!Contact.Name}"/>
</apex:pageBlockSection> 
<apex:outputPanel id="IndiaBlock">
 <apex:pageBlockSection rendered="{!Contact.Country__c == 'India'}" id="SampleSendInfoBlock" title="Select Places Visited">
    <apex:inputCheckbox label="Agra"/>
    <apex:inputcheckbox label="Delhi"/>
 </apex:pageBlockSection>
</apex:outputPanel>
<apex:outputPanel id="USBlock">
 <apex:pageBlockSection title="Select Places Visited" rendered="{!Contact.Country__c == 'America'}" id="USPageBlock">
  <apex:inputCheckbox label="Newyork"/>
  <apex:inputCheckbox label="Washington"/>
 </apex:pageBlockSection> 
</apex:outputPanel>
<apex:outputPanel id="ChinaBlock">
 <apex:pageBlockSection title="Select Places Visited" rendered="{!Contact.Country__c == 'China'}" id="ChinaPageBlock">
 <apex:inputCheckbox label="Bejing"/>
 <apex:inputCheckbox label="Taiwan"/>
 </apex:pageBlockSection>
</apex:outputPanel>
<apex:outputPanel id="AusesBlock">
 <apex:pageBlockSection title="Select Places Visited" rendered="{!Contact.Country__c == 'Australia'}" id="AusesPageBlock">
 <apex:inputCheckbox label="Sydney"/>
 <apex:inputCheckbox label="Canberra"/>
 </apex:pageBlockSection>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
I have one visualforce page with PageBlockTable
A List of SOBject in custom controller gives value to that pageBlockTable
Now i have created one column with <apex:inputCheckbox> in same pageBlockTable
 
Now i want the List of selected rows of that pageblocktable and need to save that list in a custom object.
 
How can i perform this task?
Here is my code:
VF Page Code:
<apex:page controller="viewhold" showHeader="false" tabStyle="POS__c">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
    <apex:commandButton id="btnRestore" value="Restore"/>
    <apex:commandButton id="btnCombine" value="Combine"/>
    <apex:commandButton id="btnCancel" value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!HoldPos}" var="pos">
    <apex:column >
    <apex:facet name="header">Select</apex:facet>
    <apex:inputCheckbox value="{!pos.Id}" /> 
    </apex:column>
    
    <apex:column value="{!pos.Name}"/>
    <apex:column value="{!pos.Client__r.Client__c}"/>
    <apex:column value="{!pos.CreatedDate}"/>
    <apex:column value="{!pos.TotalDue__c}"/>
    <apex:column value="{!pos.TotalPaid__c}"/>
</apex:pageBlockTable>   
</apex:pageBlock>
</apex:form>
</apex:page>
Code:
public class viewhold 
{
List<POS__c> poslist = new List<POS__c>();
List<POS__c> selectedpos = new List<POS__c>();

    public List<POS__c> getHoldPos()
        {
                poslist = [select id,Name,Client__r.Id,Client__r.Client__c,CreatedDate,RetailAmt__c,ServiceAmt__c,TotalDue__c,TotalPaid__c from POS__c where Status__c='Hold' and Client__c =: System.CurrentPageReference().getParameters().get('cid')];
                return poslist;
        }       
    public void Addticket()
    {
        for(POS__c pos:poslist)
        {
            selectedpos.add(pos);
        }    
    }
}

 Please let me know where m doing mistakes?
and what should i do to perform this task??
 
Thanks.