• ruchika Nayyar
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 13
    Replies
i have created
Upload any pdf file into Document first. Send an email as attachment to lead email Id. 
Email Subject : Welcome
Please find the attached PDF.
but i am getting mail but not attached file??

trigger SendEmail on Lead (after insert, after update) {
    
    for(Lead ld:trigger.new){
        {
             if(ld.Email!= null)
             {
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        
    
       email.setToAddresses(new String[]{'ruchikanayyar12@gmail.com'});        
        email.setReplyTo('ruchinayyar12@gmail.com');
        email.setSenderDisplayName('CRM Support');
        email.setSubject('Welcome');
        email.setBccSender(false);
        email.setUseSignature(false);
        email.setPlainTextBody('Please find the attached PDF');
                 email.saveAsActivity = false;
        email.setTargetObjectId(ld.OwnerId);
      
    
     List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
        for (Attachment a : [select Name, Body, BodyLength from Attachment where ParentId = :ld.Id])
        {
        
        Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
         efa.setContentType('application/pdf');
         efa.setFileName('pdffile.pdf');
           String body;
        
        body = '<html><h1 style=\"text-align:center;\">LeadInformation</h1><br/><br/><table align=\"center\"><tr><td>Name</td><td>' + ld.Name + '</td></tr><tr><td>Age</td><td>' + ld.Email + '</td></tr><tr><td>State</td><td>' + ld.Company + '</td></tr><tr><td>City</td><td>' + ld.Phone + '</td></tr></table></html>';
        System.debug('HTML is ' + body);
        
        efa.Body = Blob.toPDF(body);  

        fileAttachments.add(efa);
        }
        email.setFileAttachments(fileAttachments);
      //Send email
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
       
}       
}
}

    

}
trigger OPPTRIGGER on OpportunityLineItem (after update) {
    Set<Id> OLI= new set<Id>();
    for(OpportunityLineItem obj: TriggerNew)
    {
        SetOLI.add(obj.Id);
        
    }
    Map<ID, OpportunityLineItem> map1= New Map<ID, OpportunityLineItem>();
    for(OpportunityLineItem obj:[Select Id,Name,quantity,opportunity,opportunity.AccountId,Opportunity.Account.myruchika__Total_sales_quantities__c from OpportunityLineItem where ID in :Set OLI])
    {
        if(obj.opportunity!=null && obj.Opportunity.AccountId!= null)
        {
            if(map1.get(obj.Opportunity.AccountId)== null)
            {
                map1.put(obj.Opportunity.AccountId, New list<OLI> New OpportunityLineItem)
                {
                    map1.get(obj.Opportunity.AccountId).Add(obj);
                }
            
            }
        }
    }
    list<Account> lstacc= New list<Account>();
    for(Account obj:[Select Id,myruchika__Total_sales_quantities__c from account where ID in:Map.keySet()])
    {
        if(map1.get(obj.Id)!=null)
        {
            decimal total quantities=0;
        }
    }
       for(OpportunityLineItem objLI:Map1.get(obj.Id)) 
       {
           totalquantity+=objLI.quantity
       }
       if(obj.myruchika__Total_sales_quantities__c==null) 
       {
           obj.myruchika__Total_sales_quantities__c=0;
       }
      obj.myruchika__Total_sales_quantities__c+=totalquantity;
    lstacc.add(obj);
}
updateOpportunityLineItem.size() >0)
        update updateOpportunityLineItem;
}
}

error is coming in this code
please help me for this code 
trigger Account2 on Account (before insert) {
    List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
    for (Account myAccount : Trigger.new) {
    if (myAccount.Email != null && myAccount.FirstName = "AccountName") {
         Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
         List<String> sendTo = new List<String>();
        sendTo.add(00528000002VHIK.Email);
        mail.setSubject('An account has been created');
      String body = 'Dear ' + myAccount.FirstName + ', ';
      body += 'An account has been created and name is "AccountName"';
    }
        
            Messaging.sendEmail(mails);
        }
    

}

