You need to sign in to do that
Don't have an account?
rajesh kumar 10
I have facing a problem on trigger that..
I have to to write a trigger on object Primary application allocation that is related to opportuniity and
when atlease 1 record is created, set the opportunity.primary_application_allocation_set check mark = true
and
And when all the primary application records are deleted, set the opportunity.primary_application_allocation_set check mark = false ..
I was facing problem with this to write a trigger. so please can any one help on this..
when atlease 1 record is created, set the opportunity.primary_application_allocation_set check mark = true
and
And when all the primary application records are deleted, set the opportunity.primary_application_allocation_set check mark = false ..
I was facing problem with this to write a trigger. so please can any one help on this..
There is a lot of material out there regarding how to write a trigger and best practices, so it'll be worthwhile if you start digging deeper and learn something more.
Here are a few links that can get you started:
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_trigger.htm
http://techman97.wordpress.com/2012/07/18/how-to-write-a-basic-apex-trigger/
https://developer.salesforce.com/page/Apex_Code_Best_Practices
when i am using the trigger that when i am inserting the records field is updating to true but when i delete atleast one record then it is updating to false.
But i want when all records are deleted which are are related to that opportunity then only it should be update to false..
But now i was facing when atleast one recordd is deleted then it is updating to false.
So can u please solve my problem.. Below is the Trigger
trigger UpdatePrimaryApllicationAllocationSet on Primary_Application_Allocation__c (after insert,after delete) {
list<id> lst = new list<id>();
if(trigger.isInsert){
for(Primary_Application_Allocation__c paa : trigger.new) {
lst.add(paa.opportunity__c);
}}
if(trigger.isDelete){
for(Primary_Application_Allocation__c paa : trigger.old) {
lst.add(paa.opportunity__c);
}
}
list<Opportunity> opplst = new list<Opportunity>();
opplst=[SELECT Primary_Application_Allocation_Set__c FROM Opportunity where Id in :lst];
if(trigger.isInsert) {
for(Primary_Application_Allocation__c paa : trigger.new) {
for(Opportunity o : opplst) {
if(paa.Opportunity__c == o.Id) {
o.Primary_Application_Allocation_Set__c = true;
}
}
}
update opplst;
}
if(trigger.isDelete) {
for(Primary_Application_Allocation__c paa : trigger.old) {
for(Opportunity o : opplst) {
if(paa.Opportunity__c == o.id) {
o.Primary_Application_Allocation_Set__c = False;
}
}
}
update opplst;
}
}