• sachin joshi 14
  • NEWBIE
  • 40 Points
  • Member since 2015

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
pls reply me i need solution

Make a APEX page

2.       Take ONE standard object, let’s say “Opportunity”

3.       Write code for global search, which will look to each column to “Opportunity” object and display the matching records on same page.

4.       Please note, if I add any new column to “Opportunity”, your code should consider any newly added column as well in search
Hi All,
I need to send email messeges to my contacts on closing the cases also need to create Task and Email Messages record. I have done some thing like this.
trigger sendemailonclosecase on Case (before update, after update ) {

Set<Id> Caseidset = new Set<Id>();
List<Case> updCase = new List<Case>();
List<Case> Caselist = new List<Case>();
Set<id> conidset = new set<Id>();
List<Messaging.SingleEmailMessage> msgList= new List<Messaging.SingleEmailMessage>();
String [] emails = new List<String>();
Map<Id, String> Emailmap = new Map<Id, String>();
Map<Id, String> Accountmap = new Map<id, String>();
List<Task> Tasklist = new List<Task>();
List<Emailmessage> ListEmail = new List<EmailMessage>();
if(trigger.isAfter){
        if(trigger.isUpdate){
            
        System.Debug('>>>>>');

EmailTemplate et = [Select Id from Emailtemplate where Name = 'closurecaseemailtemplatece1'];
            for (case c : trigger.new){
                        if(c.status == 'Closed' && c.Survey_Sent__c == false){
                    conidset.add(c.contactid);
                                        }
                                        }
                    List<Contact> contactList = [Select Id, Email, AccountId, Account.name from Contact where Id In: conidset];
                    for(Contact ct : contactList){
                            Emailmap.put(ct.Id, ct.Email);
                            Accountmap.put(ct.AccountId, ct.Account.Name);
                            }
                    System.Debug('>>>' + Emailmap);                               
                    System.Debug('>>>' + conidset);
                    System.Debug('>>>' + Accountmap);
                            for(Case cCase : Trigger.new){
                                   System.Debug('>>> for cas');
                                    if(cCase.Status == 'Closed'){
                                            System.Debug('>>> if' + cCase.status);
                                        Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
                                        msg.setTemplateId(et.id);
                            msg.setTargetObjectId(cCase.ContactId);
                            msg.setTemplateId(et.id);
                            msg.setWhatId(cCase.id);
                            msg.setSaveAsActivity(false);
                            if(!Emailmap.isEmpty()){
                            emails.add(Emailmap.get(cCase.contactId));
                            }
                                System.Debug('Sting' + emails);
                                if(Emails.size() > 0){
                            msg.setToAddresses(emails);
                            }
                            msglist.add(msg);
                            // Updating Case hear-------------
                                //cCase.Survey_Sent__c = true;
                                Caseidset.add(cCase.Id);
                            // Creating Task hear ------------
                            Tasklist.add(new Task(ownerId = cCase.OwnerId, Priority = 'Normal', 
                                                Subject = 'Case ' + cCase.Casenumber + 'has been closed', whoId = cCase.ContactId, WhatId = cCase.Id, Account_Name__c = Accountmap.get(cCase.AccountId)));
                            System.Debug('>>> ' + Tasklist); 
                            ListEmail.add(new Emailmessage(FromName = 'FXAll Client Service',
                    ToAddress = Emailmap.get(cCase.ContactId),
                    Subject = 'Case ' + cCase.Casenumber + 'has been closed',
                    TextBody = 'Thank you for contacting AM3CS your Case ' + cCase.Casenumber + 'has been closed',
                    ParentId = cCase.Id, 
                    ActivityId = Tasklist[0].Id));
                    System.Debug('>>> ' + ListEmail);
}
}
Messaging.sendEmail(msgList);
           
Insert Tasklist;
Insert ListEmail;
}
}
/*updCase = [Select Survey_Sent__c from case where Id IN : caseidset];
                       for(case c : updCase){
                               c.survey_sent__c = true;
                                   Caselist.add(c);
                                   }
                                   
                                        
Update Caselist;*/
}
Hear I am getting Activity id null and if my email has been sent I want to update my case with survey_sent__c = true. I am not able to update case records may be i am doing something wrong i have commented the code for this.
Also I need to do some other modifications. we have 5 customer email addreses where we receive cases, I wants to send different email templates according different customers email addresses like if we receive case on customer email address1, template1 should be sent and accordingly.
Please suggest how can i update the case records and achieve this functionality.
Thank You 
 