please help me for this code
trigger accountcontact on Account (after insert) {
        list<id> AccountId= new list<Id>();
        for(contact con:Trigger.new){
            accountId.add(con.AccountId);
        }
            map<Id, Account>AccountMap= New map<Id, Account>([Select id,name,myruchika__client_contact__c from Account where Id IN:accountId]);
            list<account> updateaccountlist= new list<Account>();
            for(contact con :trigger.new){
                if(Accountmap !=null&& accountmap.size()>0)  {
                    for(Account acc: Accountmap) {
                        acc.myruchika__client_contact__c=con.Id;
                        updateAccountlist.add(acc);
                        
                    }
                }
            }
           
        if(updateAccountList !=null && updateaccountlist.size()>0)
            update updateAccountlist;
}

error=loop varible must be account type???
hi is there any opening for salesforce developer jobs minimum experience 8 month??
please tell me
thanks
how to write this code help me out?/
Write a trigger on Account when Account is update check all opportunity inside the account. Update all Opportunities Stage to close lost if an opportunity created date is greater than 30 days from today and stage not equal to close won.
trigger opportunitytrigger1 on Opportunity (after insert) {
    list<opportunityLineItem> olilist= new list<OpportunityLineItem>();
    for(opportunity op:Trigger.New)
    {
        if(op.product!=null)
        {
            OpportunityLineItem oli= New OpportunityLineItem();
            oli.Product= op.Product;
            oli.Opportunity= op.ID;
            olilist.add(oli);
        }
    }
      if(olilist!=null&&olilist.size()>0)
          insert olilist;
}

error-invalid field for product sobject 
is this Code is right??

trigger createAssetonClosedWon on Opportunity (after insert, after update) {
    for(opportunity o:Trigger.New) {
        if(o.iswon==true && o.hasOpportunitylineitem==true){
            string opptyId= o.Id;
            Opportunitylineitem[] OLI=[Select Quantity,UnitPrice,PricebookEntry.Product2Id, PricebookEntry.Product2.Name, Description from opportunitylineitem where opportunityId=:opptyId];
            asset[] ast= New Asset[]{};
                asset a= new asset();
            for(opportunitylineitem ol:OLI){
                a= new asset();
                a.AccountId=a.AccountID;
                a.Quantity=ol.quantity;
                
                a.Product2Id=ol.PricebookEntry.Product2Id;
                a.price=ol.UnitPrice;
                a.Description=ol.Description;
                a.name=ol.PricebookEntry.Product2.Name;
                ast.add(a);
                
                
            }
            
            insert ast;
            
            
        }
    }
}
 error 
Apex trigger myruchika.createAssetonClosedWon caused an unexpected exception, contact your administrator: myruchika.createAssetonClosedWon: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: AccountId, ContactId (asset must have account and/or contact parent(s)): [AccountId, ContactId]: Trigger.myruchika.createAssetonClosedWon: line 22, column 1 
  
Write a trigger on Opportunity, when an Opportunity will be insert an Opportunity Line Item should be insert by default with any of the Product associated with Opportunity
public class contactpopulate {
    public void onbeforeinsert(list<contact>TriggerNew)
        {
          onduplicateEmailandphone(TriggerNew);
        }
   void onduplicateEmailandphone(list<Contact>TriggerNew)
   {
        set<string> Set1= New set<string>();
        set<string> Set2= New set<string>();
    
        For(contact con:TriggerNew)
        {
            if(con.Phone!=null)
            {
                Set1.add(con.Phone);
            }
                if(con.Email!=null)
                {
                    Set2.add(con.Email);
                }
            }
        map<id,contact> map1= New map<id,contact>();
        map<id,contact> map2= New map<id,contact>();
        for(contact obj:[select id,name,Phone,Email from contact where Phone in: Set1 OR Email in: Set2])
        {
            map1.put(obj.phone,obj);
            map2.put(obj.Email,obj);
            
        }
    for(contact con:TriggerNew)
    {
        if(con.Phone !=null && map1.get(con.Phone)!=null)
           {
               con.adderror('duplicate phone found please enter new phone');
               
           }
        if(con.Email!=null&& map2.get(con.Email)!=null)
           {
               con.adderror('duplicate email found please enter new email');
           }
    }
    }
}
public class studenttrigger1 
{
    
