• Ajay0105
  • NEWBIE
  • 0 Points
  • Member since 2012

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

I am creating a opportunity in salesforce and when i change the owner to the new owner.. Previous owner will be getting changed updated in the related list of the Opportunity.team.

 

but when i am doing the same from partner portal i mean creating the opportunity and changing the owner previous owner will not be updating in the related list of the opportunity team

 

any one have any idea what exactly is the problem...

 

Method -->

 

public static void UpdateOpportunityTeam(List<Opportunity> oldOpps, List<Opportunity> newOpps){
       
        Set<Id> OppSet = new Set<Id>{};
        
        for(Opportunity opp : newOpps) {
            OppSet.Add(opp.Id);          
        }   
        List<OpportunityTeamMember>  ExistingOppTeamMembers = [SELECT OpportunityId, Id, UserId  
                                                                  FROM OpportunityTeamMember WHERE OpportunityId in :OppSet 
                                                                  AND IsDeleted = false];
      
        set<Id> OppUId = new set<id>();
       
        for(OpportunityTeamMember oppTeam : ExistingOppTeamMembers){ 
            OppUId.add(oppTeam.UserId);}
        
        List<OpportunityTeamMember>     listOppShare   = new List<OpportunityTeamMember>(); 
        set<Id> OppId = new set<id>();
    
       Set<Id> OwenerId = new Set<Id>();          
       for(Integer i=0; i<newOpps.size(); i++){         
           if (newOpps[i].OwnerId !=oldOpps[i].OwnerId && !OppUId.contains(oldOpps[i].CreatedById)){
            OppId.add(newOpps[i].Id);
            OwenerId.add(oldOpps[i].CreatedById);
            listOppShare.add(new OpportunityTeamMember(OpportunityId=newOpps[i].Id,UserId=oldOpps[i].CreatedById,TeamMemberRole='PartnerNet Member'));  
            system.debug('inside UpdateOpportunityTeam :: created new OpportunityTeamMember'+newOpps.size());      
           }
       }
       
       insert listOppShare;
       
       if(OppId.size()>0){         
       List<OpportunityShare> shares = [select Id, OpportunityAccessLevel, 
                                        RowCause from OpportunityShare 
                                        where OpportunityId IN :OppId and 
                                        RowCause = 'Team' and 
                                        UserOrGroupId IN:OwenerId];
    
       for(OpportunityShare share : shares) 
            share.OpportunityAccessLevel = 'Edit';
                                                    
       update shares;}
       //RowCause = 'Team' and 
    }

Apex Test Result Detail  

Time Started 4/4/2013 1:28 PM Class QuoteManager_Test Method Name invokeTestMethod Pass/Fail Fail Error Message System.NullPointerException: Attempt to de-reference a null object Stack Trace Class.QuoteManager.updatePartnerCBMDetails: line 43, column 1
Class.QuoteManager_Test.invokeTestMethod: line 41, column 1

 

Please advice me what should I do to successfully run my test case.

===================================================================================

