You need to sign in to do that
Don't have an account?
System Admin 949
Update Email Fields in Related Objects
Dear Community,
I have two Objects ProductFamily__c and PlantContact__c.ProductFamily is parent and PlantContact is child.i have email fields in both objects like AR&D,Commercial,DQA,Marketing,Pilot,Production,QA,QC,R&D..etc.also one checkbox field called 'Default ' in PlantContact object.
and to fill ProductFamily Email Fields based on the default value on PlantContact for that type.
use trigger/Process builder shall be involed every time a plant contact is created or updated with default = true, action will then be to find the corresponding product family record and update the relevant email field based on type of plant contact that is being set default.If default=false put null value in the corresponding fields of ProductFamily.For each type in PlantContact put only one default value to the corresponding ProductFamily.
For example ProductFamily reocrd is PF-0001 and it is has only one default record like AR&D,R&D,QA,QC,..etc child records.If the user try to add one more record for above types as default it will throws error.if the above types are don't select default=true put blank/null values in corresponding ProductFamily Record.
thanks in Advance
I have two Objects ProductFamily__c and PlantContact__c.ProductFamily is parent and PlantContact is child.i have email fields in both objects like AR&D,Commercial,DQA,Marketing,Pilot,Production,QA,QC,R&D..etc.also one checkbox field called 'Default ' in PlantContact object.
and to fill ProductFamily Email Fields based on the default value on PlantContact for that type.
use trigger/Process builder shall be involed every time a plant contact is created or updated with default = true, action will then be to find the corresponding product family record and update the relevant email field based on type of plant contact that is being set default.If default=false put null value in the corresponding fields of ProductFamily.For each type in PlantContact put only one default value to the corresponding ProductFamily.
For example ProductFamily reocrd is PF-0001 and it is has only one default record like AR&D,R&D,QA,QC,..etc child records.If the user try to add one more record for above types as default it will throws error.if the above types are don't select default=true put blank/null values in corresponding ProductFamily Record.
thanks in Advance
As far as i have understood your requirement i think this code will work for you or else please try to explain clearly.
Let me know in case of any query.
Thanks,
Nitish
in 2nd case,i want to create a ProductFamily Record.later through ProductFamily related list i want to create a PlantContact Record.for this while i m clicking a new button in PlantContact and select any type like AR&D,R&D,QC,QA....etc.And it is the first record for each type.I mean suppose i created record of PlantContact with AR&D and not selecting the checkbox Default=true.for that time any record of type AR&D not associated to ProductFamily record after saving the record the checkbox set to true,bcoz this is the first record for AR&D type to that ProductFamily Record.later user created record in PlantContact of same type AR&D with default=true to same ProductFamily Record(same Parent),it will through error bcoz already record created with AR&D type and default=true.
How to achieve this?? how system knows if the record of each type should be associated or not to that perticular Parent record.
thanks in advance
AR&D,R&D all these fields are Email fields right on PlantContact Object? Then how you are selecting type?
Trigger PlantContactTrigegr on PlantContact__c(after insert,after update){
if((Trigger.isInsert && Trigger.isAfter) || (Trigger.isUpdate && Trigger.isAfter)) {
List<ProductFamily__c> pfList=new List<ProductFamily__c>();
for(PlantContact__c pc:Trigger.new){
if(pc.Default__c == TRUE){
ProductFamily__c pf=new ProductFamily__c();
if(pc.TypeOfContact__c==AR&D){
pf.ARDRespID__c=pc.Email__c;
}
else if(pc.TypeOfContact__c==R&D){
pf.RDRespID__c=pc.Email__c;
}
else if(pc.TypeOfContact__c==Production){
pf. ProductionRespID__c=pc.Email__c;
}
else if(pc.TypeOfContact__c==RA){
pf.RARespID__c=pc.Email__c;
}
else if(pc.TypeOfContact__c==DQA){
pf.DQARespID__c=pc.Email__c;
}
else if(pc.TypeOfContact__c==QC){
pf.QCRespID__c=pc.Email__c;
}
else if(pc.TypeOfContact__c==QA){
pf.QARespID__c=pc.Email__c;
}
else if(pc.TypeOfContact__c==Pilot){
pf.PilotID__c=pc.Email__c;
}
else if(pc.TypeOfContact__c==Marketing){
pf.MarketingID__c=pc.Email__c;
}
else if(pc.TypeOfContact__c==Commercial){
pf.CommercialRespID__c=pc.Email__c;
}
/*f.Commercial=pc.Commercial;
pf.DQA=pc.DQA;
pf.Marketing=pc.Marketing;
pf.Pilot=pc.Pilot;
pf.Production=pc.Production;*/
pf.Id=pc.ProductFamily__c;
pfList.add(pf);
}else{
ProductFamily__c pf=new ProductFamily__c();
pf.ARDRespID__c='';
pf.RDRespID__c='';
pf.CommercialRespID__c='';
pf.DQARespID__c='';
pf.MarketingID__c='';
pf.PilotID__c='';
pf.ProductionRespID__c='';
pf.QARespID__c='';
pf.QCRespID__c='';
pf.PilotID__c='';
pf.Id=pc.ProductFamily__c;
pfList.add(pf);
}
}
if(pfList.size()>0){
update pfList;
}
}
}
Note: Error: Compile Error: Variable does not exist: AR at line 7 column 41
Try something like below code it might help or let me know if you will face any specific issue in that because i haven't tried that perticular code from my side.
Thnaks,
Nitish