You need to sign in to do that
Don't have an account?
System.LimitException: DML currently not allowed
Well,
i'm trying to do display all properties from any object from its ID in a component, I already have the next problem whe I try to update a sObject. So, Please I would like to know how to solve this. Please Help me.
My controller is...
................................
public with sharing class GenericObject {
public sObject gObject { get; set; }
public string id{ get; set; }
public List<string> describeList { get; set; }
public GenericObject()
{
describeList = new List<string>();
try{
id = Apexpages.currentPage().getParameters().get('id');
gObject = getObject(id);
}
catch(Exception e)
{
//myMsg = new Apexpages.Message(ApexPages.Severity.ERROR,'Error 111 : No Id was identify ');
//Apexpages.addMessage(myMsg);
// System.debug('Error 111 : No Id was identify ');
}
}
public sObject getObject(string idObject)
{
String s=idObject;
String id ='id';
String objectName = getObjectName(s);
Schema.SObjectType tobj = getObjectTypeFromId(idObject);
Map<String, Schema.SObjectField> allFields = tobj.getDescribe().fields.getMap();
String fieldToShowString='';
for(Schema.SObjectField df : allfields.values())
{
Schema.Describefieldresult res = df.getDescribe();
fieldToShowString+=res.getName()+',';
}
String soqlQuery = 'SELECT ' +fieldToShowString.subString(0,fieldToShowString.length()-1)
+' FROM '+objectName +' WHERE Id=\''+idObject+'\' LIMIT 1';
sObject L = DataBase.Query(soqlQuery);
/// Geting the describtion of an object
for(Schema.SObjectField df : allfields.values())
{
Schema.Describefieldresult res = df.getDescribe();
try{
string k=(string)L.get(res.getName());
if(k!=null)
{
// myMsg = new Apexpages.Message(ApexPages.Severity.ERROR,res.getName()+': '+k);
// Apexpages.addMessage(myMsg);
describeList.add(res.getName());
}
continue;
}catch(exception ex)
{
}
try{
Date k=(Date)L.get(res.getName());
if(k!=null)
{
// myMsg = new Apexpages.Message(ApexPages.Severity.ERROR,res.getName()+': '+k);
// Apexpages.addMessage(myMsg);
}
continue;
describeList.add(res.getName());
}catch(exception ex)
{
}
try{
Integer k=(Integer)L.get(res.getName());
if(k!=null)
{
// myMsg = new Apexpages.Message(ApexPages.Severity.ERROR,res.getName()+': '+k);
// Apexpages.addMessage(myMsg);
}
continue;
describeList.add(res.getName());
}catch(exception ex)
{
}
// describeList.add(res.getName());
}
return L;
}
private String getObjectName(string idObject)
{
String accId = idObject;
String keyCode = accId.subString(0,3);
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
for(Schema.SObjectType objectInstance : gd.values())
{
if(objectInstance.getDescribe().getKeyPrefix() == keyCode)
{
//Process with the API name what you want
System.debug('Id is related to object: '+ objectInstance.getDescribe().getName());
// myMsg = new Apexpages.Message(ApexPages.Severity.ERROR,'Object you are displaying > '+objectInstance.getDescribe().getName());
// Apexpages.addMessage(myMsg);
return objectInstance.getDescribe().getName();
}
}
return null;
}
private Schema.SObjectType getObjectTypeFromId(String idObject)
{
return ((ID)idObject).getSObjectType();
}
public void save(){
update gObject;
}
}
------------------- And My component is
<apex:component controller="GenericObject">
<apex:form >
<apex:pageblock title="Generic Object" >
<apex:pageBlockSection title="Generic Object">
<apex:repeat value="{!describeList}" var="op">
<apex:outputField value="{!gObject[op]}" />
</apex:repeat>
<apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" hideOnEdit="editButton"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<!-- <apex:commandButton value="Edit" action="{!save}" id="editButton" /> -->
<apex:commandButton value="Save" action="{!save}" id="saveButton" />
<apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
</apex:pageBlockButtons>
</apex:pageblock>
</apex:form>
</apex:component>
--------------------- I try to Save Button Works !!! and i cannot do that.
I have the next error
System.LimitException: DML currently not allowed
Class.GenericObject.save: line 120, column 1
Please try using allowDML="true" in your component:
<apex:component controller="GenericObject">
Let me know if it worked for you.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
All Answers
Please try using allowDML="true" in your component:
<apex:component controller="GenericObject">
Let me know if it worked for you.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Hi Ankit Arora
It Works... Really Thanks
Atte. Mijael Vargas