• Sibanee purohit
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 6
    Replies
Can anyone please help me with this problem.This error is showing only for PageblockTable.if I use apex:repeat it's working but I need to use pageblockTable. Error is 'Map key null not found in map Error is in expression '{!objRecordsMap[obj]}' in component'. Here is the code
VF Page:
<apex:page controller="FindRelatedData" >
<apex:form >
    <apex:pageBlock title="Related Data">
    <apex:pageblockSection>
    <apex:pageblockTable value="{!objFieldsMap}" var="obj">
        <!---{!obj}<br></br>-->
      <apex:repeat value="{!objRecordsMap[obj]}" var="record">
          
            <apex:repeat value="{!objFieldsMap[obj]}" var="field">
                <!---{!record[field]}<br></br>-->
                
              <apex:column headerValue="{!field}">
                  <apex:outputText value="{!record[field]}"/>
               </apex:column>
            </apex:repeat>
      </apex:repeat>

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

Apex code:
public class FindRelatedData {

    public String getQueries() {
        return null;
    }
    public Id id = '0016F00001rZlrM';
    string objType;
    string childName;
    string fname;
    //string qry;
   Public List<string> fieldlist{get;set;}
   Public List<sObject> objQry{get;set;}
    List<sObject> queries;
    Map<String, Schema.SobjectField> fmap = new Map<String, Schema.SobjectField>();
    List<string> objNames = new List<string>();
    public List<SObject> childObjs = new List<SObject>();
    public Map<String, List<string>> objFieldsMap {get;set;}
    public Map<String, List<sObject>> objRecordsMap{get;set;}
    
    public FindRelatedData()
    {
        
        objFieldsMap = new Map<String, List<string>>();
        objRecordsMap = new Map<String, List<sObject>>();
        objType = id.getsobjecttype().getDescribe().getName();
        System.debug('object Type:'+objType);
        Schema.DescribeSObjectResult relationType = Schema.getGlobalDescribe().get(objType).getDescribe();
        for(Schema.ChildRelationship childs: relationType.getChildRelationships())
        {
            System.debug('childs:'+childs);
            
            Schema.SObjectType sobj = childs.getChildSObject();
            System.debug('sobjects:'+sobj);          
            childName = String.valueOf(childs.getChildSObject());
            system.debug('Child Object:'+childName);
            List<string> setFlds = new List<String>();
            if(childName == 'SP001_MyDev__Account__c' || childName == 'opportunity' ) 
            {
                Schema.SobjectField fields = childs.getField();
            	fname = childs.getField().getDescribe().getName();
            	System.debug(fname);
                //System.debug('childName:'+childName);
                sObject obj = Schema.getGlobalDescribe().get(childName).newSObject();
                System.debug('objs:'+obj);
                objNames.add(childName);
                childObjs.add(obj);
                fieldlist = new List<string>();
                fmap = childs.getChildSObject().getDescribe().fields.getMap();
                System.debug('Fields*****'+fmap);
                for(String f:fmap.keySet())
                {
                    System.debug('field name:'+f);
                    
                    fieldlist.add(f);
                }
                objFieldsMap.put(childName,fieldlist);
                System.debug('objFields***'+objFieldsMap);
        		objQry = executeqry(fieldlist);
        		System.debug('child objects:'+objQry);
                objRecordsMap.put(childName,queries);
        			System.debug('records:'+objRecordsMap);
        	}
            
        }
    }
    
   
    Public list<sObject> executeqry(List<string> fieldlists)
    {
       		   

               string qry = fieldlists.get(0);
                    for(Integer i =1;i<fieldlists.size();i++)
                    {
                        qry  = qry+ ' , ' + fieldlists.get(i) ;
                        System.debug('Qry----'+qry);
                    }
                     System.debug('printquery:'+' SELECT '+''+ qry +' '+' FROM '+' '+ childName +' '+' WHERE '+''+fname+ ' = \'' +id+'\''+ ' LIMIT '+' '+'3');
                    queries = Database.query(' SELECT '+''+ qry +' '+' FROM '+' '+ childName +' '+' WHERE '+''+fname+ ' = \'' +id+'\''+ ' LIMIT '+' '+'3');
                    System.debug('Query:'+ queries); 
                //executeqry(fieldlist);
            
    				//fieldlist.addAll(fieldlists);
        			
		System.debug('fieldlists:'+fieldlist);
        return queries;
    }
  
}

 
I need to save records from visualforce page.My requirement is I need to get related objects dynamically based on any parent record id.So I created 1 Vf component and controller for that where I am getting related object and fields which can be displayed on vf page but i need to edit and save some record.How to achieve that.Please help me with this. Here is the code I have tried:
VF component

