• sasya.ravi
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 4
    Replies
i need quick help,
In my test class i am unable to cover the formula field.

I have a formula field Approved__C in opportunity object.That formula field holding the quote object field value ApprovalStatus__c.
i am inserting data in Quote object along with writeable field ApprovalStatus__c, but still i am not able to getting data into Opportunity formula field still it is showing null value.

 
Hi All,
Opportunity having lookup with Sales Target and master detail with Opportunity.
I want to update Sales Target field in Opportunity Split,based on common values of 3 fields in Sales target_c custom object.
and opportunity fields.
I am able to update the "Sales Target" field while creating the opportunity and editing ooportunity split and adding one more split person and saving the the split it is not updating.once again if i am editing and saving the record it is updating.
But field value must be update while saving the record for first time.

here is my class & Trigger.

public  class SalesTargetUpdationOnOppSplit {
    
   public static void Targetupdation(list<OpportunitySplit> oppsplt)
     {
         if(SalesTargetRecurtion.vbool==true)
           {
               SalesTargetRecurtion.vbool=false;
         Map<Id, Sales_Target__c> TargetMap=new Map<Id, Sales_Target__c>([Select Id, RecordTypeId,Sales_Person__c,   Year__c,    Q1__c,Q2__c,Q3__c,Q4__c,Depot__c,Hub__c,January__c,February__c  ,March__c,April__c,May__c,June__c,July__c,August__c,September__c,October__c,November__c,December__c, JobType__c from Sales_Target__c]);
         Map<string, String> salesTargetMap=new Map<string, string>();
         for(Id targetMapIds: TargetMap.keySet())
         {
             String personId = TargetMap.get(targetMapIds).Sales_Person__c;
             String targetMapKey=TargetMap.get(targetMapIds).JobType__c+String.ValueOf(TargetMap.get(targetMapIds).Year__c)+personID.subString(0,15);
             string targetMapValue=targetMapIds;
             //system.debug('targetMapValue'+targetMapValue);
             system.debug('#####Target Map Key = '+targetMapKey);
             salesTargetMap.put(targetMapKey, targetMapValue);
         }

//Logic is to compare the Opportunity Job type, Sales Person /Opp Owner , Year of Opportunity Booking and associate to appropriate opportunity record.
      Map<Id, OpportunitySplit> opps = new Map<Id, OpportunitySplit>([SELECT  id,
                                                        Opportunity.Job_Type__c,
                                                        Opportunity.CloseDate,
                                                        SplitOwnerid,
                                                        Sales_Target__c
                                                        FROM OpportunitySplit where id in : oppsplt]);
                                                 
                                                        
  list<OpportunitySplit> oppsplits = opps.values(); 
               
       list<String> vlststr=new list<string>();
       list<OpportunitySplit> vlsttoupdate = new list<OpportunitySplit>();
         system.debug('salesTargetMap=='+salesTargetMap);
       for(OpportunitySplit op: oppsplits)
       {               
           string splitOwnId = op.SplitOwnerid;
           system.debug('SplitOwnerId'+splitOwnId);
           system.debug('Jobtype'+op.Opportunity.Job_Type__c+ 'Year---' + String.ValueOf(op.Opportunity.CloseDate.year())+'ownerid'+splitOwnId);
           String targetKey= op.Opportunity.Job_Type__c+String.ValueOf(op.Opportunity.CloseDate.year())+splitOwnId.subString(0,15);
           system.debug('###Record id to be insert--->'+salesTargetMap.get(targetKey));
           system.debug('#####targetKey--->'+ targetKey);
           vlststr.add(targetKey);
           if(!vlststr.isEmpty())
           {
               op.Sales_Target__c=salesTargetMap.get(targetKey);
               system.debug('###sales target-->'+op.Sales_Target__c);
               vlsttoupdate.add(op);
               system.debug('####vlsttoupdate'+vlsttoupdate);
               
           }
           
       }
           
            if(!vlsttoupdate.isEmpty())
            {
                    system.debug('#Before vlsttoupdate1'+ vlsttoupdate);
                    Database.upsert(vlsttoupdate,false) ;
                    system.debug('vlsttoupdate1'+ vlsttoupdate);
            
           }
            system.debug('Inserted Records---->'+vlsttoupdate.size());
     }
    
}    
   
}

**************************************************************
trigger updateQuoteSplitOnOpportunitySplitEdit on OpportunitySplit (after insert,after update) {
 //if(testIfAddSplitEditSplitDone.runOnce()) { 
  //Start---03-
        //Build Map Keys for Split Type Id 
        //start--
       
           if(Trigger.isInsert && Trigger.isAfter )
           {
               system.debug('@@@@Entering insert');
               SalesTargetUpdationOnOppSplit.Targetupdation(trigger.new);
               system.debug('@@@@Exiting insert');
           }
          if(Trigger.isUpdate && Trigger.isAfter )
           {
               system.debug('@@@@Entering Update');
               SalesTargetUpdationOnOppSplit.Targetupdation(trigger.old);
               system.debug('@@@@Exiting Update');
           }
       }

 
