You need to sign in to do that
Don't have an account?
deepakM
How to retrive id of object in trigger.isdelete
hi everyone
i have one trigger senario like:
trigger FFTrigger on FF__c (after insert,after update,before delete) {
//ff object
if(ff != null && Trigger.isDelete)
{
System.debug('TriggerDelete=:'+ff.Id);
WebServiceRequestBuilder.HttpResult(ff.Opportunity__c,ff.Id,'delete');
}
}
i just want to know that in trigger .isdelete i want ot send the id of that record in webrequest as mention above. so i want to confrim that is i gt id in this case .if not what can be proper way to handle this.
please help me
thanks
You can use Trigger.old in a for loop and get IDs of all records that are deleted. Ideally you will have to use this 'for' loop inside if(Trigger.isDelete)..
Something like this:
if(Trigger.isDelete) {
for(FF__c f: Trigger.old) {
// use f.Id in your code
}
}
Let me know if you need more clarity..
All Answers
you need to fire SOQL query with key word ALL ROWS. If this not help you please let me know the requirement.
Skype : niket.chandane
reuirement is i need the id before the delete the row in trigger
You can use Trigger.old in a for loop and get IDs of all records that are deleted. Ideally you will have to use this 'for' loop inside if(Trigger.isDelete)..
Something like this:
if(Trigger.isDelete) {
for(FF__c f: Trigger.old) {
// use f.Id in your code
}
}
Let me know if you need more clarity..
hi dear below is my trigger
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
List<Opportunity> listOpp = new List<Opportunity>();
boolean flag = true;
for (FF__c ff : Trigger.new)
{
if (Trigger.isInsert)
{
if (ff.Account_Type__c == 'ANA' && ff.DOB__c == null)
{
ff.DOB__c.addError('DOB is required');
flag = false;
}
if (ff.Account_Type__c == 'DL' && ff.Last_Name__c == null)
{
ff.Last_Name__c.addError('Last Name is required');
flag = false;
}
if(flag)
{
System.debug('Triggerinsert FF ID =' +ff.Id);
if(ff.Id != null)
{
//WebServiceSalesforceFeed.HttpResult(ff.Opportunity__c,ff.Id,'add');
}
Opportunity oppNew = [SELECT Id,StageName FROM Opportunity WHERE Id =:ff.Opportunity__c];
if(oppNew.StageName == 'Ticketing')
{
oppNew.StageName = 'FF Account Assigned';
listOpp.add(oppNew);
}
if (listOpp != null && !listOpp .isEmpty())
{
Database.update(listOpp);
}
}
}
else if (Trigger.isUpdate)
{
System.debug('Triggerupdate FF ID =' +ff.Id);
if(ff.Id != null)
{
//WebServiceSalesforceFeed.HttpResult(ff.Opportunity__c,ff.Id,'update');
}
}
}
if (Trigger.isDelete)
{
// In a before delete trigger, the trigger accesses the records that will be
// deleted with the Trigger.old list.
for (FF__c ff : Trigger.old)
{
if (ff.id != null)
{
System.debug('Triggerdelete FF ID =' +ff.Id);
//WebServiceSalesforceFeed.HttpResult(ff.Opportunity__c,ff.Id,'delete');
}
}
}
}
but i am geeting error during delete the record
"There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger FFTrigger caused an unexpected exception, contact your administrator: FFTrigger: execution of AfterDelete caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.FFTrigger: line 5, column 1". "
please let me where i am wrong
just use trigger event before delete not after delete
and use trigger.old instead of trigger.new
Couple of things:
You are using all the logics inside a for loop - at line 5, which will effect the governor limits.
You cannot use Trigger.Old inside Trigger.New, logically.
For update and insert operation you can use Trigger.New, but after delete you should use Trigger.Old.
Change appropriately, I think your code will work (though I have not checked each line).
thanks to all for your suggestions.it reallly work for me.