• ASF
  • NEWBIE
  • 10 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 6
    Replies
hi,

  Can any one help me to pass the value in select option

Apex Class:

public class HousingOpportunity
{
    public Housing_Resource_Opportunity__c objHrsOpp {get; set;}
    //private String soql{get;set;}
    public HousingOpportunity()
    {
        objHrsOpp = new Housing_Resource_Opportunity__c();
   
    }
   
   public string selectBuildingname{get;set;} 

    public list<selectOption> getBuildingname()
    {
        list<selectOption> options = new list<selectOption>();
        options.add(new selectOption('','-None-'));
        list<Housing_Resource__c> houres= [Select Id,Name from Housing_Resource__c]; 
        Set<String> strUniq = new Set<String>();        
        for(Housing_Resource__c hr : houres)
        {
             if(strUniq.add(hr.Name.touppercase()))
             {
               options.add(new selectOption(hr.Name,hr.Name));
               system.debug('BuildingName--------------'+options);
             }
        }
       
        return options;
    }
 
     public string selectroomnameandnumber{get;set;}
     public List<selectOption> getroomnameandnumber()
     {
  
        List<selectOption> options = new List<selectOption>();
        options.add(new selectOption('','-None-'));
         system.debug('selectBuildingname@@@@@@@@@@@@@@@@@@@@@'+selectBuildingname);
        if(selectBuildingname != null)        // Its not covered from this line  value passing is null
        {

        String hrsSQL = 'Select Room_Name_and_Number__c from Housing_Resource__c  where Name=:selectBuildingname AND Room_Name_and_Number__c!=null';
            List<Housing_Resource__c> houres = Database.query(hrsSQL);
             //system.debug('roomnameupdown'+hrsSQL);
            for(Housing_Resource__c hr : houres)     
            {
                options.add(new selectOption(hr.Room_Name_and_Number__c,hr.Room_Name_and_Number__c ));  
            }
           
           
       } 
    
       return options;
     }
}


Test class:


@isTest
public class HousingOpportunityTestClass
{
    public static TestMethod void HousingOpportunityTestClass()
    {
         PageReference ref = Page.HousingOpportunity;
        Test.setCurrentPage(ref);
        system.debug('Test---------'+ref);

        Housing_Resource__c HousingResouce = new Housing_Resource__c(Name ='TestBuildName', Room_Name_and_Number__c = 'BN101');
        insert HousingResouce;
        
     
            ApexPages.currentPage().getParameters().put('selectBuildingname',HousingResouce.Name); 
           
            HousingOpportunity thehousopp = new HousingOpportunity();
        
      
         thehousopp.getBuildingname();
    
         thehousopp.getroomnameandnumber();

 }
 
}

public static   List<Level2sClass> Level2List;
public static List<Level2sClass> getList2Details(Level1s__c lvl)
{
// Level1s__c lvl;

Level2List= new List<Level2sClass>();
if(ApexPages.currentPage().getParameters().get('S') == null)
{
lstLevel2 = [Select id,name,Level1_Name__c,Level1__c, (select id,account__r.name from Level2s__r where account__c =:accid ) from Level2s__c where Level1__c =:lvl.id order by id];

}else
{
lstLevel2 = [Select id,name,Level1_Name__c,Level1__c, (select id,account__r.name from Level2s__r where account__c =:accid ),(select id from Level3s__r limit 1) from Level2s__c where Level1__c =:lvl.id and id in (Select cLevel2__c from Level2__c where Account__c=:accid) order by id];

}
for(level2s__c s: lstLevel2)
{
Level2List.add(new Level2sClass(s));
}
lvl1 = lvl;

return Level2List;
}

 

 

 

public void Save()
{

///////////// LEVEL2 /////////////////////

List<level2s__c> selectedLevel2= new List<level2s__c>();




for(Level2sClass cCon : getList2Details(Level1s__c lvl))          // here i call the method it passing a null value.
{
system.debug('@@@@@@@@@@@@@Level1@@@$$$$$$'+le1.id);
if(cCon.selected == true)
{
selectedLevel2.add(cCon.lev2);
}
}
}


Level2__c[] levl2= [Select Id from Level2__c where Account__c=: ApexPages.currentPage().getParameters().get('id')];
delete levl2;
if(selectedLevel2 != null)
{
for(level2s__c con : selectedLevel2)
{
//system.debug('CCCCCCCCCC:'+con+'\n');
string acctid =ApexPages.currentPage().getParameters().get('id');
List<Level2__c> lvl2obj= new Level2__c[0];
lvl2obj.add(new Level2__c(Name='Level2',Account__c=acctid,cLevel2__c=con.id));
insert lvl2obj;

}
}

 

 

 

how to call the method with parameters???????????????

First i create a button in campaign and if click this button. campaign members contact and lead ownership to be changed as    campaign owner name....

 

Thi is my code can any one tell me where did i make a mistake..

 

{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")}

var url = parent.location.href;

var AccId = "{!Account.Id}";
var CampId ="{!Campaign.Id}";
var CampOwnerId= "{!Campaign.OwnerId}";

var updateRecords = [];
var update_Cons = new sforce.SObject("Contact");

var result = sforce.connection.query("SELECT Id, Contact.OwnerId, Lead.OwnerId, campaignid FROM CampaignMember WHERE campaignid = '"+CampId +"'"); 
var recs = result.getArray("records");

if(confirm("Are you sure you want to update the name on related contacts and leads?") )
{
for(var i = 0; i < recs.length; i++)
{
recs[i].Contact.OwnerId= CampOwnerId;
recs[i].Lead.OwnerId= CampOwnerId;

updateRecords.push(recs[i]);
}

var result = sforce.connection.update(updateRecords);

parent.location.href = url;

if(result[0].success == 'true')
{
alert("Related contacts and leads updated successfully");
}
else
{
alert("Failed to update the related contacts and leads");
}
}

hi

 

 First i create a button on Account. and if i click that button that related contacts owner name is changed as Account owner Name. 

 

Please give me a solution for this...