Javascript :
-------------
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}
var ReferraAccepted = sforce.connection.query("SELECT id from {!Account.Routing_Rule__c} where AccountId ='{!Account.Id}'");
records = ReferraAccepted.getArray("records");
alert(records);
if (!records.length > 0) {
alert("There were no child records been assigned !!")
}
else {
window.open('/apex/RoutingRuleLogic?Id={!Account.Id}&objectName={!Account.Routing_Rule__c}', '_blank', 'height=600,width=600,resizable=yes,scrollbars=yes,toolbar=no,menubar=no');
}
Visualforce Page :
--------------------
<apex:page controller="RoutingRuleLogic_CLS" sidebar="false" showHeader="false">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!objectDetails}" var="a">
<apex:column value="{!a.id}"/>
<apex:column headerValue="Name">
<apex:outputText value="{!a['name']}"/>
</apex:column>
<apex:column headerValue="Email">
<apex:outputText value="{!a['email']}"/>
</apex:column>
<apex:column headerValue="Phone">
<apex:outputText value="{!a['phone']}"/>
</apex:column>
<apex:column headerValue="Account Id">
<apex:outputText value="{!a['Accountid']}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Logic :
---------------
public with sharing class RoutingRuleLogic_CLS {
public string objectName {get;set;}
public String query {get;set;}
public RoutingRuleLogic_CLS(){
objectName = apexpages.currentpage().getparameters().get('objectName');
if(objectName != '' && objectName != NULL){
getRecordsBasedOnObjectName(objectName);
}
}
public list<sObject> objectDetails {get;set;}
public Map<String,Schema.SObjectType> schemaGlobalDescription ;
public Schema.sObjectType objType ;
public Map<String,Schema.SObjectField> mapFieldList;
public void getRecordsBasedOnObjectName(string objectName){
query = 'Select ';
schemaGlobalDescription = Schema.getGlobalDescribe();
objType = schemaGlobalDescription.get(objectName);
Schema.DescribeSObjectResult objDescribeSObjectResult = objType.getDescribe();
mapFieldList = objDescribeSObjectResult.fields.getMap();
for(Schema.SObjectField field : mapFieldList.values()){
Schema.DescribeFieldResult fieldResult = field.getDescribe();
if(fieldResult.getName() == 'Id'){
}else{
query += fieldResult.getName()+ ',';
}
}
query += ' Id from '+objectName+' limit 100';
objectDetails = new list<sObject>();
if(String.isNotBlank(query)){
objectDetails = database.query(query);
}
}
}
-------------
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}
var ReferraAccepted = sforce.connection.query("SELECT id from {!Account.Routing_Rule__c} where AccountId ='{!Account.Id}'");
records = ReferraAccepted.getArray("records");
alert(records);
if (!records.length > 0) {
alert("There were no child records been assigned !!")
}
else {
window.open('/apex/RoutingRuleLogic?Id={!Account.Id}&objectName={!Account.Routing_Rule__c}', '_blank', 'height=600,width=600,resizable=yes,scrollbars=yes,toolbar=no,menubar=no');
}
Visualforce Page :
--------------------
<apex:page controller="RoutingRuleLogic_CLS" sidebar="false" showHeader="false">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!objectDetails}" var="a">
<apex:column value="{!a.id}"/>
<apex:column headerValue="Name">
<apex:outputText value="{!a['name']}"/>
</apex:column>
<apex:column headerValue="Email">
<apex:outputText value="{!a['email']}"/>
</apex:column>
<apex:column headerValue="Phone">
<apex:outputText value="{!a['phone']}"/>
</apex:column>
<apex:column headerValue="Account Id">
<apex:outputText value="{!a['Accountid']}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Logic :
---------------
public with sharing class RoutingRuleLogic_CLS {
public string objectName {get;set;}
public String query {get;set;}
public RoutingRuleLogic_CLS(){
objectName = apexpages.currentpage().getparameters().get('objectName');
if(objectName != '' && objectName != NULL){
getRecordsBasedOnObjectName(objectName);
}
}
public list<sObject> objectDetails {get;set;}
public Map<String,Schema.SObjectType> schemaGlobalDescription ;
public Schema.sObjectType objType ;
public Map<String,Schema.SObjectField> mapFieldList;
public void getRecordsBasedOnObjectName(string objectName){
query = 'Select ';
schemaGlobalDescription = Schema.getGlobalDescribe();
objType = schemaGlobalDescription.get(objectName);
Schema.DescribeSObjectResult objDescribeSObjectResult = objType.getDescribe();
mapFieldList = objDescribeSObjectResult.fields.getMap();
for(Schema.SObjectField field : mapFieldList.values()){
Schema.DescribeFieldResult fieldResult = field.getDescribe();
if(fieldResult.getName() == 'Id'){
}else{
query += fieldResult.getName()+ ',';
}
}
query += ' Id from '+objectName+' limit 100';
objectDetails = new list<sObject>();
if(String.isNotBlank(query)){
objectDetails = database.query(query);
}
}
}
No comments:
Post a Comment