public with sharing class QuoteManager {

  /* REPLACES trigger QuoteFieldUpdates on Quote__c (before insert, before update)*/
  
   private static List<Opportunity> OppList;

    public static List<Opportunity> getOppISVTeamMembersDetails(Set<Id> opportunityIds)
    {
        if (OppList == null){
            OppList = [SELECT Partner_CBM__c, End_User_Account_Owner__c FROM Opportunity WHERE Id in:opportunityIds];
        }
        return OppList;
    }
    
    private static List<Quote_Part__c > QuotePartsList;

    public static List<Quote_Part__c> getQuotePartsDetails(Set<Id> requiredQuoteIDs)
    {
        if (QuotePartsList == null){
            QuotePartsList = [SELECT Product_Category__c, 
                              Margin_Percent__c,Product_Code__c, 
                              Quote_Ref__c,Margin_Net_Dollars__c,CurrencyISOCode 
                              FROM Quote_Part__c
                              WHERE Quote_Ref__c =: requiredQuoteIDs 
                              AND Product_Category__c != 'Multi Product Accessory' 
                              AND Product_Category__c != 'Media' 
                              AND Product_Category__c != 'Service' 
                              AND Product_Category__c != 'Software' 
                              AND Product_Category__c != 'ProductLinks' 
                              AND Product_Category__c != 'OEM' 
                              AND Margin_Net_Dollars__c != null
                              ORDER BY Margin_Net_Dollars__c];
        }
        return QuotePartsList;
    }
    
    public static void updatePartnerCBMDetails(List<Quote__C> newQuote)
    {
        Map<Id, Opportunity> oppMap = new Map<Id, Opportunity>();
        
        List<Opportunity> oppsData = new List<Opportunity>();
       
        Set<ID> opportunityIds = new Set<ID>();                            // this line I am getting an error while running the test case.
         
        if (trigger.isUpdate && !QuotePartManager.isInsert)
        {
            for (Quote__c quote :newQuote)
            {
            opportunityIds.add(quote.Opportunity_Name__c);
            }
            /*oppsData = [SELECT Partner_CBM__c, End_User_Account_Owner__c FROM Opportunity WHERE Id in :opportunityIds];*/
            oppsData =getOppISVTeamMembersDetails(opportunityIds);
            
            for(Opportunity opp : oppsData) {
            oppMap.put(opp.Id, opp);
            }  
        }
  
        for (Quote__c quote :newQuote)
        {
            if (trigger.isInsert)
            {
              quote.Owner_Lookup__c = quote.OwnerID;  
            }
            if (trigger.isUpdate)
            {
              if(quote.Owner_Lookup__c != quote.OwnerId)
              {
                quote.Owner_Lookup__c = quote.OwnerID;  
              }
              if(oppMap.get(quote.Opportunity_Name__c) != null)
              {
                if(oppMap.get(quote.Opportunity_Name__c).Partner_CBM__c != quote.Partner_CBM__c)
                {
                  quote.Partner_CBM__c = oppMap.get(quote.Opportunity_Name__c).Partner_CBM__c;  
                }
                if(oppMap.get(quote.Opportunity_Name__c).End_User_Account_Owner__c != quote.End_User_Account_Owner__c)
                {
                  quote.End_User_Account_Owner__c = oppMap.get(quote.Opportunity_Name__c).End_User_Account_Owner__c;  
                }
              }  
            }
    }
    }
    
  /* REPLACES trigger QuoteBeforeDelete on Quote__c (before delete)*/
    public static void QuoteBeforeDelete(List<Quote__c> oldQuotes)
    {
    for (Quote__c quote : oldQuotes)
    {
      if (quote.Main_Quote__c)
      {
        if(!Test.isRunningTest())
        {
          quote.addError('You cannot delete a Main Quote. Uncheck the Main Quote checkbox on the Quote prior to deleting.');
        }
      }
    }
    }

 
  /*
    
    REPLACES trigger populateMarginsFromQuoteParts on Quote__c (before update)
    Trigger to assign field values "Lowest_Margin_Percent__c" and "Highest_Margin_Net_Value__c" on EDIT of a Quote:
    IF(Quote__c.Quote_Type__c EQUALS 'Hardware' AND PE.Approval_Stage__c EQUALS 'In Review') 
    ONE:
    o   Evaluate all HW Quote Parts WHERE Product_Category__c NOT EQUALS Media, Service, Software, ProductLinks, OEM:
    o   return item with lowest overall margin percentage (Margin_Percent__c)
    o   Capture that Item's corresponding Product_Code__c, Margin_Net_Dollars__c, and Margin_Percent__c into text field(s) on the Quote
    TWO:
    o   Evaluate all HW Quote Parts WHERE Product_Category__c NOT EQUALS Multi Product Accessory, Media, Service, Software, ProductLinks, OEM:
    o   return item with highest total margin dollar value (Margin_Net__Dollars__c) that has the lowest margin percentage (Margin_Percent__c)
    o   Capture that Item's corresponding Product_Code__c, Margin_Net_Dollars__c, and Margin_Percent__c into text field(s) on the Quote 
    
  */
  public static void populateMarginsFromQuoteParts(List<Quote__c> newQuotes)
  {
    /*Set of Quote IDs for which the Margins from Quote Parts should be calculated*/
    Set<Id> requiredQuoteIDs = new Set<Id>();
    Quote__c[] Quotes = new Quote__c[]{};
    for(Integer i=0; i < newQuotes.size(); i++)
    {
        if(newQuotes[i].HW_Approval_Stage__c == 'In Review')
        {
            system.debug('Approval is IN REVIEW');
            requiredQuoteIDs.add(newQuotes[i].Id);
            Quotes.add(newQuotes[i]);
        }
    }
    
    /*     
     Map of Quote ID and List of Quote Parts under that Quote - Lowest Margin Percent       
    */
    
    Map<Id,List<Quote_Part__c>> quotePartsMapLowestMarginPercent = new Map<Id,List<Quote_Part__c>>();
    
    /*    
    Map of Quote ID and List of Quote parts under that Quote - HIghest Margin Dollar Value    
    */
    
    Map<Id,List<Quote_Part__c>> quotePartsMapHighestMarginValue = new Map<Id,List<Quote_Part__c>>();
    
    /*    
    Query through all Line Items (WHERE Product_Category__c NOT EQUALS Media, 
    Service, Software, ProductLinks, OEM)    
    */
    if (!requiredQuoteIDs.isEmpty()){
      system.debug('requiredQuoteIDs contains ID');
      
    /*  
     FIRST ELEMENT --> LOWEST MARGIN PERCENT*
    */
    for(Quote_Part__c qpLi:getQuotePartsDetails(requiredQuoteIDs))
      {
          if(quotePartsMapLowestMarginPercent.get(qpLi.Quote_Ref__c) == null)
          {
              quotePartsMapLowestMarginPercent.put(qpLi.Quote_Ref__c, new List<Quote_Part__c>{ qpLi });
          }
          else
          {
              quotePartsMapLowestMarginPercent.get(qpLi.Quote_Ref__c).add(qpLi);
          }
          
      }
      system.debug('LowestMarginPercent map size is '+quotePartsMapLowestMarginPercent.size());
      /*
      Query through all Quote Parts (WHERE Product_Category__c NOT EQUALS Multi Product Accessory, Media, Service, Software, ProductLinks, OEM)
      */
     for(Quote_Part__c qpLi:getQuotePartsDetails(requiredQuoteIDs))
      {
          if(quotePartsMapHighestMarginValue.get(qpLi.Quote_Ref__c) == null)
          {
              quotePartsMapHighestMarginValue.put(qpLi.Quote_Ref__c, new List<Quote_Part__c>{ qpLi });
          }
          else
          {
              quotePartsMapHighestMarginValue.get(qpLi.Quote_Ref__c).add(qpLi);
          }
      }
      system.debug('HighestMarginValue map size is '+quotePartsMapHighestMarginValue.size());
    }
    /*Loop through Price Exceptions being updated and assign Value*/
    if (!Quotes.isEmpty())
    {
      system.debug('Quotes Loop begins');
      for(Quote__c Quote: Quotes)
      {
          if(quotePartsMapLowestMarginPercent.get(Quote.Id) != null && quotePartsMapLowestMarginPercent.get(Quote.Id).size() > 0)
          {
              system.debug('Lowest Percent Margin Percent is '+quotePartsMapLowestMarginPercent.get(Quote.Id)[0].Margin_Percent__c);
              String marginValueFormat = quotePartsMapLowestMarginPercent.get(Quote.Id)[0].Margin_Net_Dollars__c.format();
              system.debug('Lowest Percent marginNetDollars is '+quotePartsMapLowestMarginPercent.get(Quote.Id)[0].Margin_Net_Dollars__c.format());
              system.debug('Lowest Percent marginValueFormat is '+marginValueFormat);
              if(marginValueFormat.contains('.'))
              {
                  List<String> marginDecimals = marginValueFormat.split('\\.');
                  
                  if(marginDecimals.size() == 2)
                  {
                      if(marginDecimals[1].length() == 1)
                      {
                          marginValueFormat = marginValueFormat + '0';
                      }
                  }
              }
              else
              {
                  marginValueFormat = marginValueFormat + '.00';
              }
              
              String lowestMarginPercent = 'P/N ' + String.valueOf(quotePartsMapLowestMarginPercent.get(Quote.Id)[0].Product_Code__c) + 
                             ', Margin Value=' + quotePartsMapLowestMarginPercent.get(Quote.Id)[0].CurrencyISOCode + ' ' + marginValueFormat + 
                             ', Margin %=' + String.valueOf(quotePartsMapLowestMarginPercent.get(Quote.Id)[0].Margin_Percent__c);
              
              //Assign to Field
              Quote.Quote_Part_Lowest_Lowest_Margin__c = lowestMarginPercent;
          }
          
          if(quotePartsMapHighestMarginValue.get(Quote.Id) != null && quotePartsMapHighestMarginValue.get(Quote.Id).size() > 0)
          {
              Integer index = quotePartsMapHighestMarginValue.get(Quote.Id).size() - 1;
              
              String marginValueFormat = quotePartsMapHighestMarginValue.get(Quote.Id)[index].Margin_Net_Dollars__c.format();
              system.debug('Highest Value marginNetDollars is '+quotePartsMapHighestMarginValue.get(Quote.Id)[index].Margin_Net_Dollars__c.format());
              system.debug('Highest Value marginValueFormat is '+marginValueFormat);
              if(marginValueFormat.contains('.'))
              {
                  List<String> marginDecimals = marginValueFormat.split('\\.');
                  
                  if(marginDecimals.size() == 2)
                  {
                      if(marginDecimals[1].length() == 1)
                      {
                          marginValueFormat = marginValueFormat + '0';
                      }
                  }
              }
              else
              {
                  marginValueFormat = marginValueFormat + '.00';
              }
              
              String highestMarginValue = 'P/N ' + String.valueOf(quotePartsMapHighestMarginValue.get(Quote.Id)[index].Product_Code__c) + 
                            ', Margin Value=' + quotePartsMapHighestMarginValue.get(Quote.Id)[0].CurrencyISOCode + ' ' + marginValueFormat + 
                            ', Margin %=' + String.valueOf(quotePartsMapHighestMarginValue.get(Quote.Id)[index].Margin_Percent__c);
              
              //Assign to Field
              Quote.Quote_Part_Highest_Margin_Lowest_Marg__c = highestMarginValue;
          }
      }
    }
  }
}

 

 

