+ Start a Discussion
Sourav PSourav P 

Delete button to trigger as per a certain criteria

Dear All,
I have the related object " Named Driver" in the Quote object, i need that the users can only delete a named driver record only when the premium field in the quote field is zero (0), if any value present , they shouldnt able to delete. Can you plz suggest how this can realize, thanks
User-added image
Best Answer chosen by Sourav P
Karthi XaviKarthi Xavi
Hi Sourav,
I suggest you to go with before delete trigger on your Named Driver object. Check the Quote Object field value and allow the user to delete else throw an error message on your own.

Thanks,
Karthi.

All Answers

RKSalesforceRKSalesforce
Please refer to below link:
https://developer.salesforce.com/forums/?id=906F00000008ozHIAQ

let me know if helps you.

Regards,
Ramakant
Sourav PSourav P
Hi Ramakant , Thanks
I tried creating a trigger as below,
 
trigger deletionOption on Quotation_Driver__c (before delete) {
for ( Quotation_Driver__c D:Trigger.old){
if(D.Total_Price__c!=0.00){
D.addError('Clone the Quotation');
}
}
}
But the , error message showing as below, How can i get a proper error message in the same page please, e.g just on the top of the page " Clone the Quotation " ?

User-added image
 
Karthi XaviKarthi Xavi
Hi Sourav,
I suggest you to go with before delete trigger on your Named Driver object. Check the Quote Object field value and allow the user to delete else throw an error message on your own.

Thanks,
Karthi.
This was selected as the best answer
Sourav PSourav P
Hi Karthi, Thanks. Actually i used the above before delete trigger on Named Driver only ( API name : Quotation_Driver_c), I taken the criteria field value from Quote to Named driver ( API ame : Total_Price__c). Now this trigger working absolutely fine. But the error message i wannt in the detailed page with only the error text. Not as above. So, i was wondering if i can add a hyperlink in the addError. plz suggest .
Sourav PSourav P
Dear Both
I went through the docs, but managed a half a way only. I did below changes,
D.addError('Clone the Quotation <a href=\'https://cs6.salesforce.com/\'></a>', false);
and Now my error is, I wanted in the same page ( similar to validation rules error view), If any suggestion from your side on the above code changes plz

User-added image

 
Karthi XaviKarthi Xavi
Hi Sourav,

I think you reached the end and you cannot go further with standard button and you can achieve this using a custom button and javascript to show a alert message before deletion.

Thanks. 
karthi
Sourav PSourav P
Hi Karthi
Thanks. But i dont want to use the JS as seems SF is starting to remove the JS entirely,and we have to sooner or later find another way. I tried as per below with page refer, but it doesnt worked, showed same screen.
 
trigger deletionOption on Quotation_Driver__c (before delete) {
for ( Quotation_Driver__c D:Trigger.old){
if(D.Total_Price__c!=0.00){

D.addError('Clone the Quotation <a href=\'https://cs6.salesforce.com/\'></a>', false);
PageReference pageRef = ApexPages.currentPage();
}

}
}