• deeksharth srivastava
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 0
    Replies
hii , All I want to create fieldset dynamically from controller .
public  class PropertyRelatedController 
{
//  declaration Start
   public  List<String> str1 ;
   public List<SelectOption> countrieLst {get;set;}
   String newSetStr ;
   String Selectedstr;
   public  string ContactIds{get;set;}
  // public  string ContactIds1{get;set;}
   list<Contact> con =new list<Contact>();
   list<CampaignMember> cmem = new list<CampaignMember>();
   public TTL_Residential__Property__c cp{get;set;}
   Public List<WrapperClassEx> WrapperList{get;set;}
   public  list<string> ContactId = new list<string>();
   public  list<string> ContactId1 = new list<string>();
   public  list<string> ContactId2 = new list<string>();
   Set<Id> accountId = new Set<ID>();
   
   public string selectedValue{get;set;}
   
 // Controller start from here           
   public PropertyRelatedController(ApexPages.StandardSetController standardController) 
   {
            for(Sobject standcont:standardController.getSelected())
          {
               accountId.add(standcont.id);
          } 
           cp = new TTL_Residential__Property__c();
           selectedValue='';
            system.debug('chechk'+Selectedstr);
          // ContactIds = new list<string>();
           ContactId.clear();  
   }
     public void getContactNames()
    { 
     Selectedstr = selectedValue;
 
   getwrapperObj();
    }
      public List<SelectOption> getItems()
     {
        List<SelectOption> options = new List<SelectOption>();

        options.add(new SelectOption('All','--All--'));
        options.add(new SelectOption('Primary Owner or Owner','Primary Owner and Owner '));
        options.add(new SelectOption('Primary Owner','Primary Owner'));
        options.add(new SelectOption('Owner','Owner'));

        return options;
     }

 
// Wrapper Class Starts from Here 
    
   Public List<WrapperClassEx> getwrapperObj()
   {
   WrapperList = New List<WrapperClassEx>();
   map<string,TTL_Residential__Property__c> mapofproperty = new map<string,TTL_Residential__Property__c>();
    For( TTL_Residential__Property__c propobject : [ select id,name from TTL_Residential__Property__c where id in:accountId ])
     {
             mapofproperty.put(propobject.id,propobject);
      }
      set<string> setofid = new set<string>();
      map<string,WrapperClassEx> mapofwrapper = new map<string,WrapperClassEx>();
      
     if(Selectedstr != null && Selectedstr!='Primary Owner or Owner' && Selectedstr!='All' )
     {
       ContactId.clear();
    
       system.debug('cid'+ContactId);
     for(TTL_Core__Contact_Role__c contactrole : [select id,TTL_Core__Contact__c,TTL_Core__Contact_Role__c,TTL_Commercial__Property__c,TTL_Core__Contact__r.Account.Name from TTL_Core__Contact_Role__c where TTL_Commercial__Property__c in:mapofproperty.keyset() and TTL_Core__Contact_Role__c =: Selectedstr])
    {
           ContactId.add(contactrole.TTL_Core__Contact__c);
            system.debug('cid2'+ContactId);
          
        if(!setofid.contains(contactrole.TTL_Commercial__Property__c))
        {
            setofid.add(contactrole.TTL_Commercial__Property__c);
            mapofwrapper.put(mapofproperty.get(contactrole.TTL_Commercial__Property__c ).id,New WrapperClassEx(mapofproperty.get(contactrole.TTL_Commercial__Property__c ).name,mapofproperty.get(contactrole.TTL_Commercial__Property__c ).id ));
            mapofwrapper.get(contactrole.TTL_Commercial__Property__c).listofcontactrole.add(contactrole);
            WrapperList.add(New WrapperClassEx(mapofproperty.get(contactrole.TTL_Commercial__Property__c ).name,mapofproperty.get(contactrole.TTL_Commercial__Property__c ).id ));
        }
        else
        {
            mapofwrapper.get(contactrole.TTL_Commercial__Property__c).listofcontactrole.add(contactrole);
        }
    }   
    }
       
 
   Public Class WrapperClassEx
   {
     public list<TTL_Core__Contact_Role__c > listofcontactrole{get;set;}
     Public string propertyname{get;set;}
     Public string propertyid{get;set;}
   
     Public WrapperClassEx(string JCity,string propertyid){        
        this.propertyid = propertyid;
        propertyname=JCity;    
        listofcontactrole =  new   list<TTL_Core__Contact_Role__c >();          
     }
   } 

  
  

 }
public with sharing class AddToCampaignController 
{
    public TTL_Residential__Property__c c{get;set;}
    private set<string> ids = new set<string>();
    public AddToCampaignController(ApexPages.StandardSetController standardController) 
    {
        for(Sobject standcont:standardController.getSelected())
        {
            ids.add(standcont.id);
          //  this.standardController = standardController;
        }
        c = new TTL_Residential__Property__c();
    }
    
    public void UpdateRecord()
    {
    
        list<TTL_Residential__Property__c> updtlst= new list<TTL_Residential__Property__c>();
        for(TTL_Residential__Property__c  obj2 :[select Id , Name,Campaign_Lookup__c from TTL_Residential__Property__c where id in:ids])
        {
            if(obj2.Campaign_Lookup__c ==null)
            {
            obj2.Campaign_Lookup__c=c.Campaign_Lookup__c;
            updtlst.add(obj2);     
            }            
        }
        if(updtlst.size()>0)
        update updtlst;
    }  
}
i am using a list view  of account  selected multiple and call it on vf page with associated contact and i create a dropdownlist with value primary number , parmanent number primary or parmanent both , when I selecting a  value from picklist  and make a view  get all related contact s but the problem is that when i  add  with selected view on campaign  its adding all the contact whichcomes from standard set controller
 
how can i create a list view dynamically via trigger for any standard objects .