===============================================================================

 

This is my test class

 

@isTest
public with sharing class QuoteManager_Test {
    
    static testMethod void invokeTestMethod()
    {
    List<Account> alist = TestUtil.createTestAccounts(1, true);
    
    List<Opportunity> olist = TestUtil.createTestOpportunities(1, true, alist.get(0));
    
    Quote__c quote = new Quote__c(Opportunity_Name__c = olist.get(0).Id,Multiple__c = 100,Discount__c = 0,
                              Valid_Until__c = system.today().addDays(28),Sync_Required__c=true,Is_Portal_Quote__c=true,
                              HW_Approval_Stage__c='In Review',
                              Main_Quote__c=true,Type__c='Master',Status__c='Live'); 
    List<Quote__c> quoteList = new List<Quote__c>();
    
    quoteList.add(quote);
    
    //QuoteManager.QuoteBeforeDelete(quoteList);
    
   QuoteManager.populateMarginsFromQuoteParts(quoteList);
   QuoteManager.QuoteBeforeDelete(quoteList);
    
   //Opportunity[] testopps = TestUtil.createTestOpportunities(1, false, testaccts.get(0));
      
     Opportunity[] testopps = TestUtil.createTestOpportunities(1, false, alist.get(0));
    for (Opportunity to : testOpps)
    {
        to.PR_Admin__c = alist.get(0).Id;
        to.OwnerId = UserInfo.getUserId();
        to.End_User_Location_RCSM__c = alist.get(0).Id;
        to.End_User_Location_RVP__c = alist.get(0).Id;
        to.End_User_Account_Owner__c = alist.get(0).Id;
        to.Partner_CBM__c = alist.get(0).Id;
        to.Partner_CBM_Manager__c = alist.get(0).Id;
    }
    
    if(quoteList.get(0).HW_Approval_Stage__c == 'In Review'){
    
    }
    
    QuoteManager.updatePartnerCBMDetails(quoteList);
    }
    
    static testMethod void testupdatePartnerCBMDetails(){
     
    }
}

 