Hi All,
I have wrote a trigger on opportunity to update account fields, I want to populate account field(MaxoppName__c) with opportunity name which has maximum Amount below is my code, but it is not working
trigger SumAmount_Count_MaxOpportunity on Opportunity (after insert,after update) {
List<Account> Ac = new List<Account>();
Map<String, Decimal> M = new Map<String, Decimal>();  
    set<Id> accId = new set<Id>();
    for(Opportunity objOpp: trigger.new){
            accId.add(objOpp.AccountId);
        }
    Decimal Sum;
    Integer Count;
    for(Account Acc : [SELECT Id,Name,(SELECT Id,Name,Amount FROM Opportunities) 
                              FROM Account WHERE Id IN : accId]){
        Sum=0;
        Count=0;
        for(Opportunity Opp: Acc.Opportunities){
               M.put(opp.Name, opp.Amount);
                Sum += Opp.Amount ;
                Count++;
           
            List<Decimal> l = m.values();
            for(integer i=0; i<l.size(); i++){
                Decimal Max;
                if (Max < l[i]){
                    Max = l[i];
                    opportunity op = [select id, name from opportunity where Amount =: Max];
                    
                     acc.MaxoppName__c = op.name;
                            }
                      }
                    }
            Acc.Amount__c = Sum;
            Acc.OpportunityCount__c = Count;
            Ac.add(Acc);
    }
    update Ac;
}
other fields are updating but not MaxoppName__c Please give suggesions.
 
Hello Everyone,
I am facing an error on below trigger
trigger totaloflineitmoninvc on Line_Item__c(after insert, after update) {
			Invoice__c [] inv = new List<Invoice__c>();
    Set<Id> lineitmid = new Set<Id>();
    for(Line_Item__c li : Trigger.New)
    {
        lineitmid.add(li.Invoice__c);
    }
	Decimal total;
    Invoice__c[] Invo = [Select Id, Invoice_Total__c, (Select Id, Line_Item_Total__c from line_Items__r)
                        	From Invoice__c Where Id IN : lineitmid];
    for(Invoice__c invc : Invo ){
         total = 0;
                for(Line_Item__c litm : invc.Line_Items__r ){
         			total += litm.Line_Item_Total__c;
                }
    invc.Invoice_Total__c = total;
    inv.add(invc);   
    
    }
    update inv;
}

I am noy able to understand why I am getiing this error, all i want to do is just assign the total of my Line Items in Invoice Total.
Please give suggesions. 
trigger AccountDeletion on Account (before delete) {
    
        for (Account a : [SELECT Id FROM Account
                     WHERE Id IN (SELECT AccountId FROM Opportunity) AND
                     Id IN :Trigger.old]) {
        Trigger.oldMap.get(a.Id).addError(
            'Cannot delete account with related opportunities.');
    }
}
What is meaning of Trigger.oldMap.get(a.Id).addError() and why can't we use a.addError( ) as it is iterating only over the records which has opportunity.
Please Explain it will be a great help. 
pls reply me i need solution

Make a APEX page

2.       Take ONE standard object, let’s say “Opportunity”

3.       Write code for global search, which will look to each column to “Opportunity” object and display the matching records on same page.

4.       Please note, if I add any new column to “Opportunity”, your code should consider any newly added column as well in search
Hi All,
I have wrote a trigger on opportunity to update account fields, I want to populate account field(MaxoppName__c) with opportunity name which has maximum Amount below is my code, but it is not working
trigger SumAmount_Count_MaxOpportunity on Opportunity (after insert,after update) {
List<Account> Ac = new List<Account>();
Map<String, Decimal> M = new Map<String, Decimal>();  
    set<Id> accId = new set<Id>();
    for(Opportunity objOpp: trigger.new){
            accId.add(objOpp.AccountId);
        }
    Decimal Sum;
    Integer Count;
    for(Account Acc : [SELECT Id,Name,(SELECT Id,Name,Amount FROM Opportunities) 
                              FROM Account WHERE Id IN : accId]){
        Sum=0;
        Count=0;
        for(Opportunity Opp: Acc.Opportunities){
               M.put(opp.Name, opp.Amount);
                Sum += Opp.Amount ;
                Count++;
           
            List<Decimal> l = m.values();
            for(integer i=0; i<l.size(); i++){
                Decimal Max;
                if (Max < l[i]){
                    Max = l[i];
                    opportunity op = [select id, name from opportunity where Amount =: Max];
                    
                     acc.MaxoppName__c = op.name;
                            }
                      }
                    }
            Acc.Amount__c = Sum;
            Acc.OpportunityCount__c = Count;
            Ac.add(Acc);
    }
    update Ac;
}
other fields are updating but not MaxoppName__c Please give suggesions.
 
trigger AccountDeletion on Account (before delete) {
    
        for (Account a : [SELECT Id FROM Account
                     WHERE Id IN (SELECT AccountId FROM Opportunity) AND
                     Id IN :Trigger.old]) {
        Trigger.oldMap.get(a.Id).addError(
            'Cannot delete account with related opportunities.');
    }
}
What is meaning of Trigger.oldMap.get(a.Id).addError() and why can't we use a.addError( ) as it is iterating only over the records which has opportunity.
Please Explain it will be a great help.