function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SATZSATZ 

Record type selection

Hi all,

I am using EDUCATION custom object In education contact is master detail object.

Education  has two record types namely Phase and A la Carte

 

For each contact I create education In both record type. 

In both records type I want one only record must  be insert 

in Phase==1 and A la carte==1 

 

 

for this how to write condition in trigger on Education

 

regards satz

 

 


Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

 

trigger chkrecordcount on education__c (before insert)

{

               

                 integer count=[select count() from education__c where contactid=trigger.new[0].contactid and RecordTypeId=Trigger.new[0].RecordTypeId];

                 if(count>0)

                 {

                                trigger.new[0].addError('you coannot insert this record ');

                 }

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

 

trigger chkrecordcount on education__c (before insert)

{

               

                 integer count=[select count() from education__c where contactid=trigger.new[0].contactid and RecordTypeId=Trigger.new[0].RecordTypeId];

                 if(count>0)

                 {

                                trigger.new[0].addError('you coannot insert this record ');

                 }

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

This was selected as the best answer
SATZSATZ

Thanks for Your reply,

its working fine.

 

thanks a lots..