Scenario3:-
// Amount In Words
before Insert, before update
for(Quote qu : Trigger.New)
{
if(qu.amount_in_words__c!=null) {
qu.Converted_Amount_In_Words__c = ConvertRupees.ConvertFun((qu.amount_in_words__c));
}}
Scenario 4:-
// Attachment in child (Attachment Is an object in salesforce)
before Insert, before update
set<id> Oppid =new set<id>();
for(Opportunity O : Trigger.new)
{
if(o.Record_Type_Name__c != 'Jewellery' && o.Record_Type_Name__c != 'Lifestyle' && o.Record_Type_Name__c != 'Watches')
Oppid.add(O.id);
}
List<Attachment> ca = [Select id from Attachment where ParentId=:Oppid];
for(Opportunity O: Trigger.new)
{
if(o.Record_Type_Name__c != 'Jewellery' && o.Record_Type_Name__c != 'Lifestyle' && o.Record_Type_Name__c != 'Watches')
O.Total_No_of_Attachment__c = ca.size();
}
Scerino 4:-
// NumberToWords ( Two objects Quote and QuoteLineitem)
before Insert, before update
If(TriggerMonitor.ExecutedTriggers.contains('NumberToWords'))
return;
TriggerMonitor.ExecutedTriggers.add('NumberToWords');
for(Quote qu:Trigger.New)
{
if(qu.Quote_Currency__c!='INR')
{
if(qu.amount_in_words__c!=null)
{
qu.Amount_converted_Words__c = EnglishNumberToWords.convert((qu.amount_in_words__c));
qu.New_Total_Amount_in_Words__c=qu.Quote_Currency__c +' '+' '+ qu.Amount_converted_Words__c;
}
}
else
{
if(qu.amount_in_words__c!=null)
{
qu.Amount_converted_Words__c = ConvertRupees.ConvertFun((qu.amount_in_words__c));
qu.New_Total_Amount_in_Words__c = qu.Quote_Currency__c +' '+' '+ qu.Amount_converted_Words__c;
}
}
Set<String> product_cat=new Set<String>();
for(Integer j = 0; j < LN.size(); j++){
//system.debug('PROOOOOOOOOOOOO'+cd[j].Product_Categeory__c);
product_cat.add(LN[j].PricebookEntry.Product2.Product_Category__c);
}
system.debug('No of category...'+product_cat.size());
system.debug('Name of category...'+product_cat);
if(product_cat.size()<2 && product_cat.size()>0 )
{
List<Contract_Details__c> cd=[select id,Discount__c,Valid_From__c,Valid_To__c,Brand__c,Value_From__c,Value_To__c from Contract_Details__c
where Contract_Number__c =: qu.Contract_Number__c and Brand__c=: LN[0].PricebookEntry.Product2.Product_Category__c
];
system.debug('No of category...'+product_cat.size());
for(Integer j = 0; j < cd.size(); j++){
if(qu.Sent_to_Approval__c == false){
if(qu.Discount_Corp__c <= cd[j].Discount__c){
system.debug('Valid Discount');
if(qu.Price_After_Discount__c >= cd[j].Value_From__c && qu.Price_After_Discount__c <= cd[j].Value_To__c){
system.debug('Valid Values');
if(qu.CreatedDate >= cd[j].Valid_From__c && qu.CreatedDate <= cd[j].Valid_To__c){
system.debug('valid date range');
qu.Approval_Status_count_LineItem__c =' ';
qu.Approval_Status_Quote__c ='Approved';
qu.Quote_Status_watches_new__c =' ';
qu.Approved_QuoteLineItem__c = qu.Total_No_of_QuoteLineItem__c;
break;
} else{
qu.Approval_Status_count_LineItem__c ='Approval Required';
qu.Approval_Status_Quote__c ='Approval Required';
qu.Quote_Status_watches_new__c ='Approval Required';
}
} else{
qu.Approval_Status_count_LineItem__c ='Approval Required';
qu.Approval_Status_Quote__c ='Approval Required';
qu.Quote_Status_watches_new__c ='Approval Required';
}
}
else{
qu.Approval_Status_count_LineItem__c ='Approval Required';
qu.Approval_Status_Quote__c ='Approval Required';
qu.Quote_Status_watches_new__c ='Approval Required';
}
}
}
}
Scerino 5:-
//OpportunitySharingRule
After Update, After Insert
List<OpportunityShare> oppShareList = new List<OpportunityShare>();
for(Opportunity o:Trigger.New) {
if(o.Record_Type_Name__c != 'Jewellery' && o.Record_Type_Name__c != 'Lifestyle' && o.Record_Type_Name__c != 'Watches')
{
if(o.Member2__c != NULL) {
OpportunityShare OppShare = New OpportunityShare (OpportunityId=O.Id,
UserOrGroupId =O.Member2__c ,
OpportunityAccessLevel = 'Edit'
);
oppShareList.add(OppShare);
}
}}
if(oppShareList.size() > 0 ) {
insert oppShareList;
}
Scerino 4:-
before insert, before update
//owner change (Opportunity Object)
List<RecordType> rtypes = [Select Name, Id From RecordType where sObjectType='Opportunity' and isActive=true];
Map<String,String> Opprectype = new Map<String,String>{};
for(RecordType rt: rtypes)
{
Opprectype.put(rt.Name,rt.Id);
}
List<User> Userlist = [Select Name, Id From User where isActive=true];
Map<String,String> Usermap = new Map<String,String>{};
for(User u: Userlist)
{
Usermap.put(u.Name,u.Id);
}
for(Opportunity opp : Trigger.New)
{
if(opp.Record_Type_Name__c != 'Jewellery' && opp.Record_Type_Name__c != 'Lifestyle' && opp.Record_Type_Name__c != 'Watches')
{
{
if(Trigger.isUpdate)
{
if(opp.CreatedDate.date() >= date.newInstance(2012, 2, 7))
{
&nb