You need to sign in to do that
Don't have an account?
How to use trigger below logic:my code sample-please help me
How to use Trigger -below logic--: wheneverTraining object survey flag true i want to insert field into Training survey object..and also insert record type ..please help me..
------------------------------------------------------
List <training__c> t1 = new list <training__c>();
list <training_survey__c> ts2 = new list<training_survey__c>();
t1 = [ select day1surveyflag__c, day3surveyflag__c, day5surveyflag__c from training__c where day1surveyflag__c = true or day3surveyflag__c = true or day5surveyflag__c = true ];
for(training__c tx : t1)
{
training_survey__c ts = new training_survey__c();
ts.training__C = tx.id;
if(tx.day1surveyflag__c == true )
{
ts.Survey_Type__c = 'Day1';
}else
if(tx.day3surveyflag__c == true )
{
ts.Survey_Type__c = 'Day3';
}else
if(tx.day5surveyflag__c == true )
{
ts.Survey_Type__c = 'Day5';
}else
{
ts.Survey_Type__c = 'Dropped';
}
RecordType r = [Select id from Recordtype where sobjecttype = 'training_survey__c' and name= :ts.Survey_Type__c];
ts.RecordTypeid = r.id;
ts2.add(ts);
}
if(ts2 != null )
{
insert ts2;
}
Hi,
Below is the code as per your requirement. you have to make some modification in that as per your requirement.
Apex Trigger:
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/
All Answers
Hi Nesh,
This code was written as a controller, but if you need it to be a trigger, you can modify it:
If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them. Thanks!
-Glyn Anderson
Certified Salesforce Developer | Certified Salesforce Administrator
Hi,
Below is the code as per your requirement. you have to make some modification in that as per your requirement.
Apex Trigger:
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/
mapRecordtype.put(rt.Name,rt.id);
Please help me
-----
List <training__c> t1 = new list <training__c>();
list <training_survey__c> ts2 = new list<training_survey__c>();
t1 = [ select day1surveyflag__c, day3surveyflag__c, day5surveyflag__c from training__c where day1surveyflag__c = true or day3surveyflag__c = true or day5surveyflag__c = true ];
for(training__c tx : t1)
{
training_survey__c ts = new training_survey__c();
ts.training__C = tx.id;
if(tx.day1surveyflag__c == true )
{
ts.Survey_Type__c = 'Day1';
}else
if(tx.day3surveyflag__c == true )
{
ts.Survey_Type__c = 'Day3';
}else
if(tx.day5surveyflag__c == true )
{
ts.Survey_Type__c = 'Day5';
}else
{
ts.Survey_Type__c = 'Dropped';
}
RecordType r = [Select id from Recordtype where sobjecttype = 'training_survey__c' and name= :ts.Survey_Type__c];
ts.RecordTypeid = r.id;
ts2.add(ts);
}
if(ts2 != null )
{
insert ts2;
}
---------------
Try to use below trigger code.
Apex trigger: