You need to sign in to do that
Don't have an account?
Venkatesh S
how to update detail field in self relationship(challenging)
hello all,
i am newbie to apex coding.
i am stuck in this scenerio. I cannot able to update the field in a case object which is a detail of the self lookup. Please help me to break the challenge. The coding is as follows, the main error is in "update t2", its in last line...some looping problem
Thank yo so much in advance...
trigger complex on Case (before insert, after update) {
set<id> casid = new set<id>();
set<id> curid = new set<id>();
set<String> cassta = new set<String>();
list<Case> multi=new list<Case>();
for(Case c:Trigger.new){
if(c.status__c=='closed'){
cassta.add(c.status__c);
curid.add(c.id);
if(c.Case__c != null)
casid.add(c.Case__c);
}
}
if(casid.size()>0)
{
list<Case> t1=[select id,Case__c,status__c from Case Where id IN :casid];
for(Case q2:t1)
{
q2.status__c='closed';
}
update t1;
}
else
{
list<Case> t2=[select status__c from Case Where Case__c IN :curid];
for(Case q1:t2)
{
q1.status__c='closed';
}
update t2;
}
}
i am newbie to apex coding.
i am stuck in this scenerio. I cannot able to update the field in a case object which is a detail of the self lookup. Please help me to break the challenge. The coding is as follows, the main error is in "update t2", its in last line...some looping problem
Thank yo so much in advance...
trigger complex on Case (before insert, after update) {
set<id> casid = new set<id>();
set<id> curid = new set<id>();
set<String> cassta = new set<String>();
list<Case> multi=new list<Case>();
for(Case c:Trigger.new){
if(c.status__c=='closed'){
cassta.add(c.status__c);
curid.add(c.id);
if(c.Case__c != null)
casid.add(c.Case__c);
}
}
if(casid.size()>0)
{
list<Case> t1=[select id,Case__c,status__c from Case Where id IN :casid];
for(Case q2:t1)
{
q2.status__c='closed';
}
update t1;
}
else
{
list<Case> t2=[select status__c from Case Where Case__c IN :curid];
for(Case q1:t2)
{
q1.status__c='closed';
}
update t2;
}
}
You need to implement a static boolean in a helper class that's created for the instance of the call to your trigger.
This article should help;
http://help.salesforce.com/apex/HTViewSolution?id=000133752&language=en_US
All Answers
You should select the Id from your SOQL statement;
Try that and see what happens....
Also, you should have posted the error message in your question.
i did update soql with id, no use
by the way, the error is as follows
Review all error messages below to correct your data.
Apex trigger complex caused an unexpected exception, contact your administrator: complex: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 5009000000NFZvvAAH; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, complex: maximum trigger depth exceeded Case trigger event AfterUpdate for [5009000000NFZvW] Case trigger event AfterUpdate for [5009000000NFZvv] Case trigger event AfterUpdate for [5009000000NFZvW] Case trigger event AfterUpdate for [5009000000NFZvv] Case trigger event AfterUpdate for [5009000000NFZvW] Case trigger event AfterUpdate for [5009000000NFZvv] Case trigger event AfterUpdate for [5009000000NFZvW] Case trigger event AfterUpdate for [5009000000NFZvv] Case trigger event AfterUpdate for [5009000000NFZvW] Case trigger event AfterUpdate for [5009000000NFZvv] Case trigger event AfterUpdate for [5009000000NFZvW] Case trigger event AfterUpdate for [5009000000NFZvv] Case trigger event AfterUpdate for [5009000000NFZvW] Case trigger event AfterUpdate for [5009000000NFZvv] Case trigger event AfterUpdate for [5009000000NFZvW] Case trigger event AfterUpdate for [5009000000NFZvv]: []: Trigger.complex: line 30, column 1
You need to implement a static boolean in a helper class that's created for the instance of the call to your trigger.
This article should help;
http://help.salesforce.com/apex/HTViewSolution?id=000133752&language=en_US