• s_k_a
  • NEWBIE
  • 225 Points
  • Member since 2012

  • Chatter
    Feed
  • 7
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 85
    Replies

String Names = '^Community$|^Luxury$|^Golf$|^Course$|^Hospitality$|^Industrial$|^';

 

 

 

My Code:

 

Names = (Names!= '' && Names!= null) ? Names.replaceAll('\\$|^,'') : '';
system.debug(Logginglevel.Info,'::::Names::::::::::'+Names);

 

Current output in Debug Log:

^Community$|^Luxury$|^Golf$|^Course$|^Hospitality$|^Industrial$|^Industrial$|

 

Expected  Output:

 

Community,Luxury,Golf,Course,Hospitality,Industrial 

 

Hello!

 

I have some code listed below that I was hoping someone would be able to help me troubleshoot.  The code is supposed to assign the owner of a Lead based on what Account Team of the User.  So when the lead is created, if select "Storefront" for Lead_Direction__c picklist, then it should assign to the Account Team Member on the Account labeled as 'Storefront Associate'.  If the I select Big Deal in the picklist, then it should assign to the Account Team Member for the associated Account labeled as the 'Big Deal Associate'.  It works when I select Storefront in the Lead Direction and assigned the appropriate rep, but it doesn't assign correctly to the Big Deal Rep.

 

trigger OpportunityTrigger on Lead (before insert){

    List<String> accountIds = new List<String>();
    
    List<AccountTeamMember> parentAccounts = new List<AccountTeamMember>();
    
    for(Lead lead : Trigger.new){
    
        accountIds.add(lead.Account__c);    
    }
    
    parentAccounts = [Select AccountId, UserId, TeamMemberRole from AccountTeamMember where AccountId in :accountIds];
    
    Map<String,AccountTeamMember> accountMap = new Map<String,AccountTeamMember>();
    
    for(AccountTeamMember a : parentAccounts){
    
        accountMap.put(a.AccountId,a);
    }
    
    for(Lead lead : Trigger.new){
    
        AccountTeamMember parentAccount = accountMap.get(lead.Account__c);
        String memberRole = accountMap.get(lead.Account__c).TeamMemberRole;
        
        if((parentAccount != null)&&(memberRole == 'Storefront Associate')&&(lead.Lead_Direction__c == 'Storefront')){
        
            lead.OwnerId = parentAccount.UserId;
            
        }
        
        else if((parentAccount != null)&&(memberRole == 'Big Deal Associate')&&(lead.Lead_Direction__c == 'Big Deal')){
        
            lead.OwnerId = parentAccount.UserId;
          
        }
        
        else{
        
        lead.OwnerId = lead.OwnerId;
        
        }
        
    }
}

 

I have a trigger that is working the way I want it to, but it's not bulkified. If someone could help me figure out how to move the SOQL query out of the for loop I would really appreciate it! This trigger is on the OpportunityTeamMember object. When one team member is added, a field on the Opp should update to "Yes" and if a team member is deleted and there will not be any remaining team members after deletion, the field on the Opp should update to "No." 

 

  //------------------------------------------Before Delete----------------------------------------

    if(Trigger.isBefore && Trigger.isDelete){
    
        //create collections to store 1) IDs for Opportunities for deleted team member(s), 2) Actual Opportunity records with deleted Team Members, 3) Opps that will need to be updatead to say "No" not a Shared Opportunity
        Set<Id> oppIDs = new Set<ID>();
        List<Opportunity> oppsWithDeletedTeamMembers = new List<Opportunity>();
        List<Opportunity> oppsToUpdate = new List<Opportunity>();
        
    
        //loop through deleted team members and add their Opportunities to the list above
        for (OpportunityTeamMember deletedTM : trigger.old){
            oppIDS.add(deletedTM.OpportunityID);
            system.debug('[MF Debug] Opportunity field from deleted Team Member = ' + deletedTM.OpportunityID);
        }
        
        oppsWithDeletedTeamMembers = [SELECT Id FROM Opportunity WHERE id =: oppIDs];
        system.debug('[MF DEBUG] Opps with Deleted Team Member = ' + oppsWithDeletedTeamMembers);
        
        /*
        *Loop through the Opportunities in the OppsWithDeleteTeamMembers list and see how many team members pre-deletion. 
        *If it's less than or equal to 1, the Opp will no longer be considered shared after that team member is deleted.
        */
        for (Opportunity opp : oppsWithDeletedTeamMembers){
            List<OpportunityTeamMember> currentTeamMembers = [SELECT ID FROM OpportunityTeamMember WHERE OpportunityID =: opp.ID];
            Integer currentTeamMemberCount = currentTeamMembers.size();
            system.debug('[MF DEBUG] currentTeamMemberCount = :' + currentTeamMemberCount);
            
            if(currentTeamMemberCount <= 1){
                opp.SharedOpportunity__c = 'NO';
                oppsToUpdate.add(opp);
            }
        }
               
        update OppsToUpdate;
            
    }

 

Hello:

 

I have two unrelated objects that have the same Name value that I am attempting to write a code for to update a field.

 

I am trying to update the CBW_Rev_Share__c value using a formula with a value from Site__c

 

Below is my code. I am not getting a value back in the CBW_Rev_Share__c field.

trigger RevShareUpdate on Penetration_Summary__c (before insert, before update) {

Set<String> penSumName = new Set<String>(); 

for (Penetration_Summary__c pen : Trigger.new) {
    if(pen.Current__c == TRUE) {
        penSumName.add(pen.Name);
    }
} 
Set<String> releaseNameStrs = new Set<String>();
Map<String, Release__c> releaseSumMap = new Map<String, Release__c>();
for(Release__c release1:[Select ID, Name, CBW_Rev_Share__c, CBW_Rev_Share__r.Tier_One__c from Release__c Where Name IN: penSumName ]) {
    releaseSumMap.put(release1.Name, release1);
    releaseNameStrs.add(release1.Name);
}


List<Penetration_Summary__c> penForUpdate = new List<Penetration_Summary__c>();

for(Penetration_Summary__c c:[Select Id, Name, CBW_Rev__c, CBW_Rev_Share__c from Penetration_Summary__c where Name In : releaseNameStrs ]) {
if(releaseSumMap.containsKey(c.Name))
{
if(releaseSumMap.get(c.Name).CBW_Rev_Share__r.Tier_One__c != null && c.CBW_Rev__c != null)
c.CBW_Rev_Share__c = (releaseSumMap.get(c.Name).CBW_Rev_Share__r.Tier_One__c * c.CBW_Rev__c);
else
c.CBW_Rev_Share__c = 0; 
penForUpdate.add(c);
}
}
}

 

Thanks,

 

Hampton

When a parent Case gets updated, how can I set up a trigger to update all the childcases? I don't need to update any of the fields on the child, just need the modified date to change.

 

Here is what I have so far but it is not working correctly.

 

trigger updateRelatedCasesfromParent on Case (after update) {
    
If(Trigger.isUpdate){
     
    Set<ID> ids = new Set<ID>();
     list<Case> updatedParents = [SELECT Id, reason FROM Case 
                 WHERE Id in :ids];
     List<Case> childrenToUpdate = new List<Case>();

         //Then loop through each parent object in 'updated parent
         for ( Case p : updatedParents) 
         { 
                //and loop thru each kid in the child set}
               for(Case kid : p.Cases) 
               { 
                    childrenToUpdate.add(kid);
                }
        }
       //if( !childrenToUpdate.isEmpty)
       //{
            update childrenToUpdate;
       //}
}
}

 Thanks for the help.

  • May 08, 2013
  • Like
  • 0

Hi all.

concatinate_name_and_phone__c,concatinate_name_and_email__c are formula fields which holds (fullname+email)&(fullname+phone)
i need is, i need to show error when ever (fullname+email) or (fullname+phone) exists.Im not getting where iam missing.

Is formula fields works before insert????

This trigger shows an error message when email+name or name+phone already exists and give a old record link to open that record.
 This trigger shows an error message when email already exists and give a old record link to open that record. 

trigger TriggerOnLead on Lead (before insert) {
 
    Map<String, Lead> mapLead1 = new Map<String, Lead>();
    SYSTEM.DEBUG('!!!!!!!!!!mapLead1!!!!!!!!!!!'+mapLead1);
    Map<String, Lead> mapLead2 = new Map<String, Lead>();
    SYSTEM.DEBUG('+++++++++++mapLead2 +++++++++++++++'+mapLead2 );

    for (Lead lead : System.Trigger.new) {
          mapLead1.put(lead.concatinate_name_and_email__c.TOLOWERCASE().TRIM(), lead);
          mapLead2.put(lead.concatinate_name_and_phone__c.TOLOWERCASE().TRIM(), lead);
    }
     list<lead> lead1= new list<lead>([SELECT Id,Name,Email,Phone,concatinate_name_and_email__c FROM Lead WHERE concatinate_name_and_email__c  IN :mapLead1.KeySet()]);
   
    list<lead> lead2=[SELECT Id,Name,Email,Phone,concatinate_name_and_phone__c FROM Lead WHERE concatinate_name_and_phone__c IN :mapLead2.KeySet()];
    for (Lead lead4 : System.Trigger.new) {
      if(lead4.Any_way_save_record__c!=true)
      {
  
     if (lead.concatinate_name_and_email__c != null) 
    {
     for (Lead lead :lead1){
      Lead newLead = mapLead1.get(lead.concatinate_name_and_email__c.TOLOWERCASE().TRIM());
       SYSTEM.DEBUG('*************mapLead1************************'+mapLead1);
         SYSTEM.DEBUG('@@@@@@@@@newLead@@@@@@@@@@@@@@@'+newLead);
        newLead.addError('see lead<a style=color:GREEN href=/apex/leaderror?id='+LEAD.ID+'>'+  lead.name + '</a>');
  
    }}else  if (lead.concatinate_name_and_phone__c != null) 
    for (Lead lead :lead2 ) {
      Lead newLead1 = mapLead2.get(lead.concatinate_name_and_phone__c.TOLOWERCASE().TRIM());
      SYSTEM.DEBUG('%%%%%%%%%%%%newLead1%%%%%%%%%%%%%%%%%%'+newLead1);
      
        
       newLead1.addError('see lead<a style=color:GREEN href=/apex/leaderror?id='+LEAD.ID+'>'+  lead.name + '</a>');

  
    }
    
   }
}
}

 

 it is saving with out giving any error(when phone&Name  is given same

 

I have two pagelayouts on case one for closed case and one for  case open status. for Open case pagelayout  a VF page added to custom console component rightside panel, where as for the closed page laytout there is no VF page added to custom console component.

If I create a case by cloning the closed case, for the new case the custom console component is not coming. even if I refresh all tabs or browser still the new case showing the closed case pagelayout only.

Can any body plz help on this.


Thanks
  • June 10, 2014
  • Like
  • 0
Hi,
I have a trigger  to delete cases created from bounce mails or undeliverable email (email- to-case). The triiger is not working and i am getting  the below error

The following errors were encountered while processing an incoming email:

INVALID_CROSS_REFERENCE_KEY : invalid cross reference id INVALID_CROSS_REFERENCE_KEY : invalid cross reference id

My triiger code----------------------------


trigger deleteOutOfOfficeEmailAndCases on EmailMessage (after insert) {
   
    if(trigger.isinsert && trigger.isAfter)
    {
         Set<Id> deleteEmailIds = new Set<Id>();
         set<Id> deleteCaseIds = new Set<Id>();
         List<EmailMessage> emailMsgdeleteList = new List<EmailMessage>();
         List<case> deleteCasesList = new List<Case>();
         Set<Id> applicableCaseRecTypes = new Set<Id>();        
         List<Attachment> emailAttachmentDeleteList = new List<Attachment>();
       
        
         for(EmailMessage em : trigger.new)
         {
              if(em.Incoming == true && em.ReplyToEmailMessageId == null)
                {
                    //Bounced Email delete
                    if(em.FromAddress != null)
                    {
                        // the email statarts with 'mailer-daemon' or postmaster are the bounce email address
      if(em.FromAddress.containsIgnoreCase('mailer-daemon') ||em.FromAddress.containsIgnoreCase('postmaster'))
                            deleteEmailIds.add(em.id);
                    }
                   
                }
         }        
         if(!deleteEmailIds.isEmpty())
         {
             for(Attachment atmt :[select Id,ParentId from Attachment where parentId in :deleteEmailIds])
             {
                 emailAttachmentDeleteList.add(atmt);
             }
             for(EmailMessage email : [select id, parentId from EmailMessage where id in :deleteEmailIds])
             {
                 emailMsgdeleteList.add(email);
                 deleteCaseIds.add(email.parentId);
             }
             if(!deleteCaseIds.isEmpty())
             {
                 for(Case c : [select id,casenumber, subject from case where id in :deleteCaseIds])
                 {
                    deleteCasesList.add(c);
                 }
             }        
             if(!emailMsgdeleteList.isEmpty())
             {
                 if(!emailAttachmentDeleteList.isEmpty())
                        delete emailAttachmentDeleteList;
                 delete emailMsgdeleteList;
                
                 if(!deleteCasesList.isEmpty())
                     delete deleteCasesList;
             }
         }        
   }                      

}

Can any body plz let me know how to do this.

Thanks

  • January 13, 2014
  • Like
  • 0

Hi,

 

I can able to export upto 2000 records in VF page into excel. how to export more than 2000 records into excel?

 

Can anybody  please help on this.

 

 

 

  • March 19, 2013
  • Like
  • 0

Hi,

 

Can someone help on this issue.

 

For Reporting purpose  we are population a field  on parent object with all related list records separated by new line.

 

Example:

 

Object B has master detail Relationship with ObjectA. 

Let say 3 records  Record1, Record2, Record3  Of ObjectB realted to One Record of ObjectA.

ObjectBSummry is a field on Object A

We are using trigger to Populate  ObjectBSummry by using trigger.

 

Now the value of field ObjectBSummry :

 

Record1

Record2

Record3

(we have used \n character to see values )

 

But when we create a Report on objectA and export value into Excel the newline character is not working

 

The field value ObjectBSummry  is : Record1Record2Record3.

 

But we want the field value in excel also same as UI :

Record1

Record2

Record3

 

 

Is there any keyword we can use in Apex that works same as ALT+ Enter in Excel.

 

Here is my class code and trigger code.

 

public class InvoiceLineitemsSummary{

  public static void LineItemsSummary(Map<Id,Line_Item__c> LineItemsMap){
   
   set<Id> InvoiceIds = new Set<Id>();
   for( Id id:LineItemsMAp.keySet())
       InvoiceIds.add(LineItemsMap.get(id).Invoice_Statement__c);
   List<Line_Item__c> LineItems = [select Invoice_Statement__c,Merchandise__r.Name, Units_Sold__c , value__c from Line_Item__c
                                     where Invoice_Statement__c in:InvoiceIds];
   Map<Id, String> invToLineitemMap = new Map<Id, String>();
   for(Line_Item__c li:  LineItems)
   { 
       if(!invToLineitemMap.containsKey(li.Invoice_Statement__c))
           invToLineitemMap.put(li.Invoice_Statement__c,li.Merchandise__r.Name +'-'+ li.Units_Sold__c +'-'+ li.value__c +'\n');
       else
       invToLineitemMap.put(li.Invoice_Statement__c,invToLineitemMap.get(li.Invoice_Statement__c)+ li.Merchandise__r.Name + '-'+ li.Units_Sold__c +'-'+li.value__c +'\n');
   }
   List<Invoice_Statement__c> InvList  = [select id, Invoices_Summary__c from  Invoice_Statement__c where Id in: InvoiceIds];
   List<Invoice_Statement__c> InvUpdates = new List<Invoice_Statement__c>();
   for(Invoice_Statement__c inv : InvList)
   {
     inv.Invoices_Summary__c =  invToLineitemMap.get(inv.id);
     InvUpdates.add(inv);
   }
    update InvUpdates;
 }
}

 Trigger code:

 

rigger InvoiceLineitesSummaryTrigger on Line_Item__c (after insert,after delete,after Update) {

  if((trigger.isInsert || trigger.isUpdate)&& trigger.isAfter)
  {   
   InvoiceLineitemsSummary.LineItemsSummary(trigger.newMap);
 
  } else if(trigger.isDelete && trigger.isAfter)
  {
     InvoiceLineitemsSummary.LineItemsSummary(trigger.oldmap);
  }
}

 

 the new line character in code is workin in UI and when i export report results into csv.

But  it is nou working when i export report results into .xls format.

 

 

 

 

 

  • November 29, 2012
  • Like
  • 0

How to populate a field on account object with status of most recent contract (based on contract Start Date value)? contract object has look up relation with account.

 

To do this Apex code is required? or is there any way using formula field. 

  • November 05, 2012
  • Like
  • 0
1. custom object called invoice with field as
     a.invioce number(auto number)
     b.invioce date( date)
     c.Account Name(lookup with Account)
     d.invioce Amount(Roll up Summary,sumof allitems Price field of invioce Line Items object)
2.custom object called invoice Line Items with field as
    a.Invioce( Master Detail with Invioce)
    b.Product(Lookup with product)
    c.Quantity(Number)
     d.Unit Price(Currency)will contain price of one product
    e.Total Price((Formula, Quantity*Unit Price

My requirement:
Creat a  trigger on invoice line item to update account balence as sum fo all associated invoices amount for the account.(Create a custom field on Account Called "Account Balance" as currency data type)
Hi,
I have a trigger  to delete cases created from bounce mails or undeliverable email (email- to-case). The triiger is not working and i am getting  the below error

The following errors were encountered while processing an incoming email:

INVALID_CROSS_REFERENCE_KEY : invalid cross reference id INVALID_CROSS_REFERENCE_KEY : invalid cross reference id

My triiger code----------------------------


trigger deleteOutOfOfficeEmailAndCases on EmailMessage (after insert) {
   
    if(trigger.isinsert && trigger.isAfter)
    {
         Set<Id> deleteEmailIds = new Set<Id>();
         set<Id> deleteCaseIds = new Set<Id>();
         List<EmailMessage> emailMsgdeleteList = new List<EmailMessage>();
         List<case> deleteCasesList = new List<Case>();
         Set<Id> applicableCaseRecTypes = new Set<Id>();        
         List<Attachment> emailAttachmentDeleteList = new List<Attachment>();
       
        
         for(EmailMessage em : trigger.new)
         {
              if(em.Incoming == true && em.ReplyToEmailMessageId == null)
                {
                    //Bounced Email delete
                    if(em.FromAddress != null)
                    {
                        // the email statarts with 'mailer-daemon' or postmaster are the bounce email address
      if(em.FromAddress.containsIgnoreCase('mailer-daemon') ||em.FromAddress.containsIgnoreCase('postmaster'))
                            deleteEmailIds.add(em.id);
                    }
                   
                }
         }        
         if(!deleteEmailIds.isEmpty())
         {
             for(Attachment atmt :[select Id,ParentId from Attachment where parentId in :deleteEmailIds])
             {
                 emailAttachmentDeleteList.add(atmt);
             }
             for(EmailMessage email : [select id, parentId from EmailMessage where id in :deleteEmailIds])
             {
                 emailMsgdeleteList.add(email);
                 deleteCaseIds.add(email.parentId);
             }
             if(!deleteCaseIds.isEmpty())
             {
                 for(Case c : [select id,casenumber, subject from case where id in :deleteCaseIds])
                 {
                    deleteCasesList.add(c);
                 }
             }        
             if(!emailMsgdeleteList.isEmpty())
             {
                 if(!emailAttachmentDeleteList.isEmpty())
                        delete emailAttachmentDeleteList;
                 delete emailMsgdeleteList;
                
                 if(!deleteCasesList.isEmpty())
                     delete deleteCasesList;
             }
         }        
   }                      

}

Can any body plz let me know how to do this.

Thanks

  • January 13, 2014
  • Like
  • 0

Hello Friends!!!

 

I am trying to Generate Apex Classes from WSDL file.  But while parsing XML file getting below message.

 

Failed to parse wsdl: Unsupported Schema element found http://www.w3.org/2001/XMLSchema:attribute

 

Our WSDL contains below elements

 

<xs:attribute name="FactoryType" type="xs:QName"/>
<xs:attribute name="Id" type="xs:ID"/>
<xs:attribute name="Ref" type="xs:IDREF"/>

 

I referred Salesforce help site and w3school schemas referral sites and i found both supports attribute tag:

Salesforce help Site: http://www.salesforce.com/us/developer/docs/dbcom_apex250/Content/apex_callouts_wsdl2apex.htm

 

w3school XML Schema referral: http://www.w3.org/2001/XMLSchema

 

Please let me know if one knows about the same.

 

Thanks,

Pradip

 

String Names = '^Community$|^Luxury$|^Golf$|^Course$|^Hospitality$|^Industrial$|^';

 

 

 

My Code:

 

Names = (Names!= '' && Names!= null) ? Names.replaceAll('\\$|^,'') : '';
system.debug(Logginglevel.Info,'::::Names::::::::::'+Names);

 

Current output in Debug Log:

^Community$&#124;^Luxury$&#124;^Golf$&#124;^Course$&#124;^Hospitality$&#124;^Industrial$&#124;^Industrial$&#124;

 

Expected  Output:

 

Community,Luxury,Golf,Course,Hospitality,Industrial 

 

I'm attempting to write a trigger to create a new custom object record, when a Contact record meets specific criteria.  The problem is, the trigger is creating 2 records instead of 1.

 

Code below:

trigger createPreferenceWeb on Contact (before update) {
    
    List <rethink3__Requirements__c> prefToInsert = new List <rethink3__Requirements__c> ();
   
    
    for (Contact c : Trigger.new) {

        if (c.Web_To_Lead__c = true){  
        
        rethink3__Requirements__c p = new rethink3__Requirements__c ();
        
        p.rethink3__Contact__c = c.Name;
        p.rethink3__Contact__c = c.Id;
        p.Down_Payment_Available__c = c.Down_Payment_Available__c;
        p.Maximum_Price__c = c.Maximum_Price__c;

        
        prefToInsert.add(p);
        
        
        }
        
    }
    try {
        insert prefToInsert; 
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
    
}

 

Hello:

 

I have two unrelated custo objects that share a common key (Service_Order__c.Release__c = Resweep_Assignment__c.Name).

 

Both custom objects have date fields: Service_Order__c.Order_App_Date__c and Resweep_Assignment__c.Date_Assigned__c

 

What I am looking to do is to update a number field (Orders__c) with a count of Service_Order__c records where Service_Order__c.Order_App_Date__c is within 30 days of Resweep_Assignment__c.Date_Assigned__c.

 

Here is what I have, which is not saving. Any suggestions are greatly appreciated.

 

trigger ServiceOrderCount on Service_Order__c (after insert) {

     Set<String> serviceOrder = new Set<String>(); 
     for (Service_Order__c sord : Trigger.new) {
        serviceOrder.add(sord.Release__c);

     Map<String, Service_Order__c> sordMap = new Map<String,Service_Order__c>();
     for(Service_Order__c sord1 : [Select Name, Order_App_Date__c, Release__c from Service_Order__c where Name in : serviceOrder and Video__c=1]);
     sordMap.put(sord1.Release__c, sord1);

     Map<String, Resweep_Assignment__c> resweepMap = new Map<String, Resweep_Assignment__c>();
     for(Resweep_Assignment__c resweep1: [Select Name, Date_Assigned__c, Orders__c from Resweep_Assignment__c where Name in : serviceOrder]);
     resweepMap.put(resweep1.Name, resweep1);

     Set<String> resweepDate = new Set<String>();
     resweepDate.add(resweep1.Date_Assigned);

     integer i = [Select Count() from Service_Order__c where Name =: serviceOrder and (resweepDate < Order_App_Date__c < resweepDate+30)];

     List<Resweep_Assignment__c> resweepToUpdate = new List<Resweep_Assignment__c>();
          for(Resweep_Assignment__c a : [Select Name, Date_Assigned__c, Orders__c where Name in : serviceOrder]){
               if(serviceOrderMap.containskey(a.Name){
                    a.Orders__c = i;
               resweepToUpdate.add(a);
   }
 }
update resweepToUpdate
}

 Thanks,

 

Hampton

 

Hi ,

      I wrote a trigger on my custom object ,it is the child of opportunity object.Opportunity having Account field and My custom object also having Account field.if i update my custom object thus account field is updated with Parent object opportunity accountfield.

The trigger working fine but when i edit record and click on save.Than it shows error i.e,

Apex trigger EM_Key_Player_update_Account caused an unexpected exception, contact your administrator: EM_Key_Player_update_Account: System.LimitException: Too many query rows: 50001

 

Trigger:


trigger EM_Key_Player_update_Account on PW_Key_Players__c (after insert, after update) {

list<opportunity> opp=[SELECT Id,StageName,accountid FROM Opportunity WHERE RecordTypeId in (SELECT Id FROM RecordType WHERE (Name='IS_Opportunity') OR (Name='EM_IS_Speedi'))];
list<PW_Key_Players__c> lokp=[select id,name,PW_Account__c from PW_Key_Players__c];
list<opportunity> lopp=new list<opportunity>();
for(PW_Key_Players__c okp:trigger.new){
for(opportunity o:opp){
if(okp.EM_IS_WinAccCu__c==true){
o.accountid=okp.PW_Account__c;
lopp.add(o);
}

}
update opp;
}
}

I thought this can be achieve by bulk trigger,but i dont no exactly.Could anyone help me out.

 

Hi everybody,

 

I created a custom field that shows me for how long the status of a lead has been on "open". Now I want to be informed by mail as soon as a lead (or even better: a group of leads) exceeds a specified time span the lead has been on "open". 

Does anybody of you have any idea how this can be done?

 

Thanks in advance for your support.

 

Tim

Hello!

 

I have some code listed below that I was hoping someone would be able to help me troubleshoot.  The code is supposed to assign the owner of a Lead based on what Account Team of the User.  So when the lead is created, if select "Storefront" for Lead_Direction__c picklist, then it should assign to the Account Team Member on the Account labeled as 'Storefront Associate'.  If the I select Big Deal in the picklist, then it should assign to the Account Team Member for the associated Account labeled as the 'Big Deal Associate'.  It works when I select Storefront in the Lead Direction and assigned the appropriate rep, but it doesn't assign correctly to the Big Deal Rep.

 

trigger OpportunityTrigger on Lead (before insert){

    List<String> accountIds = new List<String>();
    
    List<AccountTeamMember> parentAccounts = new List<AccountTeamMember>();
    
    for(Lead lead : Trigger.new){
    
        accountIds.add(lead.Account__c);    
    }
    
    parentAccounts = [Select AccountId, UserId, TeamMemberRole from AccountTeamMember where AccountId in :accountIds];
    
    Map<String,AccountTeamMember> accountMap = new Map<String,AccountTeamMember>();
    
    for(AccountTeamMember a : parentAccounts){
    
        accountMap.put(a.AccountId,a);
    }
    
    for(Lead lead : Trigger.new){
    
        AccountTeamMember parentAccount = accountMap.get(lead.Account__c);
        String memberRole = accountMap.get(lead.Account__c).TeamMemberRole;
        
        if((parentAccount != null)&&(memberRole == 'Storefront Associate')&&(lead.Lead_Direction__c == 'Storefront')){
        
            lead.OwnerId = parentAccount.UserId;
            
        }
        
        else if((parentAccount != null)&&(memberRole == 'Big Deal Associate')&&(lead.Lead_Direction__c == 'Big Deal')){
        
            lead.OwnerId = parentAccount.UserId;
          
        }
        
        else{
        
        lead.OwnerId = lead.OwnerId;
        
        }
        
    }
}

 

Hi,

I have completed the batch class and scheduler class which works fine but need help in creating test class.

Can someone please guide me on how to begin with it.

 

Batch class:

global class oppupdates implements Database.Batchable<sObject>{
    public String query;
    public String email;
    public Set<Id> setCaseId = new Set<Id>();
    //list <Case> objcase;
    public List<Opportunity> lstOppty= new List<Opportunity>();
    public List<Case> lstCase;
    public String SumLicense;
    public Integer CountOpportunity;
    public Double SLic = 0;
    public Decimal conRate=2;
    public String accId;
    
     
    global Database.querylocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<sObject> scope){
         lstCase = new list<Case>();// ([select id, Status from Case]);
                         
        for(sObject s : scope){Case c = (Case)s;
            {
                setCaseId.add(c.Id);
                      }
        }
          
        
        //objcase = trigger.new;
 List<Case> lstCase = [Select Id, AccountId,Status from Case where Id IN :setCaseId and AccountId != null 
order by AccountId];
List<Id> accountIdList = new List<Id>();
Map<Id, Case> account2CaseMap = new Map<Id, Case>();
List<Case> cs = new List<Case>();

 

// collect the account id's into a list and create a map of account id to case
for (Case case1 : lstCase) {
    accountIdList.add(case1.AccountId);
    account2CaseMap.put(case1.AccountId, case1);
}

 

// get opportunities for all accounts of interest
lstOppty = [Select Id, Name, Probability,accountid, Amount from Opportunity
where AccountId in : accountIdList
AND StageName IN ('Qualification','Prospecting')
AND CloseDate = THIS_QUARTER
AND CloseDate <= NEXT_QUARTER order by AccountId];


//CountOpportunity = lstOppty.size();
Id previousAcctId = null;
//SLic = 0;
//Decimal conRate = ?
Integer oppCount = 0;
Integer caseIndex = 0;
for (Opportunity opp: lstOppty){
    String thisAcctId = opp.AccountId;
    
    //system.debug('IIIIIIIIIIaccid' + thisAcctId);
   // system.debug('IIIIIIIIIIopp.accid' + opp.AccountId);
    
    if (thisAcctId != previousAcctId) {
        if (previousAcctId != null) {
            // skip past any non matching account id's - should not be any
            while ((caseIndex < lstCase.size()) && (lstCase[caseIndex].AccountId != previousAcctId)) 
                caseIndex++;
            while ((caseIndex < lstCase.size()) && (lstCase[caseIndex].AccountId == previousAcctId)) {
                Case c = lstCase[caseIndex];
            
                if ((c != null) && (c.Status !=null)) {
              
                    c.SumLicence__c = SLic;
                    
                    c.Total_opp__c = oppCount;
                   
                //c.Status = 'Working';
                    cs.add(c);            
                }
                caseIndex++;
            }
        }
        previousAcctId = thisAcctId;
        SLic = 0;
        oppCount = 0;
        
    }
    oppCount++;
  
                
                
    if(opp.Amount != null){
        SLic += opp.Amount*conRate;
      
    }

}
// handle the opportunities for the last account
            while ((caseIndex < lstCase.size()) && (lstCase[caseIndex].AccountId == previousAcctId)) {
                Case c = lstCase[caseIndex];
                if ((c != null) && (c.Status !=null)) {
                
                    c.SumLicence__c = SLic;
                    c.Total_opp__c = oppCount;
                //c.Status = 'Working';
                    cs.add(c);            
                }
                caseIndex++;
            }
           // Database.DMLOptions dml = new Database.DMLOptions();
          // dml.optAllOrNone = false; // tried true also                
          //  database.update(cs,false);
Update cs;
}      

        //SumLicense = SLic;
  
        
   
    global void finish(Database.BatchableContext BC){
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        mail.setToAddresses(new String[] {email});
        mail.setReplyTo('batch@acme.com');
        mail.setSenderDisplayName('Batch Processing');
        mail.setSubject('Batch Process Completed');
        mail.setPlainTextBody('Batch Process has completed');
        
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
}

 

Scheduler class:

 

global class oppaccount implements Schedulable{ 
  global void execute(SchedulableContext SC) {
oppupdates opp = new oppupdates();
opp.query = 'Select Id, AccountId,Status from Case where Status =\'' + 'Working' + '\'';
opp.email='j1j2test@yahoo.com';
Database.executeBatch(opp);
}
}

 

I am fairly new to the Apex crowd but I have created two objects that have Master Detail Relationship.  The Commission Rec object is the master and Order Entry as the child.  I am creating a VF Page to render as PDF to be used as a report.  I can use the Standard Controller for the information I need to display from the Commission Rec and the information from the Order Entry is all contained in the Related List.  The problem is that the Order Entry contains a Sales Rep field that I need to group the results by and then subtotal both the Total and Commission Paid fields.  My thought has been that I could just write a controller extension for the Commission Rec object and use the AggregateResults and Group By funtions but I am having a hard writing the extention.  I have tried to leverage the various examples I have seen on the web of how to write the new list but I am really having a hard time finding an example that is as simple as what I need.  I don't have to filter any data and I am pulling records that are already defined in a one-to-many relationship.  Does anyone have an example of code that will take a standard related list and group and subtotal the results?

 

thank you,

Bryan