You need to sign in to do that
Don't have an account?

Trigger
Iam having 2 custom objects, 1)Digitalfactory 2)Stage.both are in lookup relation.stage name and stage creation date,are 2 fields in stage object. and SALESREADYDATE is the field in Devfactory (object).
requirement:- i need to write a trigger,when ever the stage name=closed ,then date of creation should come to salesready date (field)in devfactory(object)
hi
create trigger on stage object.
Trigger triggername on stage (before insert, before update) {
List<Digialfactory__c> dgList = new List<Digitalfactory>();
set<id> stgid = new set<id>();
for(stage__c stg : Trigger.New) {
stgid.add(stg.digitalfactory__c);
}
List<digitalfactory> dgist =[select id , name, salesreadydate, stage__c from digitalfactory__c where stagc__c IN: staid];
for(stage__c stg : Trigger.new) {
if(stg.stagename == 'closed') {
for (digitalfactory__c dgf:dgist) {
if(dgf.stage__c == stg.id) {
dgf.salesredaydate = stg.createdate;
dgList.add(dgf);
}
}
}
}
update dgList;
}
All Answers
I wrote this trigger considering Account and Opportunity and you can use this for your scenario i guess
trigger stageChanges on Opportunity (after update) {
List<Account> accList = new List<Account>();
List<Account> accUpdateList = new List<Account>();
List<id> accIdList= new List<id>();
for(Opportunity opp : Trigger.new){
accIdList.add(opp.accountid);
}
accList = [Select id,SLAExpirationDate__c from Account where id in :accIdList];
for(Opportunity opp : Trigger.new){
for(Account acc: accList){
if(opp.Accountid == acc.id && opp.StageName=='Qualification'){
acc.SLAExpirationDate__c = opp.CloseDate;
accUpdateList.add(acc);
}
}
}
update accUpdateList;
}
Hi thanks for u r replay am very new to trigger i dnt know any thing
i wan t write trigger on Digtafascroty object
and the related object is stage
in the stage i have the fields
StageName__c
Digital_Factory__c
Stage_Creation_Date_time__c
stage and digitalfactory have look up relation if i created any stage the Stage_Creation_Date_time__c should be display on the digitalfactory field (Sales_Ready_Date__c)
please suggest me for these fields how to write trigger
thanks advance
hi
create trigger on stage object.
Trigger triggername on stage (before insert, before update) {
List<Digialfactory__c> dgList = new List<Digitalfactory>();
set<id> stgid = new set<id>();
for(stage__c stg : Trigger.New) {
stgid.add(stg.digitalfactory__c);
}
List<digitalfactory> dgist =[select id , name, salesreadydate, stage__c from digitalfactory__c where stagc__c IN: staid];
for(stage__c stg : Trigger.new) {
if(stg.stagename == 'closed') {
for (digitalfactory__c dgf:dgist) {
if(dgf.stage__c == stg.id) {
dgf.salesredaydate = stg.createdate;
dgList.add(dgf);
}
}
}
}
update dgList;
}