==================================================================

 

Hi 

 

I have write a workflow rule .Each time the condition met the email will send to the people who are in the group.

 

when the people in the group received the email he will see all the other peple in group.I dont want he can see other

 

person in the list.

 

My reqt was every person will receive the email as personalised one.I want the email to go to number of people but when they received the email they can see only there name in the mail not others.

Hi All,

 

I am creating a case using email-to-case feature Though I am successfully able to  create a case while sending an email.

 

Problem arises when I am attaching a .txt in a email and  try to open a case through I am successfully created a case  but

 

without the attachment or .txt file.

 

Could anyone help me how can I achieve it.

 

My requirement is I have to create a case everytime someone send a mail to a particular e-mail ID.and I want the .txt file

 

should also be get  when the case will get created.I want the attachment or .txt file should get attached in the case as attachment while creating a case

 

Problem-:. txt  file I am attaching in a e-mail will not be there in the case just created.

 

I have one soution tha I can go to Setup -> Cases -> Page Layout -> Edit -> choose related lists -> drag email into related lists. and I can see my attachment.

 

But want the accachment to get accached in the Attachment section. 

 

Can any one plz help me in achieving this through trigger ?????

 

Hi All,

 

My Requirement is 

 

 Account Is Record Type="Master Account Layout' and parent account is Null then HQ field set to True

 