    public void onbeforeinsert(list<myruchika__Student__c>TriggerNew)
    {
        createStatusofTeacher(TriggerNew);
    }
    void  createStatusofTeacher(list<myruchika__Student__c>TriggerNew)
    {
    set<ID> settech= New set<ID>();
    for(student__c objS:TriggerNew)
    {
     if(objS.myruchika__Teacher__c!=null)
     {
         settech.add(objS.myruchika__Teacher__c);
     }
    }
 map<ID,myruchika__Teacher__c> mapteach=new map<ID,myruchika__Teacher__c>([select ID, myruchika__statusofteacher__c from myruchika__Teacher__c where ID in:settech]);
     for(student__c objT:Triggernew)
     {
       If (objT.student__c!=null && mapstudent__c.get(objT.myruchika__Teacher__c)!=null)
           {
               teacher__c obj= mapteach.get(objT.myruchika__Teacher__c);
           
         if(obj.myruchika__statusofteacher__c==false)
         {
             objT.adderror('Teacher must be active to create student');
         }
          }
   }   
    
    }
            }



 
  Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger myruchika.contact caused an unexpected exception, contact your administrator: myruchika.contact: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Class.myruchika.contact1.Managefeeonupdate: line 48, column 1



public void onafterupdate(list<contact>Triggernew,list<contact>Triggerold,map<ID,contact>Triggernewmap,map<ID,contact>Triggeroldmap)
{
  Managefeeonupdate(TriggerNew,Triggeroldmap);
}
void Managefeeonupdate(list<contact>Triggernew,Map<ID,contact>Triggeroldmap)
{
    set<ID> setAccID= New set<ID>();
    list<Account> lstAcc=New list<Account>();
    for(contact objC: TriggerNew)
    {
        if (objC.AccountId!=null && objC.myruchika__fee__c!=TriggeroldMap.get(objC.AccountID).myruchika__fee__c)
           {
           setAccID.Add(objC.AccountId);
           }
    }         
     if(setAccID.size()>0)
           {
               for(Account objA:[select ID,myruchika__totalfees__c,(select ID,myruchika__fee__c From contacts Where myruchika__fee__c!=null) From Account Where ID in :setAccID])
               {
                   
               
           Decimal amt=0;
           for(contact objC:objA.contacts)
           {
               amt += objC.myruchika__fee__c;
           }
         objA.myruchika__totalfees__c=amt;
               
           lstAcc.add(objA);
           }
           If(lstAcc.size()>0)
           {
               update lstAcc;
               
           }
}
i have created
Upload any pdf file into Document first. Send an email as attachment to lead email Id. 
Email Subject : Welcome
Please find the attached PDF.
but i am getting mail but not attached file??

trigger SendEmail on Lead (after insert, after update) {
    
    for(Lead ld:trigger.new){
        {
             if(ld.Email!= null)
             {
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        
    
       email.setToAddresses(new String[]{'ruchikanayyar12@gmail.com'});        
        email.setReplyTo('ruchinayyar12@gmail.com');
        email.setSenderDisplayName('CRM Support');
        email.setSubject('Welcome');
        email.setBccSender(false);
        email.setUseSignature(false);
        email.setPlainTextBody('Please find the attached PDF');
                 email.saveAsActivity = false;
        email.setTargetObjectId(ld.OwnerId);
      
    
     List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
        for (Attachment a : [select Name, Body, BodyLength from Attachment where ParentId = :ld.Id])
        {
        
        Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
         efa.setContentType('application/pdf');
         efa.setFileName('pdffile.pdf');
           String body;
        
        body = '<html><h1 style=\"text-align:center;\">LeadInformation</h1><br/><br/><table align=\"center\"><tr><td>Name</td><td>' + ld.Name + '</td></tr><tr><td>Age</td><td>' + ld.Email + '</td></tr><tr><td>State</td><td>' + ld.Company + '</td></tr><tr><td>City</td><td>' + ld.Phone + '</td></tr></table></html>';
        System.debug('HTML is ' + body);
        
        efa.Body = Blob.toPDF(body);  

        fileAttachments.add(efa);
        }
        email.setFileAttachments(fileAttachments);
      //Send email
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
       
}       
}
}

    

}
trigger OPPTRIGGER on OpportunityLineItem (after update) {
    Set<Id> OLI= new set<Id>();
    for(OpportunityLineItem obj: TriggerNew)
    {
        SetOLI.add(obj.Id);
        
    }
    Map<ID, OpportunityLineItem> map1= New Map<ID, OpportunityLineItem>();
    for(OpportunityLineItem obj:[Select Id,Name,quantity,opportunity,opportunity.AccountId,Opportunity.Account.myruchika__Total_sales_quantities__c from OpportunityLineItem where ID in :Set OLI])
    {
        if(obj.opportunity!=null && obj.Opportunity.AccountId!= null)
        {
            if(map1.get(obj.Opportunity.AccountId)== null)
            {
                map1.put(obj.Opportunity.AccountId, New list<OLI> New OpportunityLineItem)
                {
                    map1.get(obj.Opportunity.AccountId).Add(obj);
                }
            
            }
        }
    }
    list<Account> lstacc= New list<Account>();
    for(Account obj:[Select Id,myruchika__Total_sales_quantities__c from account where ID in:Map.keySet()])
    {
        if(map1.get(obj.Id)!=null)
        {
            decimal total quantities=0;
        }
    }
       for(OpportunityLineItem objLI:Map1.get(obj.Id)) 
       {
           totalquantity+=objLI.quantity
       }
       if(obj.myruchika__Total_sales_quantities__c==null) 
       {
           obj.myruchika__Total_sales_quantities__c=0;
       }
      obj.myruchika__Total_sales_quantities__c+=totalquantity;
    lstacc.add(obj);
}
updateOpportunityLineItem.size() >0)
        update updateOpportunityLineItem;
}
}

