-
ChatterFeed
-
0Best Answers
-
1Likes Received
-
0Likes Given
-
6Questions
-
3Replies
getting an error while writing a test class for these class.
public class AddmultipleAccountsController { public String rowNumber { get; set; } public String cnt { get; set; } public String listAccount { get; set; } Offer__c account = new Offer__c(); public list<Offer__c> listOffer{ get; set; } public Offer__c del; public Integer rowIndex {get;set;} public List<Offer__c> dellistOffer {get;set;} public AddmultipleAccountsController() { listOffer=new list<Offer__c>(); listOffer.add(account); } public PageReference deleteRow(){ rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex')); // System.debug('rowbe deleted ' + rowIndex ); //System.debug('rowm to be deleted '+listOffer[rowIndex]); del = listOffer.remove(rowIndex); //dellistOffer.add(del); return Page.dy; } Public void addAccount() { Offer__c acc = new Offer__c(); listOffer.add(acc); } public PageReference saveAccount() { for(Integer i=0; i<listOffer.size(); i++) { insert listOffer; } return Page.dy; } }
- pooja kasliwal
- February 05, 2016
- Like
- 0
Save dynamic values using json
There are dynamic values in my visualforce page and I want to save those values in object using json. But the dynamic value are getting store in a variable and I am unable to pass variable in json string .how can I achieve it please suggest me.
Thanks in advance
Thanks in advance
- pooja kasliwal
- November 24, 2015
- Like
- 0
Dynamically find data type of fields and compare them
Hi Everyone,
There are four picklist one for source object , second for sourcefield( childobject.fieldname of source object) ,another for target object and one for target(childobject.fieldname of target object). now I want to validate sourcefield and target field by their type like type of source field could be anything and type of target field should be string because anything to string type conversion is possible.but I am unable to get type of both the fields.I tried something but its not working properly.Please sugget me how can I achieve it?
Here is the vf code:-
<apex:page controller="ObjectMapper1" sidebar="false" id="page" readOnly="true">
<apex:form id="form">
<apex:pageBlock >
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockSection columns="5" id="pb">
<apex:pageBlockSectionItem >
<apex:outputLabel >Source Objects</apex:outputLabel>
<apex:selectList size="1" value="{!sourceobject}" id="selectobject">
<apex:selectOption itemvalue="--None--"/>
<apex:selectOptions value="{!source_objects}"/>
<apex:actionSupport event="onchange" reRender="form" />
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Source Field</apex:outputLabel>
<apex:selectList size="1" value="{!sourcefield}" id="selectfield" >
<apex:selectOption itemvalue="--None--"/>
<apex:selectOptions value="{!child_Objects}" />
<apex:actionSupport event="onchange" reRender="form"/>
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Target Object</apex:outputLabel>
<apex:selectList size="1" value="{!targetobject}" id="selectobject" >
<apex:selectOption itemvalue="--None--"/>
<apex:selectOptions value="{!target_objects}" />
<apex:actionSupport event="onchange" reRender="form"/>
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Target Field</apex:outputLabel>
<apex:selectList size="1" value="{!targetfield}" id="selectobject">
<apex:selectOptions value="{!child_target_Objects}" />
<apex:actionSupport event="onchange" reRender="form" action="{!error}"/>
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:commandButton value="+" id="thebutton" action="{!AddRecord}" style="width:30px;height:20px" disabled="{!buttonDisable}" reRender="form" />
</apex:pageBlockSection>
<apex:pageBlockTable value="{!objectwrapperlist}" id="bottomsection" var="objwrap" columns="5">
<apex:column headerValue="Source Object">
<apex:outputLabel value="{!objwrap.source_object}" />
</apex:column>
<apex:column headerValue="Source Field">
<apex:outputLabel value="{!objwrap.source_field}" />
</apex:column>
<apex:column headerValue="Target Object">
<apex:outputLabel value="{!objwrap.target_object}" />
</apex:column>
<apex:column width="5%">
<apex:outputLabel >
<apex:commandButton value="-" action="{!removeRecords}" reRender="bottomsection"><apex:param name="val" assignTo="{!index}" value="{!objwrap.index_number}"/></apex:commandbutton>
</apex:outputLabel>
</apex:column>
</apex:pageBlockTable>
</apex:pageblock>
</apex:form>
</apex:page>
Here is the controller:-
public class ObjectMapper1
{
public String target_object { get; set; }
public String sourcefield { get; set; }
public String sourceobject { get; set; }
public Integer counter=0;
public Integer index{get;set;}
public string targetobject{get;set;}
public string targetfield{ get; set; }
boolean buttonDisable;
Schema.DisplayType sourcefielddataType;
Schema.DisplayType targetfielddataType;
/*--------------------------------------------- Method For getting source object -------------------------------------*/
public selectoption[] getsource_objects()
{
selectoption[] source_objects = new selectoption[0];
for (Schema.SObjectType obj: Schema.getGlobalDescribe().values())
{
String name = obj.getDescribe().getName();
if (!obj.getDescribe().isCustomSetting() && obj.getDescribe().getRecordTypeInfos().size() > 0 && obj.getDescribe().isCreateable() &&!name.containsignorecase('history') && !name.containsignorecase('tag') && !name.containsignorecase('share') && !name.containsignorecase('feed')&& !name.containsignorecase('Announcement')&& !name.containsignorecase('CampaignMember')&& !name.containsignorecase('GroupRecord')&& !name.containsignorecase('ContentVersion')&& !name.containsignorecase('Macro')&& !name.containsignorecase('search'))
{
source_objects.add(new SelectOption(obj.getDescribe().getName(), obj.getDescribe().getLabel()));
}
}
source_objects.sort();
return source_objects;
}
/*--------------------------------------------- Method For getting target objects ----------------------------------------------------*/
public selectoption[] gettarget_objects()
{
selectoption[] target_objects = new selectoption[0];
for (Schema.SObjectType obj: Schema.getGlobalDescribe().values())
{
String name = obj.getDescribe().getName();
if (!obj.getDescribe().isCustomSetting() && obj.getDescribe().getRecordTypeInfos().size() > 0 && obj.getDescribe().isCreateable() &&!name.containsignorecase('history') && !name.containsignorecase('tag') && !name.containsignorecase('share') && !name.containsignorecase('feed')&& !name.containsignorecase('Announcement')&& !name.containsignorecase('CampaignMember')&& !name.containsignorecase('GroupRecord')&& !name.containsignorecase('ContentVersion')&& !name.containsignorecase('Macro')&& !name.containsignorecase('search'))
{
target_objects.add(new SelectOption(obj.getDescribe().getName(), obj.getDescribe().getLabel()));
}
}
target_objects.sort();
return target_objects;
}
/*--------------------------------------------- Method For getting related child_source_objects.fieldname ----------------------------------------------------*/
public selectoption[] getchild_Objects()
{
selectoption[] child_Objects = new selectoption[0];
if(sourceobject == '--None--' || sourceobject == null )
{
child_Objects.add(new selectoption('--None--','--None--'));
}
else
{
map<string,string> childObjectsMap = new map<string,string>();
map<string,schema.sobjecttype> describe = schema.getglobaldescribe(); // gives the map of all sobjects
LIST<Schema.childRelationship> childobject = describe.get(sourceobject).getdescribe().getchildRelationships(); // gives the map of all sobjects name and add it to the list
for(Schema.childRelationship child : childObject)
{
childObjectsMap.put(child.getChildSObject().getDescribe().getName(),child.getChildSObject().getDescribe().getLabel());
}
for(string childs :childObjectsMap.keyset())
{
if(!childs.containsignorecase('history') && !childs.containsignorecase('tag') && !childs.containsignorecase('share') && !childs.containsignorecase('feed'))
{
map<string,schema.sobjecttype> descibe = schema.getglobaldescribe(); // gives the map of all sobjects
if(descibe.containskey(childs))
{
map<string,schema.sobjectfield> fieldmap = descibe.get(childs).getdescribe().fields.getmap(); // gives the map of all the fields;
for(string fieldname:fieldmap.keyset())
{
child_Objects.add(new selectoption(childs+'.'+fieldname,childs+'.'+fieldname));
}
//sourcefielddataType = fieldMap.get(sourcefield).getDescribe().getType();
}
}
}
}
return child_Objects;
}
/*-----------------------------------------------------method ----------------------------------------------*/
/*public static String getFieldType(String fieldName){
// Assume that "sObjectName" is populated elsewhere
Schema.SObjectType t = Schema.getGlobalDescribe().get(sObjectName);
Schema.DescribeSObjectResult r = t.getDescribe();
Schema.DescribeFieldResult f = r.fields.getMap().get(fieldName).getDescribe();
if (f.getType() == Schema.DisplayType.String){
return 'String';
} // .... else if
return null;
}*/
/*--------------------------------------------- Method For getting related child_target_objects.fieldname ----------------------------------------------------*/
public selectoption[] getchild_target_Objects()
{
selectoption[] child_target_Objects = new selectoption[0];
if(targetobject== '--None--' || targetobject== null )
{
child_target_Objects.add(new selectoption('--None--','--None--'));
}
else
{
map<string,string> childObjectsMap = new map<string,string>();
map<string,schema.sobjecttype> describe = schema.getglobaldescribe(); // gives the map of all sobjects
LIST<Schema.childRelationship> childobject = describe.get(targetobject).getdescribe().getchildRelationships(); // gives the map of all sobjects name and add it to the list
for(Schema.childRelationship child : childObject)
{
childObjectsMap.put(child.getChildSObject().getDescribe().getName(),child.getChildSObject().getDescribe().getLabel());
}
for(string childs :childObjectsMap.keyset())
{
if(!childs.containsignorecase('history') && !childs.containsignorecase('tag') && !childs.containsignorecase('share') && !childs.containsignorecase('feed'))
{
map<string,schema.sobjecttype> descibe = schema.getglobaldescribe(); // gives the map of all sobjects
if(descibe.containskey(childs))
{
map<string,schema.sobjectfield> fieldmap = descibe.get(childs).getdescribe().fields.getmap(); // gives the map of all the fields;
for(string fieldname:fieldmap.keyset())
{
// targetfielddataType = fieldMap.get(targetfield).getDescribe().getType();
child_target_Objects.add(new selectoption(childs+'.'+fieldname,childs+'.'+fieldname));
}
}
}
}
}
return child_target_Objects;
}
public pageReference AddRecord()
{
ObjectWrapper objwrapper= new ObjectWrapper();
objwrapper.source_object=sourceobject;
objwrapper.source_field= sourcefield;
objwrapper.target_object= targetobject;
objwrapper.target_field= targetfield;
objwrapper.index_number = counter++;
objectwrapperlist.add(objwrapper);
return null;
}
/*--------------------------------------------- Method For Enable and disable '+' button ----------------------------------------------------*/
public boolean getbuttonDisable()
{
if((sourceobject != null && sourceobject != '--None--') && (sourcefield != null && sourcefield != '--None--')&&(targetobject != null && targetobject!= '--None--')&&(targetfield != null && targetfield!= '--None--'))
{
buttonDisable = false;
}
else
{
buttonDisable = true;
}
return buttonDisable;
}
/*------------------------------------------------ Method For displaying error message ----------------------------------------------------*/
public PageReference error()
{
Schema.SObjectType t = Schema.getGlobalDescribe().get(sourceobject);
Schema.DescribeSObjectResult r = t.getDescribe();
Schema.DescribeFieldResult f = r.fields.getMap().get(sourcefield).getDescribe();
system.debug(f.getType());
if(f.getType() == Schema.DisplayType.STRING)/*||
(f.getType() == Schema.DisplayType.BOOLEAN)||
(f.getType() == Schema.DisplayType.DATETIME)||
(f.getType() == Schema.DisplayType.STRING)||
(f.getType() == Schema.DisplayType.CURRENCY)||
(f.getType() == Schema.DisplayType.DOUBLE)||
(f.getType() == Schema.DisplayType.ADDRESS)||
(f.getType() == Schema.DisplayType.PHONE)||
(f.getType() == Schema.DisplayType.DATE)||
(f.getType() == Schema.DisplayType.TEXTAREA)||
(f.getType() == Schema.DisplayType.ID)||
(f.getType() == Schema.DisplayType.URL)||
(f.getType() == Schema.DisplayType.EMAIL))*/
{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Source object and target object can not be same');
ApexPages.addMessage(myMsg);
}
return null;
}
public list<ObjectWrapper> objectwrapperlist{get;set;}
// Constructor of the classs
public ObjectMapper1()
{
this.objectwrapperlist= new list<ObjectWrapper>();
ObjectWrapper objwrapper = new ObjectWrapper();
}
public class ObjectWrapper
{
public string source_object{ get;set;}
public string source_field{get;set;}
public string target_object{get;set;}
public string target_field{get;set;}
public integer index_number{get;set;}
}
/*---------------------------------------- this method is to remove the rows. -----------------------------------------------------------*/
public PageReference removeRecords()
{
for(Integer i=0;i<objectwrapperlist.size();i++)
{
if(objectwrapperlist[i].index_number== index)//1 == 1
{
objectwrapperlist.remove(i);
}
}
counter--;
return null;
}
}
There are four picklist one for source object , second for sourcefield( childobject.fieldname of source object) ,another for target object and one for target(childobject.fieldname of target object). now I want to validate sourcefield and target field by their type like type of source field could be anything and type of target field should be string because anything to string type conversion is possible.but I am unable to get type of both the fields.I tried something but its not working properly.Please sugget me how can I achieve it?
Here is the vf code:-
<apex:page controller="ObjectMapper1" sidebar="false" id="page" readOnly="true">
<apex:form id="form">
<apex:pageBlock >
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockSection columns="5" id="pb">
<apex:pageBlockSectionItem >
<apex:outputLabel >Source Objects</apex:outputLabel>
<apex:selectList size="1" value="{!sourceobject}" id="selectobject">
<apex:selectOption itemvalue="--None--"/>
<apex:selectOptions value="{!source_objects}"/>
<apex:actionSupport event="onchange" reRender="form" />
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Source Field</apex:outputLabel>
<apex:selectList size="1" value="{!sourcefield}" id="selectfield" >
<apex:selectOption itemvalue="--None--"/>
<apex:selectOptions value="{!child_Objects}" />
<apex:actionSupport event="onchange" reRender="form"/>
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Target Object</apex:outputLabel>
<apex:selectList size="1" value="{!targetobject}" id="selectobject" >
<apex:selectOption itemvalue="--None--"/>
<apex:selectOptions value="{!target_objects}" />
<apex:actionSupport event="onchange" reRender="form"/>
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Target Field</apex:outputLabel>
<apex:selectList size="1" value="{!targetfield}" id="selectobject">
<apex:selectOptions value="{!child_target_Objects}" />
<apex:actionSupport event="onchange" reRender="form" action="{!error}"/>
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:commandButton value="+" id="thebutton" action="{!AddRecord}" style="width:30px;height:20px" disabled="{!buttonDisable}" reRender="form" />
</apex:pageBlockSection>
<apex:pageBlockTable value="{!objectwrapperlist}" id="bottomsection" var="objwrap" columns="5">
<apex:column headerValue="Source Object">
<apex:outputLabel value="{!objwrap.source_object}" />
</apex:column>
<apex:column headerValue="Source Field">
<apex:outputLabel value="{!objwrap.source_field}" />
</apex:column>
<apex:column headerValue="Target Object">
<apex:outputLabel value="{!objwrap.target_object}" />
</apex:column>
<apex:column width="5%">
<apex:outputLabel >
<apex:commandButton value="-" action="{!removeRecords}" reRender="bottomsection"><apex:param name="val" assignTo="{!index}" value="{!objwrap.index_number}"/></apex:commandbutton>
</apex:outputLabel>
</apex:column>
</apex:pageBlockTable>
</apex:pageblock>
</apex:form>
</apex:page>
Here is the controller:-
public class ObjectMapper1
{
public String target_object { get; set; }
public String sourcefield { get; set; }
public String sourceobject { get; set; }
public Integer counter=0;
public Integer index{get;set;}
public string targetobject{get;set;}
public string targetfield{ get; set; }
boolean buttonDisable;
Schema.DisplayType sourcefielddataType;
Schema.DisplayType targetfielddataType;
/*--------------------------------------------- Method For getting source object -------------------------------------*/
public selectoption[] getsource_objects()
{
selectoption[] source_objects = new selectoption[0];
for (Schema.SObjectType obj: Schema.getGlobalDescribe().values())
{
String name = obj.getDescribe().getName();
if (!obj.getDescribe().isCustomSetting() && obj.getDescribe().getRecordTypeInfos().size() > 0 && obj.getDescribe().isCreateable() &&!name.containsignorecase('history') && !name.containsignorecase('tag') && !name.containsignorecase('share') && !name.containsignorecase('feed')&& !name.containsignorecase('Announcement')&& !name.containsignorecase('CampaignMember')&& !name.containsignorecase('GroupRecord')&& !name.containsignorecase('ContentVersion')&& !name.containsignorecase('Macro')&& !name.containsignorecase('search'))
{
source_objects.add(new SelectOption(obj.getDescribe().getName(), obj.getDescribe().getLabel()));
}
}
source_objects.sort();
return source_objects;
}
/*--------------------------------------------- Method For getting target objects ----------------------------------------------------*/
public selectoption[] gettarget_objects()
{
selectoption[] target_objects = new selectoption[0];
for (Schema.SObjectType obj: Schema.getGlobalDescribe().values())
{
String name = obj.getDescribe().getName();
if (!obj.getDescribe().isCustomSetting() && obj.getDescribe().getRecordTypeInfos().size() > 0 && obj.getDescribe().isCreateable() &&!name.containsignorecase('history') && !name.containsignorecase('tag') && !name.containsignorecase('share') && !name.containsignorecase('feed')&& !name.containsignorecase('Announcement')&& !name.containsignorecase('CampaignMember')&& !name.containsignorecase('GroupRecord')&& !name.containsignorecase('ContentVersion')&& !name.containsignorecase('Macro')&& !name.containsignorecase('search'))
{
target_objects.add(new SelectOption(obj.getDescribe().getName(), obj.getDescribe().getLabel()));
}
}
target_objects.sort();
return target_objects;
}
/*--------------------------------------------- Method For getting related child_source_objects.fieldname ----------------------------------------------------*/
public selectoption[] getchild_Objects()
{
selectoption[] child_Objects = new selectoption[0];
if(sourceobject == '--None--' || sourceobject == null )
{
child_Objects.add(new selectoption('--None--','--None--'));
}
else
{
map<string,string> childObjectsMap = new map<string,string>();
map<string,schema.sobjecttype> describe = schema.getglobaldescribe(); // gives the map of all sobjects
LIST<Schema.childRelationship> childobject = describe.get(sourceobject).getdescribe().getchildRelationships(); // gives the map of all sobjects name and add it to the list
for(Schema.childRelationship child : childObject)
{
childObjectsMap.put(child.getChildSObject().getDescribe().getName(),child.getChildSObject().getDescribe().getLabel());
}
for(string childs :childObjectsMap.keyset())
{
if(!childs.containsignorecase('history') && !childs.containsignorecase('tag') && !childs.containsignorecase('share') && !childs.containsignorecase('feed'))
{
map<string,schema.sobjecttype> descibe = schema.getglobaldescribe(); // gives the map of all sobjects
if(descibe.containskey(childs))
{
map<string,schema.sobjectfield> fieldmap = descibe.get(childs).getdescribe().fields.getmap(); // gives the map of all the fields;
for(string fieldname:fieldmap.keyset())
{
child_Objects.add(new selectoption(childs+'.'+fieldname,childs+'.'+fieldname));
}
//sourcefielddataType = fieldMap.get(sourcefield).getDescribe().getType();
}
}
}
}
return child_Objects;
}
/*-----------------------------------------------------method ----------------------------------------------*/
/*public static String getFieldType(String fieldName){
// Assume that "sObjectName" is populated elsewhere
Schema.SObjectType t = Schema.getGlobalDescribe().get(sObjectName);
Schema.DescribeSObjectResult r = t.getDescribe();
Schema.DescribeFieldResult f = r.fields.getMap().get(fieldName).getDescribe();
if (f.getType() == Schema.DisplayType.String){
return 'String';
} // .... else if
return null;
}*/
/*--------------------------------------------- Method For getting related child_target_objects.fieldname ----------------------------------------------------*/
public selectoption[] getchild_target_Objects()
{
selectoption[] child_target_Objects = new selectoption[0];
if(targetobject== '--None--' || targetobject== null )
{
child_target_Objects.add(new selectoption('--None--','--None--'));
}
else
{
map<string,string> childObjectsMap = new map<string,string>();
map<string,schema.sobjecttype> describe = schema.getglobaldescribe(); // gives the map of all sobjects
LIST<Schema.childRelationship> childobject = describe.get(targetobject).getdescribe().getchildRelationships(); // gives the map of all sobjects name and add it to the list
for(Schema.childRelationship child : childObject)
{
childObjectsMap.put(child.getChildSObject().getDescribe().getName(),child.getChildSObject().getDescribe().getLabel());
}
for(string childs :childObjectsMap.keyset())
{
if(!childs.containsignorecase('history') && !childs.containsignorecase('tag') && !childs.containsignorecase('share') && !childs.containsignorecase('feed'))
{
map<string,schema.sobjecttype> descibe = schema.getglobaldescribe(); // gives the map of all sobjects
if(descibe.containskey(childs))
{
map<string,schema.sobjectfield> fieldmap = descibe.get(childs).getdescribe().fields.getmap(); // gives the map of all the fields;
for(string fieldname:fieldmap.keyset())
{
// targetfielddataType = fieldMap.get(targetfield).getDescribe().getType();
child_target_Objects.add(new selectoption(childs+'.'+fieldname,childs+'.'+fieldname));
}
}
}
}
}
return child_target_Objects;
}
public pageReference AddRecord()
{
ObjectWrapper objwrapper= new ObjectWrapper();
objwrapper.source_object=sourceobject;
objwrapper.source_field= sourcefield;
objwrapper.target_object= targetobject;
objwrapper.target_field= targetfield;
objwrapper.index_number = counter++;
objectwrapperlist.add(objwrapper);
return null;
}
/*--------------------------------------------- Method For Enable and disable '+' button ----------------------------------------------------*/
public boolean getbuttonDisable()
{
if((sourceobject != null && sourceobject != '--None--') && (sourcefield != null && sourcefield != '--None--')&&(targetobject != null && targetobject!= '--None--')&&(targetfield != null && targetfield!= '--None--'))
{
buttonDisable = false;
}
else
{
buttonDisable = true;
}
return buttonDisable;
}
/*------------------------------------------------ Method For displaying error message ----------------------------------------------------*/
public PageReference error()
{
Schema.SObjectType t = Schema.getGlobalDescribe().get(sourceobject);
Schema.DescribeSObjectResult r = t.getDescribe();
Schema.DescribeFieldResult f = r.fields.getMap().get(sourcefield).getDescribe();
system.debug(f.getType());
if(f.getType() == Schema.DisplayType.STRING)/*||
(f.getType() == Schema.DisplayType.BOOLEAN)||
(f.getType() == Schema.DisplayType.DATETIME)||
(f.getType() == Schema.DisplayType.STRING)||
(f.getType() == Schema.DisplayType.CURRENCY)||
(f.getType() == Schema.DisplayType.DOUBLE)||
(f.getType() == Schema.DisplayType.ADDRESS)||
(f.getType() == Schema.DisplayType.PHONE)||
(f.getType() == Schema.DisplayType.DATE)||
(f.getType() == Schema.DisplayType.TEXTAREA)||
(f.getType() == Schema.DisplayType.ID)||
(f.getType() == Schema.DisplayType.URL)||
(f.getType() == Schema.DisplayType.EMAIL))*/
{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Source object and target object can not be same');
ApexPages.addMessage(myMsg);
}
return null;
}
public list<ObjectWrapper> objectwrapperlist{get;set;}
// Constructor of the classs
public ObjectMapper1()
{
this.objectwrapperlist= new list<ObjectWrapper>();
ObjectWrapper objwrapper = new ObjectWrapper();
}
public class ObjectWrapper
{
public string source_object{ get;set;}
public string source_field{get;set;}
public string target_object{get;set;}
public string target_field{get;set;}
public integer index_number{get;set;}
}
/*---------------------------------------- this method is to remove the rows. -----------------------------------------------------------*/
public PageReference removeRecords()
{
for(Integer i=0;i<objectwrapperlist.size();i++)
{
if(objectwrapperlist[i].index_number== index)//1 == 1
{
objectwrapperlist.remove(i);
}
}
counter--;
return null;
}
}
- pooja kasliwal
- November 19, 2015
- Like
- 0
Field Mapping Of Two System Objects
Hello Everyone ,
There are four picklist on a visualforce page , one picklist is for all source objects and one is for their corresponding fields. and the other two picklists are for corresponding child objects of source object and their corresponding fields .I want to map fields of source object with fields of target object( which is the corresponding child objects of source object). Please suggest how can i achieve it?
There are four picklist on a visualforce page , one picklist is for all source objects and one is for their corresponding fields. and the other two picklists are for corresponding child objects of source object and their corresponding fields .I want to map fields of source object with fields of target object( which is the corresponding child objects of source object). Please suggest how can i achieve it?
- pooja kasliwal
- November 16, 2015
- Like
- 0
Display Type Of Object
Hello Everyone,
I want to display the relationship between two objects(MD or Lookup) on visualforce page and If i choose one object from one picklist then it shoul show picklist of its all related obejct and their relationship type (MD or Lookup) on vf.how can i achieve it??
Thanks in advance..
I want to display the relationship between two objects(MD or Lookup) on visualforce page and If i choose one object from one picklist then it shoul show picklist of its all related obejct and their relationship type (MD or Lookup) on vf.how can i achieve it??
Thanks in advance..
- pooja kasliwal
- October 31, 2015
- Like
- 1
Field Mapping In Visualforce
Hello,
How can I achieve field mapping in visualforce for all object, like the below snapshot ??
Thanks in advance
How can I achieve field mapping in visualforce for all object, like the below snapshot ??
Thanks in advance
- pooja kasliwal
- October 30, 2015
- Like
- 0
Display Type Of Object
Hello Everyone,
I want to display the relationship between two objects(MD or Lookup) on visualforce page and If i choose one object from one picklist then it shoul show picklist of its all related obejct and their relationship type (MD or Lookup) on vf.how can i achieve it??
Thanks in advance..
I want to display the relationship between two objects(MD or Lookup) on visualforce page and If i choose one object from one picklist then it shoul show picklist of its all related obejct and their relationship type (MD or Lookup) on vf.how can i achieve it??
Thanks in advance..
- pooja kasliwal
- October 31, 2015
- Like
- 1
getting an error while writing a test class for these class.
public class AddmultipleAccountsController { public String rowNumber { get; set; } public String cnt { get; set; } public String listAccount { get; set; } Offer__c account = new Offer__c(); public list<Offer__c> listOffer{ get; set; } public Offer__c del; public Integer rowIndex {get;set;} public List<Offer__c> dellistOffer {get;set;} public AddmultipleAccountsController() { listOffer=new list<Offer__c>(); listOffer.add(account); } public PageReference deleteRow(){ rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex')); // System.debug('rowbe deleted ' + rowIndex ); //System.debug('rowm to be deleted '+listOffer[rowIndex]); del = listOffer.remove(rowIndex); //dellistOffer.add(del); return Page.dy; } Public void addAccount() { Offer__c acc = new Offer__c(); listOffer.add(acc); } public PageReference saveAccount() { for(Integer i=0; i<listOffer.size(); i++) { insert listOffer; } return Page.dy; } }
- pooja kasliwal
- February 05, 2016
- Like
- 0
Save dynamic values using json
There are dynamic values in my visualforce page and I want to save those values in object using json. But the dynamic value are getting store in a variable and I am unable to pass variable in json string .how can I achieve it please suggest me.
Thanks in advance
Thanks in advance
- pooja kasliwal
- November 24, 2015
- Like
- 0
Dynamically find data type of fields and compare them
Hi Everyone,
There are four picklist one for source object , second for sourcefield( childobject.fieldname of source object) ,another for target object and one for target(childobject.fieldname of target object). now I want to validate sourcefield and target field by their type like type of source field could be anything and type of target field should be string because anything to string type conversion is possible.but I am unable to get type of both the fields.I tried something but its not working properly.Please sugget me how can I achieve it?
Here is the vf code:-
<apex:page controller="ObjectMapper1" sidebar="false" id="page" readOnly="true">
<apex:form id="form">
<apex:pageBlock >
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockSection columns="5" id="pb">
<apex:pageBlockSectionItem >
<apex:outputLabel >Source Objects</apex:outputLabel>
<apex:selectList size="1" value="{!sourceobject}" id="selectobject">
<apex:selectOption itemvalue="--None--"/>
<apex:selectOptions value="{!source_objects}"/>
<apex:actionSupport event="onchange" reRender="form" />
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Source Field</apex:outputLabel>
<apex:selectList size="1" value="{!sourcefield}" id="selectfield" >
<apex:selectOption itemvalue="--None--"/>
<apex:selectOptions value="{!child_Objects}" />
<apex:actionSupport event="onchange" reRender="form"/>
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Target Object</apex:outputLabel>
<apex:selectList size="1" value="{!targetobject}" id="selectobject" >
<apex:selectOption itemvalue="--None--"/>
<apex:selectOptions value="{!target_objects}" />
<apex:actionSupport event="onchange" reRender="form"/>
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Target Field</apex:outputLabel>
<apex:selectList size="1" value="{!targetfield}" id="selectobject">
<apex:selectOptions value="{!child_target_Objects}" />
<apex:actionSupport event="onchange" reRender="form" action="{!error}"/>
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:commandButton value="+" id="thebutton" action="{!AddRecord}" style="width:30px;height:20px" disabled="{!buttonDisable}" reRender="form" />
</apex:pageBlockSection>
<apex:pageBlockTable value="{!objectwrapperlist}" id="bottomsection" var="objwrap" columns="5">
<apex:column headerValue="Source Object">
<apex:outputLabel value="{!objwrap.source_object}" />
</apex:column>
<apex:column headerValue="Source Field">
<apex:outputLabel value="{!objwrap.source_field}" />
</apex:column>
<apex:column headerValue="Target Object">
<apex:outputLabel value="{!objwrap.target_object}" />
</apex:column>
<apex:column width="5%">
<apex:outputLabel >
<apex:commandButton value="-" action="{!removeRecords}" reRender="bottomsection"><apex:param name="val" assignTo="{!index}" value="{!objwrap.index_number}"/></apex:commandbutton>
</apex:outputLabel>
</apex:column>
</apex:pageBlockTable>
</apex:pageblock>
</apex:form>
</apex:page>
Here is the controller:-
public class ObjectMapper1
{
public String target_object { get; set; }
public String sourcefield { get; set; }
public String sourceobject { get; set; }
public Integer counter=0;
public Integer index{get;set;}
public string targetobject{get;set;}
public string targetfield{ get; set; }
boolean buttonDisable;
Schema.DisplayType sourcefielddataType;
Schema.DisplayType targetfielddataType;
/*--------------------------------------------- Method For getting source object -------------------------------------*/
public selectoption[] getsource_objects()
{
selectoption[] source_objects = new selectoption[0];
for (Schema.SObjectType obj: Schema.getGlobalDescribe().values())
{
String name = obj.getDescribe().getName();
if (!obj.getDescribe().isCustomSetting() && obj.getDescribe().getRecordTypeInfos().size() > 0 && obj.getDescribe().isCreateable() &&!name.containsignorecase('history') && !name.containsignorecase('tag') && !name.containsignorecase('share') && !name.containsignorecase('feed')&& !name.containsignorecase('Announcement')&& !name.containsignorecase('CampaignMember')&& !name.containsignorecase('GroupRecord')&& !name.containsignorecase('ContentVersion')&& !name.containsignorecase('Macro')&& !name.containsignorecase('search'))
{
source_objects.add(new SelectOption(obj.getDescribe().getName(), obj.getDescribe().getLabel()));
}
}
source_objects.sort();
return source_objects;
}
/*--------------------------------------------- Method For getting target objects ----------------------------------------------------*/
public selectoption[] gettarget_objects()
{
selectoption[] target_objects = new selectoption[0];
for (Schema.SObjectType obj: Schema.getGlobalDescribe().values())
{
String name = obj.getDescribe().getName();
if (!obj.getDescribe().isCustomSetting() && obj.getDescribe().getRecordTypeInfos().size() > 0 && obj.getDescribe().isCreateable() &&!name.containsignorecase('history') && !name.containsignorecase('tag') && !name.containsignorecase('share') && !name.containsignorecase('feed')&& !name.containsignorecase('Announcement')&& !name.containsignorecase('CampaignMember')&& !name.containsignorecase('GroupRecord')&& !name.containsignorecase('ContentVersion')&& !name.containsignorecase('Macro')&& !name.containsignorecase('search'))
{
target_objects.add(new SelectOption(obj.getDescribe().getName(), obj.getDescribe().getLabel()));
}
}
target_objects.sort();
return target_objects;
}
/*--------------------------------------------- Method For getting related child_source_objects.fieldname ----------------------------------------------------*/
public selectoption[] getchild_Objects()
{
selectoption[] child_Objects = new selectoption[0];
if(sourceobject == '--None--' || sourceobject == null )
{
child_Objects.add(new selectoption('--None--','--None--'));
}
else
{
map<string,string> childObjectsMap = new map<string,string>();
map<string,schema.sobjecttype> describe = schema.getglobaldescribe(); // gives the map of all sobjects
LIST<Schema.childRelationship> childobject = describe.get(sourceobject).getdescribe().getchildRelationships(); // gives the map of all sobjects name and add it to the list
for(Schema.childRelationship child : childObject)
{
childObjectsMap.put(child.getChildSObject().getDescribe().getName(),child.getChildSObject().getDescribe().getLabel());
}
for(string childs :childObjectsMap.keyset())
{
if(!childs.containsignorecase('history') && !childs.containsignorecase('tag') && !childs.containsignorecase('share') && !childs.containsignorecase('feed'))
{
map<string,schema.sobjecttype> descibe = schema.getglobaldescribe(); // gives the map of all sobjects
if(descibe.containskey(childs))
{
map<string,schema.sobjectfield> fieldmap = descibe.get(childs).getdescribe().fields.getmap(); // gives the map of all the fields;
for(string fieldname:fieldmap.keyset())
{
child_Objects.add(new selectoption(childs+'.'+fieldname,childs+'.'+fieldname));
}
//sourcefielddataType = fieldMap.get(sourcefield).getDescribe().getType();
}
}
}
}
return child_Objects;
}
/*-----------------------------------------------------method ----------------------------------------------*/
/*public static String getFieldType(String fieldName){
// Assume that "sObjectName" is populated elsewhere
Schema.SObjectType t = Schema.getGlobalDescribe().get(sObjectName);
Schema.DescribeSObjectResult r = t.getDescribe();
Schema.DescribeFieldResult f = r.fields.getMap().get(fieldName).getDescribe();
if (f.getType() == Schema.DisplayType.String){
return 'String';
} // .... else if
return null;
}*/
/*--------------------------------------------- Method For getting related child_target_objects.fieldname ----------------------------------------------------*/
public selectoption[] getchild_target_Objects()
{
selectoption[] child_target_Objects = new selectoption[0];
if(targetobject== '--None--' || targetobject== null )
{
child_target_Objects.add(new selectoption('--None--','--None--'));
}
else
{
map<string,string> childObjectsMap = new map<string,string>();
map<string,schema.sobjecttype> describe = schema.getglobaldescribe(); // gives the map of all sobjects
LIST<Schema.childRelationship> childobject = describe.get(targetobject).getdescribe().getchildRelationships(); // gives the map of all sobjects name and add it to the list
for(Schema.childRelationship child : childObject)
{
childObjectsMap.put(child.getChildSObject().getDescribe().getName(),child.getChildSObject().getDescribe().getLabel());
}
for(string childs :childObjectsMap.keyset())
{
if(!childs.containsignorecase('history') && !childs.containsignorecase('tag') && !childs.containsignorecase('share') && !childs.containsignorecase('feed'))
{
map<string,schema.sobjecttype> descibe = schema.getglobaldescribe(); // gives the map of all sobjects
if(descibe.containskey(childs))
{
map<string,schema.sobjectfield> fieldmap = descibe.get(childs).getdescribe().fields.getmap(); // gives the map of all the fields;
for(string fieldname:fieldmap.keyset())
{
// targetfielddataType = fieldMap.get(targetfield).getDescribe().getType();
child_target_Objects.add(new selectoption(childs+'.'+fieldname,childs+'.'+fieldname));
}
}
}
}
}
return child_target_Objects;
}
public pageReference AddRecord()
{
ObjectWrapper objwrapper= new ObjectWrapper();
objwrapper.source_object=sourceobject;
objwrapper.source_field= sourcefield;
objwrapper.target_object= targetobject;
objwrapper.target_field= targetfield;
objwrapper.index_number = counter++;
objectwrapperlist.add(objwrapper);
return null;
}
/*--------------------------------------------- Method For Enable and disable '+' button ----------------------------------------------------*/
public boolean getbuttonDisable()
{
if((sourceobject != null && sourceobject != '--None--') && (sourcefield != null && sourcefield != '--None--')&&(targetobject != null && targetobject!= '--None--')&&(targetfield != null && targetfield!= '--None--'))
{
buttonDisable = false;
}
else
{
buttonDisable = true;
}
return buttonDisable;
}
/*------------------------------------------------ Method For displaying error message ----------------------------------------------------*/
public PageReference error()
{
Schema.SObjectType t = Schema.getGlobalDescribe().get(sourceobject);
Schema.DescribeSObjectResult r = t.getDescribe();
Schema.DescribeFieldResult f = r.fields.getMap().get(sourcefield).getDescribe();
system.debug(f.getType());
if(f.getType() == Schema.DisplayType.STRING)/*||
(f.getType() == Schema.DisplayType.BOOLEAN)||
(f.getType() == Schema.DisplayType.DATETIME)||
(f.getType() == Schema.DisplayType.STRING)||
(f.getType() == Schema.DisplayType.CURRENCY)||
(f.getType() == Schema.DisplayType.DOUBLE)||
(f.getType() == Schema.DisplayType.ADDRESS)||
(f.getType() == Schema.DisplayType.PHONE)||
(f.getType() == Schema.DisplayType.DATE)||
(f.getType() == Schema.DisplayType.TEXTAREA)||
(f.getType() == Schema.DisplayType.ID)||
(f.getType() == Schema.DisplayType.URL)||
(f.getType() == Schema.DisplayType.EMAIL))*/
{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Source object and target object can not be same');
ApexPages.addMessage(myMsg);
}
return null;
}
public list<ObjectWrapper> objectwrapperlist{get;set;}
// Constructor of the classs
public ObjectMapper1()
{
this.objectwrapperlist= new list<ObjectWrapper>();
ObjectWrapper objwrapper = new ObjectWrapper();
}
public class ObjectWrapper
{
public string source_object{ get;set;}
public string source_field{get;set;}
public string target_object{get;set;}
public string target_field{get;set;}
public integer index_number{get;set;}
}
/*---------------------------------------- this method is to remove the rows. -----------------------------------------------------------*/
public PageReference removeRecords()
{
for(Integer i=0;i<objectwrapperlist.size();i++)
{
if(objectwrapperlist[i].index_number== index)//1 == 1
{
objectwrapperlist.remove(i);
}
}
counter--;
return null;
}
}
There are four picklist one for source object , second for sourcefield( childobject.fieldname of source object) ,another for target object and one for target(childobject.fieldname of target object). now I want to validate sourcefield and target field by their type like type of source field could be anything and type of target field should be string because anything to string type conversion is possible.but I am unable to get type of both the fields.I tried something but its not working properly.Please sugget me how can I achieve it?
Here is the vf code:-
<apex:page controller="ObjectMapper1" sidebar="false" id="page" readOnly="true">
<apex:form id="form">
<apex:pageBlock >
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockSection columns="5" id="pb">
<apex:pageBlockSectionItem >
<apex:outputLabel >Source Objects</apex:outputLabel>
<apex:selectList size="1" value="{!sourceobject}" id="selectobject">
<apex:selectOption itemvalue="--None--"/>
<apex:selectOptions value="{!source_objects}"/>
<apex:actionSupport event="onchange" reRender="form" />
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Source Field</apex:outputLabel>
<apex:selectList size="1" value="{!sourcefield}" id="selectfield" >
<apex:selectOption itemvalue="--None--"/>
<apex:selectOptions value="{!child_Objects}" />
<apex:actionSupport event="onchange" reRender="form"/>
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Target Object</apex:outputLabel>
<apex:selectList size="1" value="{!targetobject}" id="selectobject" >
<apex:selectOption itemvalue="--None--"/>
<apex:selectOptions value="{!target_objects}" />
<apex:actionSupport event="onchange" reRender="form"/>
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Target Field</apex:outputLabel>
<apex:selectList size="1" value="{!targetfield}" id="selectobject">
<apex:selectOptions value="{!child_target_Objects}" />
<apex:actionSupport event="onchange" reRender="form" action="{!error}"/>
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:commandButton value="+" id="thebutton" action="{!AddRecord}" style="width:30px;height:20px" disabled="{!buttonDisable}" reRender="form" />
</apex:pageBlockSection>
<apex:pageBlockTable value="{!objectwrapperlist}" id="bottomsection" var="objwrap" columns="5">
<apex:column headerValue="Source Object">
<apex:outputLabel value="{!objwrap.source_object}" />
</apex:column>
<apex:column headerValue="Source Field">
<apex:outputLabel value="{!objwrap.source_field}" />
</apex:column>
<apex:column headerValue="Target Object">
<apex:outputLabel value="{!objwrap.target_object}" />
</apex:column>
<apex:column width="5%">
<apex:outputLabel >
<apex:commandButton value="-" action="{!removeRecords}" reRender="bottomsection"><apex:param name="val" assignTo="{!index}" value="{!objwrap.index_number}"/></apex:commandbutton>
</apex:outputLabel>
</apex:column>
</apex:pageBlockTable>
</apex:pageblock>
</apex:form>
</apex:page>
Here is the controller:-
public class ObjectMapper1
{
public String target_object { get; set; }
public String sourcefield { get; set; }
public String sourceobject { get; set; }
public Integer counter=0;
public Integer index{get;set;}
public string targetobject{get;set;}
public string targetfield{ get; set; }
boolean buttonDisable;
Schema.DisplayType sourcefielddataType;
Schema.DisplayType targetfielddataType;
/*--------------------------------------------- Method For getting source object -------------------------------------*/
public selectoption[] getsource_objects()
{
selectoption[] source_objects = new selectoption[0];
for (Schema.SObjectType obj: Schema.getGlobalDescribe().values())
{
String name = obj.getDescribe().getName();
if (!obj.getDescribe().isCustomSetting() && obj.getDescribe().getRecordTypeInfos().size() > 0 && obj.getDescribe().isCreateable() &&!name.containsignorecase('history') && !name.containsignorecase('tag') && !name.containsignorecase('share') && !name.containsignorecase('feed')&& !name.containsignorecase('Announcement')&& !name.containsignorecase('CampaignMember')&& !name.containsignorecase('GroupRecord')&& !name.containsignorecase('ContentVersion')&& !name.containsignorecase('Macro')&& !name.containsignorecase('search'))
{
source_objects.add(new SelectOption(obj.getDescribe().getName(), obj.getDescribe().getLabel()));
}
}
source_objects.sort();
return source_objects;
}
/*--------------------------------------------- Method For getting target objects ----------------------------------------------------*/
public selectoption[] gettarget_objects()
{
selectoption[] target_objects = new selectoption[0];
for (Schema.SObjectType obj: Schema.getGlobalDescribe().values())
{
String name = obj.getDescribe().getName();
if (!obj.getDescribe().isCustomSetting() && obj.getDescribe().getRecordTypeInfos().size() > 0 && obj.getDescribe().isCreateable() &&!name.containsignorecase('history') && !name.containsignorecase('tag') && !name.containsignorecase('share') && !name.containsignorecase('feed')&& !name.containsignorecase('Announcement')&& !name.containsignorecase('CampaignMember')&& !name.containsignorecase('GroupRecord')&& !name.containsignorecase('ContentVersion')&& !name.containsignorecase('Macro')&& !name.containsignorecase('search'))
{
target_objects.add(new SelectOption(obj.getDescribe().getName(), obj.getDescribe().getLabel()));
}
}
target_objects.sort();
return target_objects;
}
/*--------------------------------------------- Method For getting related child_source_objects.fieldname ----------------------------------------------------*/
public selectoption[] getchild_Objects()
{
selectoption[] child_Objects = new selectoption[0];
if(sourceobject == '--None--' || sourceobject == null )
{
child_Objects.add(new selectoption('--None--','--None--'));
}
else
{
map<string,string> childObjectsMap = new map<string,string>();
map<string,schema.sobjecttype> describe = schema.getglobaldescribe(); // gives the map of all sobjects
LIST<Schema.childRelationship> childobject = describe.get(sourceobject).getdescribe().getchildRelationships(); // gives the map of all sobjects name and add it to the list
for(Schema.childRelationship child : childObject)
{
childObjectsMap.put(child.getChildSObject().getDescribe().getName(),child.getChildSObject().getDescribe().getLabel());
}
for(string childs :childObjectsMap.keyset())
{
if(!childs.containsignorecase('history') && !childs.containsignorecase('tag') && !childs.containsignorecase('share') && !childs.containsignorecase('feed'))
{
map<string,schema.sobjecttype> descibe = schema.getglobaldescribe(); // gives the map of all sobjects
if(descibe.containskey(childs))
{
map<string,schema.sobjectfield> fieldmap = descibe.get(childs).getdescribe().fields.getmap(); // gives the map of all the fields;
for(string fieldname:fieldmap.keyset())
{
child_Objects.add(new selectoption(childs+'.'+fieldname,childs+'.'+fieldname));
}
//sourcefielddataType = fieldMap.get(sourcefield).getDescribe().getType();
}
}
}
}
return child_Objects;
}
/*-----------------------------------------------------method ----------------------------------------------*/
/*public static String getFieldType(String fieldName){
// Assume that "sObjectName" is populated elsewhere
Schema.SObjectType t = Schema.getGlobalDescribe().get(sObjectName);
Schema.DescribeSObjectResult r = t.getDescribe();
Schema.DescribeFieldResult f = r.fields.getMap().get(fieldName).getDescribe();
if (f.getType() == Schema.DisplayType.String){
return 'String';
} // .... else if
return null;
}*/
/*--------------------------------------------- Method For getting related child_target_objects.fieldname ----------------------------------------------------*/
public selectoption[] getchild_target_Objects()
{
selectoption[] child_target_Objects = new selectoption[0];
if(targetobject== '--None--' || targetobject== null )
{
child_target_Objects.add(new selectoption('--None--','--None--'));
}
else
{
map<string,string> childObjectsMap = new map<string,string>();
map<string,schema.sobjecttype> describe = schema.getglobaldescribe(); // gives the map of all sobjects
LIST<Schema.childRelationship> childobject = describe.get(targetobject).getdescribe().getchildRelationships(); // gives the map of all sobjects name and add it to the list
for(Schema.childRelationship child : childObject)
{
childObjectsMap.put(child.getChildSObject().getDescribe().getName(),child.getChildSObject().getDescribe().getLabel());
}
for(string childs :childObjectsMap.keyset())
{
if(!childs.containsignorecase('history') && !childs.containsignorecase('tag') && !childs.containsignorecase('share') && !childs.containsignorecase('feed'))
{
map<string,schema.sobjecttype> descibe = schema.getglobaldescribe(); // gives the map of all sobjects
if(descibe.containskey(childs))
{
map<string,schema.sobjectfield> fieldmap = descibe.get(childs).getdescribe().fields.getmap(); // gives the map of all the fields;
for(string fieldname:fieldmap.keyset())
{
// targetfielddataType = fieldMap.get(targetfield).getDescribe().getType();
child_target_Objects.add(new selectoption(childs+'.'+fieldname,childs+'.'+fieldname));
}
}
}
}
}
return child_target_Objects;
}
public pageReference AddRecord()
{
ObjectWrapper objwrapper= new ObjectWrapper();
objwrapper.source_object=sourceobject;
objwrapper.source_field= sourcefield;
objwrapper.target_object= targetobject;
objwrapper.target_field= targetfield;
objwrapper.index_number = counter++;
objectwrapperlist.add(objwrapper);
return null;
}
/*--------------------------------------------- Method For Enable and disable '+' button ----------------------------------------------------*/
public boolean getbuttonDisable()
{
if((sourceobject != null && sourceobject != '--None--') && (sourcefield != null && sourcefield != '--None--')&&(targetobject != null && targetobject!= '--None--')&&(targetfield != null && targetfield!= '--None--'))
{
buttonDisable = false;
}
else
{
buttonDisable = true;
}
return buttonDisable;
}
/*------------------------------------------------ Method For displaying error message ----------------------------------------------------*/
public PageReference error()
{
Schema.SObjectType t = Schema.getGlobalDescribe().get(sourceobject);
Schema.DescribeSObjectResult r = t.getDescribe();
Schema.DescribeFieldResult f = r.fields.getMap().get(sourcefield).getDescribe();
system.debug(f.getType());
if(f.getType() == Schema.DisplayType.STRING)/*||
(f.getType() == Schema.DisplayType.BOOLEAN)||
(f.getType() == Schema.DisplayType.DATETIME)||
(f.getType() == Schema.DisplayType.STRING)||
(f.getType() == Schema.DisplayType.CURRENCY)||
(f.getType() == Schema.DisplayType.DOUBLE)||
(f.getType() == Schema.DisplayType.ADDRESS)||
(f.getType() == Schema.DisplayType.PHONE)||
(f.getType() == Schema.DisplayType.DATE)||
(f.getType() == Schema.DisplayType.TEXTAREA)||
(f.getType() == Schema.DisplayType.ID)||
(f.getType() == Schema.DisplayType.URL)||
(f.getType() == Schema.DisplayType.EMAIL))*/
{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Source object and target object can not be same');
ApexPages.addMessage(myMsg);
}
return null;
}
public list<ObjectWrapper> objectwrapperlist{get;set;}
// Constructor of the classs
public ObjectMapper1()
{
this.objectwrapperlist= new list<ObjectWrapper>();
ObjectWrapper objwrapper = new ObjectWrapper();
}
public class ObjectWrapper
{
public string source_object{ get;set;}
public string source_field{get;set;}
public string target_object{get;set;}
public string target_field{get;set;}
public integer index_number{get;set;}
}
/*---------------------------------------- this method is to remove the rows. -----------------------------------------------------------*/
public PageReference removeRecords()
{
for(Integer i=0;i<objectwrapperlist.size();i++)
{
if(objectwrapperlist[i].index_number== index)//1 == 1
{
objectwrapperlist.remove(i);
}
}
counter--;
return null;
}
}
- pooja kasliwal
- November 19, 2015
- Like
- 0