<apex:component controller="CustomRelatedListControllerNew" allowDML="true" >
    <apex:attribute assignTo="{!typeOf}" name="typeOfParam" required="true" type="String" description="Type of Related Record" />
    <apex:attribute assignTo="{!fieldlist}" name="relatedFieldlistParam" required="true" type="String[]" description="String of related Fields." />
    <apex:attribute assignTo="{!relatedField}" name="relatedFieldParam" required="true" type="String" description="String of related field." />   
    <apex:attribute assignTo="{!relatedId}" name="relatedIdParam" required="true" type="String" description="String of related Id." />
    <!---<apex:attribute assignTo="{!obj}" name="relatedIdobject" required="true" type="sObject[]" description="String of related objects." />-->

    <apex:form >
    <apex:pageblock title="{!typeOf}" id="childobj">
    <apex:commandButton value="Save" action="{!Save}" reRender="childobj"/> 
    <apex:pageBlockTable var="o" value="{!objects}">

      <apex:repeat value="{!fieldlist}" var="fldNames">
       <apex:column > 

                <apex:outputText value="{!$ObjectType[typeOf].fields[fldNames].Name}">

                </apex:outputText>

        </apex:column>
        <br></br>
        <apex:column >
        <apex:inputField value="{!o[fldNames]}">
        <!---<apex:inlineEditSupport showOnEdit="saveButton,cancelButton"
                        hideOnEdit="editButton" event="ondblclick"
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>-->
                        </apex:inputField> 
        </apex:column>
        <br/>
          </apex:repeat>



    </apex:pageBlockTable>

    </apex:pageblock>

    </apex:form>
</apex:component>

Controller:
public class CustomRelatedListControllerNew {
    private ApexPages.StandardController controller {get; set;}
    public String typeOf { get; set; }  
    public String relatedField { get; set; }
    public List<String> fieldlist{ get; set; }
    public Id relatedId { get; set; }
    public List<sObject> obj{ get; set; }
    public String query;
    public Integer n;
    public List<sObject> objects;

   public List<sObject> getObjects() {
        n = fieldlist.size();
        System.debug(n);
        //String d = ApexPages.currentPage().getParameters().get('id');
        //System.debug(d);
        query = fieldlist.get(0);
        //String query1 = 'SELECT Id'+ ' ' + 'FROM'+ ' ' + 'Attachment';
        for(Integer i=1;i<fieldlist.size();i++){
            query = query+ ' , ' + fieldlist.get(i) ;
            System.debug(query);
        }

        System.debug('qqq****'+'SELECT'+ ' '+ query +' '+'FROM '+ typeOf+' '+'WHERE' +' '+  relatedField + ' = \'' + relatedId +'\'');
        objects = Database.query('SELECT'+ ' '+ query +' '+'FROM '+ typeOf+' '+'WHERE' +' '+  relatedField + ' = \'' + relatedId +'\'');
       //return Database.query('SELECT'+ ' '+ query +' '+'FROM '+ typeOf+' '+'WHERE' +' '+  relatedField + ' = \'' + relatedId +'\'');
       return objects;
    }
    public void setObjects(List<sObject> objects)
    {
        System.debug('ooo'+objects);
        this.objects = objects;
        //objects = s;
        //update objects;
        
    }
   public PageReference Save() {
        setObjects();
        update objects;
        System.debug('ooo'+objects);
        return null;
    }

}

getting child records in 'objects' but it's not getting saved and setobject method also not getting invoked.Where I am doing wrong here please help me with this
In my scenario I have some records and I need to create one custom button in detail page,by clicking that button that record should be deactivated or disabled...How can I achieve that functionality..Please help me
I need to save records from visualforce page.My requirement is I need to get related objects dynamically based on any parent record id.So I created 1 Vf component and controller for that where I am getting related object and fields which can be displayed on vf page but i need to edit and save some record.How to achieve that.Please help me with this. Here is the code I have tried:
VF component