error is coming in this code
please help me for this code 
trigger Account2 on Account (before insert) {
    List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
    for (Account myAccount : Trigger.new) {
    if (myAccount.Email != null && myAccount.FirstName = "AccountName") {
         Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
         List<String> sendTo = new List<String>();
        sendTo.add(00528000002VHIK.Email);
        mail.setSubject('An account has been created');
      String body = 'Dear ' + myAccount.FirstName + ', ';
      body += 'An account has been created and name is "AccountName"';
    }
        
            Messaging.sendEmail(mails);
        }
    

}

please help me for this code
trigger opportunitytrigger1 on Opportunity (after insert) {
    list<opportunityLineItem> olilist= new list<OpportunityLineItem>();
    for(opportunity op:Trigger.New)
    {
        if(op.product!=null)
        {
            OpportunityLineItem oli= New OpportunityLineItem();
            oli.Product= op.Product;
            oli.Opportunity= op.ID;
            olilist.add(oli);
        }
    }
      if(olilist!=null&&olilist.size()>0)
          insert olilist;
}

error-invalid field for product sobject 
Write a trigger on Opportunity, when an Opportunity will be insert an Opportunity Line Item should be insert by default with any of the Product associated with Opportunity
public class contactpopulate {
    public void onbeforeinsert(list<contact>TriggerNew)
        {
          onduplicateEmailandphone(TriggerNew);
        }
   void onduplicateEmailandphone(list<Contact>TriggerNew)
   {
        set<string> Set1= New set<string>();
        set<string> Set2= New set<string>();
    
        For(contact con:TriggerNew)
        {
            if(con.Phone!=null)
            {
                Set1.add(con.Phone);
            }
                if(con.Email!=null)
                {
                    Set2.add(con.Email);
                }
            }
        map<id,contact> map1= New map<id,contact>();
        map<id,contact> map2= New map<id,contact>();
        for(contact obj:[select id,name,Phone,Email from contact where Phone in: Set1 OR Email in: Set2])
        {
            map1.put(obj.phone,obj);
            map2.put(obj.Email,obj);
            
        }
    for(contact con:TriggerNew)
    {
        if(con.Phone !=null && map1.get(con.Phone)!=null)
           {
               con.adderror('duplicate phone found please enter new phone');
               
           }
        if(con.Email!=null&& map2.get(con.Email)!=null)
           {
               con.adderror('duplicate email found please enter new email');
           }
    }
    }
}

Hi ,

 

     I am confused between synchronous and asynchronous can any one explain me from the scratch what are they actually , and when we use the @future annotation . Please Help me  !!!

 

 

Help is highly appreciated.

 

Thanks in Advance. 

  • June 22, 2013
  • Like
  • 2