I have Created a trigger for achieving above reqt

 

1
2
3
4
5
6
7
8
9
10
11

trigger accountTypeChange on Account (before Insert) {

for(Account acc :Trigger.new){
  If(acc.Record_Type__c == 'Master Account Layout' &&  (acc.Parent == null || acc.Parent.Record_Type__c == 'Virtual Acount Partner'))
{
   // acc.HQ__c =true;
}  
 insert acc; 
  
}
}

 

But as I want to insert the record on Account Object I am getting the error msg 

 

"Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger accountTypeChange caused an unexpected exception, contact your administrator: accountTypeChange: execution of BeforeInsert caused by: System.SObjectException: DML statment cannot operate on trigger.new or trigger.old: Trigger.accountTypeChange: line 8, column 1"

 

Plz Help me in rectifying the Issue..

 

 

Hi All,

 

I am creating a case using email-to-case feature Though I am successfully able to  create a case while sending an email.

 

Problem arises when I am attaching a .txt in a email and  try to open a case through I am successfully created a case  but

 

without the attachment or .txt file.

 

Could anyone help me how can I achieve it.

 

My requirement is I have to create a case everytime someone send a mail to a particular e-mail ID.and I want the .txt file

 

should also be get  when the case will get created.I want the attachment or .txt file should get attached in the case as attachment while creating a case

 

Problem-:. txt  file I am attaching in a e-mail will not be there in the case just created.

 

I have one soution tha I can go to Setup -> Cases -> Page Layout -> Edit -> choose related lists -> drag email into related lists. and I can see my attachment.

 

But want the accachment to get accached in the Attachment section. 

 

Can any one plz help me in achieving this through trigger ?????

 

Hi All,

 

My Requirement is 

 

 Account Is Record Type="Master Account Layout' and parent account is Null then HQ field set to True

 

I have Created a trigger for achieving above reqt

 

1
2
3
4
5
6
7
8
9
10
11

trigger accountTypeChange on Account (before Insert) {

for(Account acc :Trigger.new){
  If(acc.Record_Type__c == 'Master Account Layout' &&  (acc.Parent == null || acc.Parent.Record_Type__c == 'Virtual Acount Partner'))
{
   // acc.HQ__c =true;
}  
 insert acc; 
  
}
}

 

But as I want to insert the record on Account Object I am getting the error msg 

 

"Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger accountTypeChange caused an unexpected exception, contact your administrator: accountTypeChange: execution of BeforeInsert caused by: System.SObjectException: DML statment cannot operate on trigger.new or trigger.old: Trigger.accountTypeChange: line 8, column 1"

 

Plz Help me in rectifying the Issue..