Account having a checkbox field if that flag value is true then clicking on newopportunity button it should throw error?
Hello i want to create contact and opportunity from Accounts detail page by using button.

i created controller extention but it created contact and opportunities they are not related to that particular account.

 here is my code :
public class OppClass3
    {
      Public Account Account;
      public Opportunity opportunity;
      public contact contact;
      public string ConName {get;set;}
      public String fstName {get;set;}
      public string Email{get;set;}
      public string conacc{get;set;}
      public string oppacc{get;set;}
      public string Phone {get;set;}
      public String OppName{get;set;}
      public Date d {get;set;}
     
    private final Account acc;
     public String OpportunityName {get;set;}
public String OpportunityStage {get;set;}
public Date ClosedDate {get;set;}
                
     public OppClass3(ApexPages.StandardController stdController) {
        this.acc= (Account)stdController.getRecord();
     }
 
      public account getAccount()
      {
      if(account == null)
      {
      Account = new Account();
      system.debug('Account------>'+account);
      
      }
      return Account;
      }
          
          public contact getcontact()
          {
          
          if(contact==null)
          contact = new contact();
          System.debug('contact--->'+contact);
          return contact;
          
          
          }
          
          public Opportunity getOpportunity()
          {
          if(opportunity == null)
          opportunity = new opportunity();
          
          System.debug('opportunity--->'+opportunity);
          return opportunity;
          
          }
 
    public PageReference NewOpp(){
         opportunity = new opportunity();
         contact = new contact();
        
               return new PageReference('https://sreeee.ap1.visual.force.com/apex/page14');
 
        }
        
        public PageReference mySave()
        {
        
        
        contact = new contact(lastname = conname,firstname = fstName,Email = email,phone = phone,accountid=acc.id );
        //contact.accountid = account.id;
        insert contact;
        
        
        
        opportunity = new opportunity(name = OppName,StageName='New Opportunity',CloseDate=d,accountid=acc.id);
       // opportunity.accountid = account.id;
        insert opportunity;
        
        PageReference pr = new Apexpages.StandardController(contact).view();
        
        
        pr.setRedirect(true);
         PageReference pr1 = new Apexpages.StandardController(opportunity).view();
        
        
        pr1.setRedirect(true);
        
      return new PageReference('https://sreeee.ap1.visual.force.com/apex/page14');
      // return null;
        
        }
 
}
<apex:page standardcontroller="Account" extensions="OppClass3">
    <apex:form >
 <apex:pageBlock >
 <apex:pageBlockButtons >
  <apex:commandButton value="Save" action="{!mysave}"/>
 <apex:commandButton value="Cancel" action="{!cancel}"/>
 <apex:commandButton value="New opp" action="{!NewOpp}"/>
</apex:pageBlockButtons>

<apex:pageBlockSection title="Contact Information">
<apex:pageBlockTable value="{!contact}" var="o">
<apex:column headerValue="LastName"><apex:inputText value="{!ConName}"/></apex:column>

<apex:column headerValue="FirstName"><apex:inputText value="{!fstName}"/></apex:column>
<apex:column headerValue="phone"><apex:inputText value="{!phone}"/></apex:column>
<apex:column headerValue="Email"><apex:inputText value="{!Email}"/></apex:column>
<apex:column headerValue="AccountName"><apex:inputField value="{!o.accountid}"/></apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>


   <apex:pageBlockSection title="Opportunity Information">
   <apex:pageBlockTable value="{!Opportunity}" var="o">
   
   <apex:column headerValue="OpportunityName">
   <apex:inputText value="{!OppName}"/> </apex:column>
   <apex:column headerValue="AccountName"><apex:inputField value="{!o.accountid}"/></apex:column>
   <apex:column headerValue="Stage" >
   <apex:inputField value="{!o.stagename}"/> </apex:column>
    <apex:column headerValue="CloseDate" ><apex:inputText value="{!d}"/> </apex:column>
   
  </apex:pageBlockTable>
   
          <!-- <apex:pageBlockSectionItem >
                   <apex:outputLabel value="Opportunity Name"/>
                   <apex:inputText value="{!opportunityName}" />
           </apex:pageBlockSectionItem>
             
           <apex:pageBlockSectionItem >
                   <apex:outputLabel value="Opportunity Amount"/>
                  <apex:inputText value="{!opportunitystage}" />
           </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                   <apex:outputLabel value="ClosedDate"/>
                  <apex:inputText value="{!ClosedDate}" />
           </apex:pageBlockSectionItem>
            
            <apex:pageBlockSectionItem >
                    <apex:outputLabel value="AccountName"/>
                    <apex:outputField Value="{!Account.name}"/>
            </apex:pageBlockSectionItem>-->
    </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Thanks in advance !!!!
i need quick help,
In my test class i am unable to cover the formula field.

I have a formula field Approved__C in opportunity object.That formula field holding the quote object field value ApprovalStatus__c.
i am inserting data in Quote object along with writeable field ApprovalStatus__c, but still i am not able to getting data into Opportunity formula field still it is showing null value.

 
Account having a checkbox field if that flag value is true then clicking on newopportunity button it should throw error?