<apex:component controller="CustomRelatedListControllerNew" allowDML="true" >
    <apex:attribute assignTo="{!typeOf}" name="typeOfParam" required="true" type="String" description="Type of Related Record" />
    <apex:attribute assignTo="{!fieldlist}" name="relatedFieldlistParam" required="true" type="String[]" description="String of related Fields." />
    <apex:attribute assignTo="{!relatedField}" name="relatedFieldParam" required="true" type="String" description="String of related field." />   
    <apex:attribute assignTo="{!relatedId}" name="relatedIdParam" required="true" type="String" description="String of related Id." />
    <!---<apex:attribute assignTo="{!obj}" name="relatedIdobject" required="true" type="sObject[]" description="String of related objects." />-->

    <apex:form >
    <apex:pageblock title="{!typeOf}" id="childobj">
    <apex:commandButton value="Save" action="{!Save}" reRender="childobj"/> 
    <apex:pageBlockTable var="o" value="{!objects}">

      <apex:repeat value="{!fieldlist}" var="fldNames">
       <apex:column > 

                <apex:outputText value="{!$ObjectType[typeOf].fields[fldNames].Name}">

                </apex:outputText>

        </apex:column>
        <br></br>
        <apex:column >
        <apex:inputField value="{!o[fldNames]}">
        <!---<apex:inlineEditSupport showOnEdit="saveButton,cancelButton"
                        hideOnEdit="editButton" event="ondblclick"
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>-->
                        </apex:inputField> 
        </apex:column>
        <br/>
          </apex:repeat>



    </apex:pageBlockTable>

    </apex:pageblock>

    </apex:form>
</apex:component>

Controller:
public class CustomRelatedListControllerNew {
    private ApexPages.StandardController controller {get; set;}
    public String typeOf { get; set; }  
    public String relatedField { get; set; }
    public List<String> fieldlist{ get; set; }
    public Id relatedId { get; set; }
    public List<sObject> obj{ get; set; }
    public String query;
    public Integer n;
    public List<sObject> objects;

   public List<sObject> getObjects() {
        n = fieldlist.size();
        System.debug(n);
        //String d = ApexPages.currentPage().getParameters().get('id');
        //System.debug(d);
        query = fieldlist.get(0);
        //String query1 = 'SELECT Id'+ ' ' + 'FROM'+ ' ' + 'Attachment';
        for(Integer i=1;i<fieldlist.size();i++){
            query = query+ ' , ' + fieldlist.get(i) ;
            System.debug(query);
        }

        System.debug('qqq****'+'SELECT'+ ' '+ query +' '+'FROM '+ typeOf+' '+'WHERE' +' '+  relatedField + ' = \'' + relatedId +'\'');
        objects = Database.query('SELECT'+ ' '+ query +' '+'FROM '+ typeOf+' '+'WHERE' +' '+  relatedField + ' = \'' + relatedId +'\'');
       //return Database.query('SELECT'+ ' '+ query +' '+'FROM '+ typeOf+' '+'WHERE' +' '+  relatedField + ' = \'' + relatedId +'\'');
       return objects;
    }
    public void setObjects(List<sObject> objects)
    {
        System.debug('ooo'+objects);
        this.objects = objects;
        //objects = s;
        //update objects;
        
    }
   public PageReference Save() {
        setObjects();
        update objects;
        System.debug('ooo'+objects);
        return null;
    }

}

getting child records in 'objects' but it's not getting saved and setobject method also not getting invoked.Where I am doing wrong here please help me with this
In my scenario I have some records and I need to create one custom button in detail page,by clicking that button that record should be deactivated or disabled...How can I achieve that functionality..Please help me
I would like to create a round assignment on the opportunity object. So when an opportunity is created, an account name will be added to the opportunity (based off of a picklist of three account names). I see that there isn't an assignment rule option on the opportunity object, so I created an assignment rule on the case object for the account names. Right now I'm stuck on the soql statement [Select ID From Account Where Name in: oppList.id]. I receive a debug statement of Variable does not exist: id.  Is there a way for me to reference the assignment rule id so that it loops through the three account names?

trigger NewAcc on Opportunity (after insert) {
   
    List<Opportunity> oppList = new  List<Opportunity>();
    AssignmentRule ar = new AssignmentRule();
    ar = [SELECT ID FROM AssignmentRule where SobjectType = 'Case'and ID = '01Q360000001zcv' and Active = true limit 1];
      
  Case newCase = new Case(Status = 'new');
  Database.DMLOptions dmlOpts = new Database.DMLOptions();
        newCase.setOptions(dmlOpts);    

  Account acct = [SELECT Id From Account Where NAME in: oppList.id  ]

    for(Opportunity opp: Trigger.new){
          
        opp.AccountId = acct.Id;
        oppList.add(opp);
 
    }
insert newCase;
insert oppList;
}
  • July 04, 2017
  • Like
  • 0