You need to sign in to do that
Don't have an account?
Prasanth R
recordtype with trigger
Create a picklist field with two value Type1, Type2 in contact object. Picklist fields name = 'Secondary Contact Type', make it mandatory When a user creates a Contact record, if User selects value in Secondary Contact Type a new record in the Object called Secondary Contact should be created.
Create two record type for Secondary Contact object namely Sales and Service.
If Type1 selected - Secondary Contact of record type 'Sales' should be created
If Type2 selected - Secondary Contact of record type 'Service' should be created
Secondary Contact created should be seen in Contact records detail page as a lookup field.
trigger contactRecordValues on Contact (after insert) { List<Secondary_Contact1__c> sectlist = new List<Secondary_Contact1__c>(); for(Contact con:Trigger.new){ if(con.Secondary_Contact_Type__c=='Type1'){ Secondary_Contact1__c seccon = new Secondary_Contact1__c(); seccon.RecordTypeId = con.Secondary_Contact1__c; sectlist.add(seccon);
}
}
if(sectlist.size()>0){ insert sectlist; }
}
above code is i tried...kindly someone help me
Create two record type for Secondary Contact object namely Sales and Service.
If Type1 selected - Secondary Contact of record type 'Sales' should be created
If Type2 selected - Secondary Contact of record type 'Service' should be created
Secondary Contact created should be seen in Contact records detail page as a lookup field.
trigger contactRecordValues on Contact (after insert) { List<Secondary_Contact1__c> sectlist = new List<Secondary_Contact1__c>(); for(Contact con:Trigger.new){ if(con.Secondary_Contact_Type__c=='Type1'){ Secondary_Contact1__c seccon = new Secondary_Contact1__c(); seccon.RecordTypeId = con.Secondary_Contact1__c; sectlist.add(seccon);
}
}
if(sectlist.size()>0){ insert sectlist; }
}
above code is i tried...kindly someone help me
try with below code.
If this helps, please mark it as best answer.
Thanks!!
can you explain these two lines
Id SalesRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Sales').getRecordTypeId(); Id ServiceRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Service').getRecordTypeId();
Sorry.!! Can you please replace the Account with Secondary_Contact1__c. Please refer the below modified code.
If this helps, Please mark it as best answer.
Thanks!!
i'm not able to understand this.can you give anyother way?
Try with below alterantive query.
Id SalesRecordTypeId = [SELECT id FROM RecordType WHERE name = 'Sales' and sobjecttype ='Secondary_Contact1__c '].Id;
Id ServiceRecordTypeId= [SELECT id FROM RecordType WHERE name = 'Service' and sobjecttype ='Secondary_Contact1__c '].Id;
If this helps, please mark it as best answer.
trigger contactRecordValues on Contact (after insert) {
List<Secondary_Contact1__c> sectlist = new List<Secondary_Contact1__c>();
Id SalesRecordTypeId = [SELECT id FROM RecordType WHERE name = 'Sales' and sobjecttype ='Secondary_Contact1__c '].Id;
Id ServiceRecordTypeId= [SELECT id FROM RecordType WHERE name = 'Service' and sobjecttype ='Secondary_Contact1__c '].Id;
for(Contact con:Trigger.new){
if(con.Secondary_Contact_Type__c=='Type1'){
Secondary_Contact1__c seccon = new Secondary_Contact1__c();
seccon.RecordTypeId = con.SalesRecordTypeId;
seccon.Contact__c = con.Id;
sectlist.add(seccon);
}
else if(con.Secondary_Contact_Type__c=='Type2'){
Secondary_Contact1__c seccon1 = new Secondary_Contact1__c();
seccon1.RecordTypeId = con.ServiceRecordTypeId;
seccon1.Contact__c = con.Id;
sectlist.add(seccon1);
}
}
if(sectlist.size()>0){
insert sectlist;
}
}
Try with below code. If this helps, Please mark it as best answer.
Thanks!!
explain more about this statement