• Kiru535
  • NEWBIE
  • 10 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 26
    Questions
  • 24
    Replies
Please help me How to write test class for below one....

Functionality: Export to records in Excel file 

public pageReference download()
     {
     
      List<Account> dacc1 = new List<Account>();   
      accountList=null;
      MethCal=true; 
      if(accountList == null) { 
      for(Account a: [SELECT Name, Owner.Name, NameLocal, Id, Motorola_Customer_Number__c,Underserved_Account__c, AccountNumber, 
                            Assigned_MR__c, Assigned_MR__r.Name,Assigned_MR__r.id, Updated_Assigned_MR__r.id,Updated_Assigned_MR__r.Name,
                            Primary_Served__c, Secondary_Served__c,
                            Updated_Primary_Served__c,Updated_Secondary_Served__c,Updated_Underserved_Account__c
                       FROM Account 
                       WHERE Owner.Manager.Id =:selectedAsm AND Owner_Business_Group__c='Government' 
                           AND RecordTypeId =:custRecordTypeId 
                           AND (Primary_Served__c IN ('MR Led', 'MSI Led', 'Inside Sales/Tele-Sales Led') 
                           OR Secondary_Served__c IN ('MR Led', 'MSI Led', 'Inside Sales/Tele-Sales Led'))
                           Order By Name]) 
                       {                       
                           dacc1.add(a); 
                           System.debug('**********DownloadExcel**************'+dacc1.size());
                       }    
     }
     
     downloadacc = dacc1.clone();
     PageReference pageRef = new PageReference('/apex/RenderedAsExcel');
     pageRef.setRedirect(false);
     return pageRef;  
     }
My requirement was to display picklist values based on user object. In User object Field called ASM__C (Formula Field) and I am retrieving the records based on this field. But I am getting Null value. The values are exist in database for this field.

Please guide me how to get the value...

This is my code-:   
public class ManageAccountAssignmentsController
{

public String selectedAsm{get;set;}
//Public String AsmId{get;set;}
Public List<Account> AsmAssocAccounts{get;set;}
Public boolean MethCal{get;Set;}
Public boolean successMsg{get;Set;}
public Document document {get; set;} 

    public List<SelectOption> getAsmOptions()
    {
      Set<Id> accset = new Set<Id>();
      Id customerRecordTypeId = Schema.SObjectType.Account.RecordTypeInfosByName.get('Customer').RecordTypeId;
      List<Account> acct = New List<Account>();
      Set<id> ArConId = new Set<id>();
      acct = [Select Name, Ownerid, id from Account where RecordTypeId =:customerRecordTypeId];
      for(Account acclst:acct)
      {
        accset.add(acclst.Ownerid);
      }
       List<SelectOption> options = new List<SelectOption>();
       for (User e1:[SELECT Name,id,Area_Controller__c,ASM__c FROM User WHERE id IN:accset])
        {
             ArConId.add(e1.ASM__c); //Getting Null in this Set eventhough value is present in database
             system.debug('ArConId'+ArConId);       
         }

       
       options.add(new selectOption('--None--','--None--'));
        for (User e:[SELECT Name,Id FROM User WHERE id IN:ArConId])
         {
             options.add(new selectOption(e.id,e.Name));
                              
         }
         return options;
    }

     

  
Hi Friends,

My requirement was I need to get completed and failed jobs during the day needs to send notification to support via email daily night @11:00PM. I have created batch apex class but I am not able to get the records via email. Please help me out...
Error:
First error: List has more than 1 row for assignment to SObject

This is my code...

global class MPE_BatchJobStatus implements Database.Batchable<sObject>,Schedulable
{
//String query;
global Database.QueryLocator start(Database.BatchableContext BC) {
    String query = 'SELECT ApexClassId,CompletedDate,Id,JobItemsProcessed,JobType,MethodName,NumberOfErrors,Status,TotalJobItems,ExtendedStatus FROM AsyncApexJob where CompletedDate =Today'; 
    
    return Database.getQueryLocator(query);
  }
   global void execute(SchedulableContext SC)
   {
     MPE_BatchJobStatus ds=new MPE_BatchJobStatus();
      database.executebatch(ds);
   }
  global void Execute(Database.BatchableContext bc,LIST<SObject> scope)
   {
     
     }
global void finish(Database.BatchableContext BC){
   //List<AsyncApexJob> a = new List<AsyncApexJob>();
   AsyncApexJob a = [SELECT ApexClassId,CompletedDate,Id,JobItemsProcessed,JobType,MethodName,NumberOfErrors,Status,TotalJobItems,ExtendedStatus FROM AsyncApexJob where CompletedDate =Today];
   Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
   attach.setFileName('BatchJobs.xls');
    // blob csvBlob = Blob.valueOf(a);
     String body;
     body = '<html><body><table><tr><td>ID</td><td>' + a.Id + '</td></tr><tr><td>ApexClassId</td><td>' + a.ApexClassId + '</td></tr><tr><td>CompletedDate</td><td>' + a.CompletedDate + '</td></tr><tr><td>JobsProcessed</td><td>' + a.JobItemsProcessed + '</td></tr><tr><td>JobType</td><td>' + a.JobType + '</td></tr><tr><td>NumberOfErrors</td><td>' + a.NumberOfErrors + '</td></tr><tr><td>Error</td><td>' + a.ExtendedStatus + '</td></tr><tr><td>TotalJobItems</td><td>' + a.TotalJobItems + '</td></tr><tr><td>Status</td><td>' + a.Status + '</td></tr></table></body></html>';
     attach.body = Blob.valueOf(body);
// Send an email to the Apex job's submitter notifying of job completion.
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   String[] toAddresses = new String[] {'vrm674@motorolasolutions.com'};// we are getting email from custom label
   mail.setToAddresses(toAddresses);
   mail.setSubject('ApexJobs');
   mail.setHtmlBody('PFA');
   mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
   mails.add(mail);
   if(!mails.isEmpty())
{
    Messaging.SendEmail(mails);
}
}

}

Regards,
kk.
Hello Experts,

I need urgent help on Heap size error issue.

I have done following fixes which is working perfectly in fullcopy Sandbox but in production still we are getting this issue.

-->Cleared all list variables
-->Declared Trasient keyword for unwanted variables
-->removed unwanted fields from SOQL select query.

Please advice what else needs to be done to overcome this issue in production.

Regards,
KK.
During any apex class errors I need to send do not reply email to all the users in the organization at a time. Is there any standard option available without apex coding.
Can you please anyone help me on this issue.
When ever new record inserted in particular object.... this particular record must be copied to all the accounts which are assigned to particular template. I have written trigger for this and it is working perfectly but code coverage is 55%. I need to cover the code more than 85%. Please help me here how to increase the code coverage.

Actually the code which is in the for loop not covering.... I have highlighed the code in the BOLD

Apex trigger:

trigger PACodeUpdate on Program_Criteria_Details__c (after insert)
{
    Set<Id> parentIdSet = new Set<ID>();
   
    List<Program_Criteria_Details__c> pcdList = new List<Program_Criteria_Details__c>();
    List<Program_Requirement_detail__c> insertlist = new List<Program_Requirement_detail__c>();
    Map<String,Program_Criteria_Details__c> pcdMap = new Map<String,Program_Criteria_Details__c>();       
    for(Program_Criteria_Details__c pnew : Trigger.new)
    {
        if(Trigger.isInsert)
        {
            parentIdSet.add(pnew.ProgramTemplates__c);
        }
        pcdMap.put(pnew.ProgramTemplates__c,pnew);  
    }
   /* if(parentIdSet.size() > 0)
    {
      pcdList = [select Id,criteria__c,Metric_Status__c,ProgramTemplates__c,Target__c,Product__c from Program_Criteria_Details__c where ProgramTemplates__c in :parentIdSet];
    }*/
   
      List<Program_Level_Requirements__c> plr = [select id,Name,Account__c,Community__c,ProgramTemplates__c,Technology__c from Program_Level_Requirements__c where ProgramTemplates__c in :parentIdSet];
      for(Program_Level_Requirements__c plrlist:plr)
      {
        Program_Requirement_detail__c prd = new Program_Requirement_detail__c();
        prd.Account__c = plrlist.Account__c;
        prd.Program_Level_Requirement__c = plrlist.id;
        //prd.Community__c = plrlist.Community__c;
        //prd.Technology__c = plrlist.Technology__c;
        prd.Program_Criteria_Details__c = pcdMap.get(plrlist.ProgramTemplates__c).id;
        prd.Criteria__c = pcdMap.get(plrlist.ProgramTemplates__c).Criteria__c;
        prd.Product__c = pcdMap.get(plrlist.ProgramTemplates__c).Product__c;
        prd.Target__c = pcdMap.get(plrlist.ProgramTemplates__c).Target__c;
        prd.Measure__c = pcdMap.get(plrlist.ProgramTemplates__c).Measure__c;
        insertlist.add(prd);
      }
      insert insertlist;
}



Test Class:

@isTest(seealldata=true)
private class PACodeUpdateTest
{
   static testMethod void PATest()  
   {
     Test.startTest();
     RecordType RT = [Select Id from RecordType where Name='Partner' and SobjectType='Account' limit 1];
     Account ac1 = new Account(name='Test Account1',RecordTypeId=RT.id,Metal_Level__c='Gold',Partner_HQ_Country__c='United States',AccountNumber='11223344');
     Account ac2 = new Account(name='Test Account2',RecordTypeId=RT.id,Metal_Level__c='Gold',Partner_HQ_Country__c='United States',AccountNumber='11223345');
     list<Account> acc=new list<Account>();
     acc.add(ac1);
     acc.add(ac2);
     insert acc;
     Partner_Type__c pt1 = new Partner_Type__c(Account__c = ac1.id, Program__c = 'Mobility',Status__c='Active',Support_Services__c=True,Advanced_Services__c=True,US_Federal_Specialization__c='Authorized',Partner_Track__c='DMR');
     Partner_Type__c pt2 = new Partner_Type__c(Account__c = ac2.id, Program__c = 'Mobility',Status__c='Active',Support_Services__c=True,Advanced_Services__c=True,US_Federal_Specialization__c='Authorized',Partner_Track__c='DMR');
     list<Partner_Type__c> pt=new list<Partner_Type__c>();
     pt.add(pt1);
     pt.add(pt2);
     insert pt;
   
     Technology_Specialization__c ts1 = new Technology_Specialization__c(Partner_Program__c=pt1.id,Account__c=ac1.id,Technology_specialization__c='Mobile Computing',Technology_specialization_level__c='Authorized',Technology_Specialization_Status__c='Active',Community_Type__c='Value Added Reseller');
      Technology_Specialization__c ts2 = new Technology_Specialization__c(Partner_Program__c=pt2.id,Account__c=ac2.id,Technology_specialization__c='Mobile Computing',Technology_specialization_level__c='Authorized',Technology_Specialization_Status__c='Active',Community_Type__c='Value Added Reseller');
     list<Technology_Specialization__c> ts=new list<Technology_Specialization__c>();
     ts.add(ts1);
     ts.add(ts2);
     insert ts;
    
     ProgramTemplates__c ptp = new ProgramTemplates__c(Program__c ='Mobility',Technology__c ='Mobile Computing',Region__c ='NAMR',Status__c ='Active',Community__c='Value Added Reseller');
     List<ProgramTemplates__c> ptlst = new List<ProgramTemplates__c>();
     ptlst.add(ptp);
     insert ptlst;
     Program_Criteria_Details__c pcd = new Program_Criteria_Details__c(Criteria__c ='TestPA1',Target__c =2,Measure__c='Annually',ProgramTemplates__c =ptp.id,Product__c ='WT4090');
     List<Program_Criteria_Details__c> pcdlst = new List<Program_Criteria_Details__c>();
     pcdlst.add(pcd);
     insert pcdlst;
     Id recordtyid= Schema.SObjectType.Program_Level_Requirements__c.getRecordTypeInfosByName().get('PLR_Product Access').getRecordTypeId();
     Program_Level_Requirements__c pr1=new Program_Level_Requirements__c(Account__c=ac1.id,Technology__c=ts1.Technology_Specialization__c,Community__c=ts1.Community_Type__c, Recordtypeid=recordtyid,ProgramTemplates__c =ptp.id);
     Program_Level_Requirements__c pr2=new Program_Level_Requirements__c(Account__c=ac2.id,Technology__c=ts2.Technology_Specialization__c,Community__c=ts2.Community_Type__c, Recordtypeid=recordtyid,ProgramTemplates__c =ptp.id);
     List<Program_Level_Requirements__c> pr1lst = new List<Program_Level_Requirements__c>();
     pr1lst.add(pr1);
     pr1lst.add(pr2);
     insert pr1lst;
     /*Program_Requirement_detail__c prdetail=new Program_Requirement_detail__c(Account__c=ac1.id,Program_Level_Requirement__c=pr1.id,Program_Criteria_Details__c =pcd.id,Criteria__c = pcd.Criteria__c,Product__c =pcd.Product__c,Target__c =pcd.Target__c,Measure__c =pcd.Measure__c);
     Program_Requirement_detail__c prdetail1=new Program_Requirement_detail__c(Account__c=ac2.id,Program_Level_Requirement__c=pr2.id,Program_Criteria_Details__c =pcd.id,Criteria__c = pcd.Criteria__c,Product__c =pcd.Product__c,Target__c =pcd.Target__c,Measure__c =pcd.Measure__c);
     List<Program_Requirement_detail__c> prdetaillst = new List<Program_Requirement_detail__c>();
     prdetaillst.add(prdetail);
     prdetaillst.add(prdetail1);
     insert prdetaillst;*/
    
     List<Program_Level_Requirements__c> plrfinal= [select id,Name,Account__c,Community__c,ProgramTemplates__c,Technology__c from Program_Level_Requirements__c where ProgramTemplates__c =:ptp.id];
     List<Program_Requirement_detail__c> prdfinal = new List<Program_Requirement_detail__c>();
     for(Program_Level_Requirements__c plrrec:plrfinal)
     {
        Program_Requirement_detail__c prdinsert = new Program_Requirement_detail__c();
        prdinsert.Account__c = plrrec.Account__c;
        prdinsert.Program_Level_Requirement__c = plrrec.id;
        prdinsert.Program_Criteria_Details__c = pcd.id;
        prdinsert.Criteria__c = pcd.Criteria__c;
        prdinsert.Product__c = pcd.Product__c;
        prdinsert.Target__c = pcd.Target__c;
        prdinsert.Measure__c = pcd.Measure__c;
        prdfinal.add(prdinsert);
     }
     insert prdfinal;
     Test.stopTest();
   }
}
I am getting Heap size error while running batch class.

Error :
First error: Apex heap size too large: 12020286

I have cleared all the list components...still I am getting this error. Can you please anybody quick reply ASAP for resolution ASAP.
I need help to write a test clss for below class. Please help me

public class LeadFieldUpdate
{
  public void UpdateLead(CampaignMember[] cmember)
  {
    Set<Id> leadIds = new Set<Id>();
    Set<String> campaignperLead;
    List<Lead> leadforupdate = new List<Lead>();
    String Compname;
   
   
    for (CampaignMember  cm: cmember)
    {
       leadIds.add(cm.LeadId);
      
    }
    for(Lead con:[SELECT id, Cname__c,(SELECT id, CampaignId, CreatedDate,Campaign.Name, Campaign.StartDate, Status, LeadId, HasResponded FROM CampaignMembers Order by CreatedDate,HasResponded) FROM Lead where Id IN :leadIds])
    {
      Compname = NULL;
     
      campaignperLead = new Set<String>();
      for(CampaignMember uis: con.CampaignMembers)
      {
        IF(uis.CampaignId!= NULL && uis.HasResponded == true)
        {
          Compname = uis.CampaignId;
         
        }
      }
      boolean isUpdateRequired = false;
    
      if(con.Cname__c != string.valueof(Compname))
      {
       
        con.Cname__c = string.valueof(Compname);
        isUpdateRequired = true;
        system.debug('6----******Lead Updated Compaign Name is*********' + con.Cname__c);
       
      }
      if(isUpdateRequired)
        leadforupdate.add(con);
       
    }
     if(leadforupdate.size() > 0)
            update leadforupdate; 
  }
}
I have a requirement like this. Please reply to me ASAP.

In Lead standard object I have created one custom field called Compaign Name. I want to populate this field based on compaign history field called Status and Start date fields. Based on below criteria it would have populate...

If compaign history contains morethan one record then  based on most recent Date (Consider Start Date, Time Stamp field) record compaign Name should populate on Lead object custom field. I have already tried with  trigger and its working fine but businees said do not use trigger because each lead getting compaigns morethan 3000 per day so, it could be a performance issue when we use trigger. Please suggest me any other solution by using Reports or other solution. I am struggling with this requirement ...please help me.

Regards,
kk

Note : 
Hi Friends, I have a requirement like this...

In Lead standard object I have created one custom field called Compaign Name. I want to populate this field based on compaign history field called Status and Start date fields. Based on below criteria it would have populate...

If compaign history contains morethan one record then  based on most recent Date (Consider Start Date field) record compaign Name should populate on Lead object custom field. I am struggling with this requirement ...please help me.

PFA -- Screeshot

 Screenshot
My Requirement was during upon selected an account on contact while creating new contact or update contact.... Account address to be populated on contact automatically. During insert the trigger is working properly but an update it is not working. Please suggest me what i need to change in below code.

trigger PopulateAccountAddress on Contact (before insert,before update)
{
  Map<id,Account> accaddress = new Map<id,Account>();
  List<Account> acclist = [Select id,BillingCity,BillingCountry,BillingPostalCode,BillingState,BillingStreet from Account];
  for(Account addaddress : acclist)
  {
    accaddress.put(addaddress.id,addaddress);
  }
  System.debug ('*****accaddress Map*****' + accaddress);
  for(Id conaddress:accaddress.keyset())
  {
      System.debug('Address ids' + conaddress);
        
         Contact c = new Contact();
        System.debug('!!!!!conaddress!!!!!!' + conaddress);
        c.MailingCity = accaddress.get(conaddress).BillingCity;
        System.debug('$$$$ MailingCity $$$$$' + c.MailingCity);
        c.MailingCountry = accaddress.get(conaddress).BillingCountry;
        c.MailingPostalCode= accaddress.get(conaddress).BillingPostalCode;
        c.MailingState = accaddress.get(conaddress).BillingState;
        c.MailingStreet= accaddress.get(conaddress).BillingStreet;
       
          
    }   
   }
I am new to Rest API. I have a requirement like this

2 instances -- S1, S2

Create one button in S1 instance - Opportunity detail page called Pust To S2. When user clicks on this button first validate the opportunity number field exist or not. If exist do not push this opportunity to S2 instance, Else by using rest API we have to create same opportunity in S2 instance and return created opportunity id to S1 Instance.

Please post me a code for this.

Please suggest how to maintain Universal picklist?

I have one picklist which is having 50 values and this picklist present in various objects. My requiremnt is when ever user get change the value (Insert,delete,update) particular value should be updated in other picklist fields present in various objects.

Please give me the code if you done in your projects


Hi,

 

I haev on requirement like if user selects picklist value to Closed all the fields makes readonly except 2 fields.

 

I used output field with rendered - But field is hiding in page if not matching the condition.

 

How do I achive this?

 

My Code :

 

<apex:sectionHeader title="IBX Lines Edit" subtitle="{!IBX_Lines__c.name}"/> 
    <apex:form >
        <apex:pageBlock mode="edit" id="pgBlockId"> 
            <apex:pageMessages escape="false" />
            <apex:pageBlockButtons location="both"> 
                <apex:commandButton value="Save" action="{!save}"/> 
                <apex:commandButton value="Save & New" action="{!save}" /> 
                <apex:commandButton value="Cancel" action="{!cancel}"/> 
            </apex:pageBlockButtons> 

            <apex:pageBlockSection title="Information" columns="2"> 
                <apex:inputField value="{!IBX_Lines__c.Name}" required="false"/> 
                <apex:inputField value="{!IBX_Lines__c.CurrencyIsoCode}" required="false"/> 
                <apex:inputField value="{!IBX_Lines__c.Opportunity__c}" required="true"/> 
                <apex:inputField value="{!IBX_Lines__c.Primary_Campaign_Source__c}" required="false"/>
                <apex:pageBlockSectionItem >
                  <apex:outputLabel value="IBX Name" for="stage"/>
                <apex:actionRegion >
                <apex:inputField value="{!IBX_Lines__c.IBX_Name__c}" required="true" id="stage">
                    <apex:actionSupport event="onchange" reRender="dependentPick" action="{!getCompetitorsFromIBX}"/>
                </apex:inputField>
                </apex:actionRegion>
                </apex:pageBlockSectionItem> 
                <apex:inputField value="{!IBX_Lines__c.Lead_Source__c}" required="false"/> 
                <apex:inputField value="{!IBX_Lines__c.Line_Type__c}" required="true"/> 
                <apex:inputField value="{!IBX_Lines__c.Cross_Region_Lead_Source__c}" required="false"/> 
                <apex:inputField value="{!IBX_Lines__c.Adjustment_Type__c}" required="false"/> 
            </apex:pageBlockSection>
             
            <apex:pageBlockSection title="Status" columns="1"> 
                <apex:inputField value="{!IBX_Lines__c.Forecast_Status__c}" required="false"/> 
                <apex:inputField value="{!IBX_Lines__c.Lost_Reason__c}" required="false"/> 
                <apex:inputField value="{!IBX_Lines__c.Closed_Won_Lost_Notes__c}" required="false"/> 
            </apex:pageBlockSection>
             
            <apex:pageBlockSection title="MRR/NRR" columns="2"> 
                <!--<apex:inputField value="{!IBX_Lines__c.Forecast_MRR__c}" required="true"/>-->
                <apex:outputField value="{!IBX_Lines__c.Forecast_MRR__c}" rendered="{!(IBX_Lines__c.Forecast_Status__c='Slipped')}" />
                <!--<apex:outputField value="{!IBX_Lines__c.Forecast_MRR__c}" rendered="{!(IBX_Lines__c.Forecast_Status__c=='Active')}" />-->
                <apex:inputField value="{!IBX_Lines__c.Forecast_NRR__c}" required="true"/>
                <!--
                <apex:inputField value="{!IBX_Lines__c.Booked_Gross_MRR__c}" required="false"/> 
                <apex:inputField value="{!IBX_Lines__c.Booked_Gross_NRR__c}" required="false"/> 
                <apex:inputField value="{!IBX_Lines__c.Booked_Net_MRR__c}" required="false"/> 
                <apex:inputField value="{!IBX_Lines__c.Booked_Net_NRR__c}" required="false"/> -->
            </apex:pageBlockSection>
             
            <apex:pageBlockSection title="Competitors" columns="2" >
                
                <!-- Temporarily commented out by SD -->
                
                <c:MultiselectPicklist leftLabel="Available Competitors" id="dependentPick" 
                                       leftOptionsName="{!allCompetitors}"
                                       rightLabel="Selected Competitors"
                                       rightOptionsName="{!selectedCompetitors}"
                                       size="14"
                                       width="150px"/>
                <apex:inputHidden value="{!IBX_Lines__c.Competitors__c}" required="false"/>
            </apex:pageBlockSection>
             
            <apex:pageBlockSection title="Comments" columns="1"> 
                <apex:inputField value="{!IBX_Lines__c.Comments__c}" required="false"/> 
            </apex:pageBlockSection> 
           </apex:pageBlock> 
    </apex:form> 
</apex:page>
                                        

Please Reply to this requirement urgently with code.

 

One Account present in salesforce (Flipcart application) and  that acclunt email id =abc@gmail.com.

 

If I send email from particular email id (abc@gmail.com) to sales@flipcart.com, automaticllay one record with Email subject should be stored in Notes & Attachment of particular account.

 

Please help me

How to write a test class for below class. The test class should work for  the bulk scenario also. Please help me.

 

public with sharing class CloneOpportunityUtil {

public static void cloneOpportunities(List<Opportunity> oppList) {

List<IBX_Lines__c> newIBXLines = new List<IBX_Lines__c>();
Set<Id> cloneOppIds = new Set<Id>();
Map<Id,Id> cloneOppToNewOppIdMap = new Map<Id,Id>();
Map<Id,List<IBX_Lines__c>> oppIdIBXListMap = new Map<Id,List<IBX_Lines__c>>();
List<IBX_Lines__c> listIBX = null;
for(Opportunity tempOpp : oppList) {
if(tempOpp.Clone_Opportunity_ID__c != null) {
cloneOppIds.add(tempOpp.Clone_Opportunity_ID__c);
cloneOppToNewOppIdMap.put(tempOpp.Clone_Opportunity_ID__c,tempOpp.Id);
}
}

if(cloneOppIds.size() > 0) {
List<IBX_Lines__c> listIBXLines = [Select IBX_Name__c,Adjustment_Type__c,Opportunity__c,Competitors__c,Forecast_MRR__c,Forecast_NRR__c,Forecast_Status__c,Lead_Source__c,Line_Type__c,Primary_Campaign_Source__c,Cross_Region_Lead_Source__c from IBX_Lines__c where Opportunity__c IN :cloneOppIds and Forecast_Status__c = 'Slipped'];
for(IBX_Lines__c tempIBX : listIBXLines) {
if(oppIdIBXListMap.keySet().contains(tempIBX.Opportunity__c)) {
oppIdIBXListMap.get(tempIBX.Opportunity__c).add(tempIBX);
} else {
listIBX = new List<IBX_Lines__c>();
listIBX.add(tempIBX);
oppIdIBXListMap.put(tempIBX.Opportunity__c,listIBX);
}
}

}
IBX_Lines__c insertIBX = null;
for(Id tempId : cloneOppToNewOppIdMap.keySet()) {
if(oppIdIBXListMap.get(tempId).size() > 0) {
for(IBX_Lines__c tempIBX : oppIdIBXListMap.get(tempId)) {
insertIBX = new IBX_Lines__c();
insertIBX.Opportunity__c = cloneOppToNewOppIdMap.get(tempId);
insertIBX.IBX_Name__c = tempIBX.IBX_Name__c;
insertIBX.Adjustment_Type__c =tempIBX.Adjustment_Type__c;
insertIBX.Competitors__c = tempIBX.Competitors__c;
insertIBX.Forecast_MRR__c = tempIBX.Forecast_MRR__c;
insertIBX.Forecast_NRR__c = tempIBX.Forecast_NRR__c;
insertIBX.Forecast_Status__c = 'New/Active';
insertIBX.Lead_Source__c = tempIBX.Lead_Source__c;
insertIBX.Line_Type__c = tempIBX.Line_Type__c;
insertIBX.Cross_Region_Lead_Source__c = tempIBX.Cross_Region_Lead_Source__c;
insertIBX.Primary_Campaign_Source__c = tempIBX.Primary_Campaign_Source__c;
newIBXLines.add(insertIBX);
}
}
}
if(newIBXLines.size() > 0)
insert newIBXLines;
}

}

Technically the trigger isn't bulkified (many times for cloning I don't do that anyways b/c it's triggered by button click). But, since this is a trigger, technically you should add all the opportunities that need to be cloned to a list and pass the entire list to the helper method.

 

I am getting error in this trigger:

Error: Compile Error: Method does not exist or incorrect signature: [Cloneopty].CloneoptywithIbxline(MAP<Id,Id>) at line 44 column 9

 

Please post the code how to achive this

 

My Class :

public class Cloneopty
{

public final String ForecastStatusIsNewActive = 'New/Active';
Map<Id, Id> OppsToCloneList = new Map<Id, Id>();
//Method to check the opportunity has Slipped IBXline
public void CloneoptywithIbxline(Id oldOppoID ,Id opportunityId)
{
List<IBX_Lines__c> ibx =[Select Name,Opportunity__c,IBX_Name__c,Forecast_Status__c,Line_Type__c,Booked_Gross_MRR__c,Booked_Gross_NRR__c,Booked_Net_MRR__c,Booked_Net_NRR__c,Forecast_NRR__c,Forecast_MRR__c from IBX_Lines__c where opportunity__c =:oldOppoID AND Forecast_Status__c='Slipped'];
List<IBX_Lines__c> ibsList = new List<IBX_Lines__c>();
system.debug ('***The ibx is***'+ ibx);
for(IBX_Lines__c ib : ibx)
{
IBX_Lines__c newline = new IBX_Lines__c ();
newline.Opportunity__c= opportunityId;
newline.IBX_Name__c = ib.IBX_Name__c;
newline.Line_Type__c = ib.Line_Type__c;
newline.Forecast_Status__c = ForecastStatusIsNewActive;
newline.Forecast_NRR__c =ib.Forecast_NRR__c;
newline.Forecast_MRR__c =ib.Forecast_MRR__c;
ibsList.add(newline);

}
insert ibsList;
system.debug('***list is****'+ ibsList);
}
}

 

Trigger :

trigger Eqx_CloneOpportunity on Opportunity (after insert,Before Update)
{
// Update the clone opportunity Id - This is used to determine whether to use whether Only Slipped IBX should be cloned
if(Trigger.isUpdate && Trigger.isBefore)
{
for (Opportunity opp : Trigger.New)
{
// To avoid unndessary updates, can we check and see if the clone opportunity Id has changed

if(opp.Clone_Opportunity_ID__c == null || opp.Clone_Opportunity_ID__c != opp.ID)
{
opp.Clone_Opportunity_ID__c = opp.ID;
}
}
}

if(Trigger.isInsert && Trigger.isAfter)
{
Map<Id, Id> OppsToCloneList = new Map<Id, Id>();

for (Opportunity opp : Trigger.New)
{

system.debug('OpportunityID--->'+opp.Clone_Opportunity_ID__c);
if (opp.Clone_Opportunity_ID__c != null)

//cp.CloneoptywithIbxline(opp.Clone_Opportunity_ID__c,opp.id<http://opp.id>);
OppsToCloneList.put(opp.Clone_Opportunity_ID__c,opp.id);



}
Cloneopty cp = new Cloneopty();
cp.CloneoptywithIbxline(OppsToCloneList);

}
}

 
         

Please help me writing test class for below class.

 

public class Cloneopty
{

public final String ForecastStatusIsNewActive = 'New/Active';

public void CloneoptywithIbxline(Id oldOppoID ,Id opportunityId) 
{
List<IBX_Lines__c> ibx =[Select Name,Opportunity__c,IBX_Name__c,Forecast_Status__c,Line_Type__c,Booked_Gross_MRR__c,Booked_Gross_NRR__c,Booked_Net_MRR__c,Booked_Net_NRR__c,Forecast_NRR__c,Forecast_MRR__c from IBX_Lines__c where opportunity__c =:oldOppoID AND Forecast_Status__c='Slipped'];
List<IBX_Lines__c> ibsList = new List<IBX_Lines__c>();
system.debug ('***The ibx is***'+ ibx);
for(IBX_Lines__c ib : ibx)
{
IBX_Lines__c newline = new IBX_Lines__c ();
newline.Opportunity__c= opportunityId;
newline.IBX_Name__c = ib.IBX_Name__c;

newline.Line_Type__c = ib.Line_Type__c;
newline.Forecast_Status__c = ForecastStatusIsNewActive;
newline.Forecast_NRR__c =ib.Forecast_NRR__c;
newline.Forecast_MRR__c =ib.Forecast_MRR__c;
ibsList.add(newline);

}
insert ibsList;
system.debug('***list is****'+ ibsList);
}
}

I have opportunity with related list (Custom object SO)

 

My requirement was when user clone the opportunity -- I want to clone Relatedlist records which has status called 'Active'

 

My custom object has autonumber field.

 

Please help me to achieve this requirement.

 

Please paste the code

My Requirement is  Update multiselect picklist based on the Text field on object.

 

If Text field value = India

Multiselect picklist right side values displayed as all the states in India.

 

Please help me how to achieve thi requirement.

Hi Friends, I have a requirement like this...

In Lead standard object I have created one custom field called Compaign Name. I want to populate this field based on compaign history field called Status and Start date fields. Based on below criteria it would have populate...

If compaign history contains morethan one record then  based on most recent Date (Consider Start Date field) record compaign Name should populate on Lead object custom field. I am struggling with this requirement ...please help me.

PFA -- Screeshot

 Screenshot
My requirement was to display picklist values based on user object. In User object Field called ASM__C (Formula Field) and I am retrieving the records based on this field. But I am getting Null value. The values are exist in database for this field.

Please guide me how to get the value...

This is my code-:   
public class ManageAccountAssignmentsController
{

public String selectedAsm{get;set;}
//Public String AsmId{get;set;}
Public List<Account> AsmAssocAccounts{get;set;}
Public boolean MethCal{get;Set;}
Public boolean successMsg{get;Set;}
public Document document {get; set;} 

    public List<SelectOption> getAsmOptions()
    {
      Set<Id> accset = new Set<Id>();
      Id customerRecordTypeId = Schema.SObjectType.Account.RecordTypeInfosByName.get('Customer').RecordTypeId;
      List<Account> acct = New List<Account>();
      Set<id> ArConId = new Set<id>();
      acct = [Select Name, Ownerid, id from Account where RecordTypeId =:customerRecordTypeId];
      for(Account acclst:acct)
      {
        accset.add(acclst.Ownerid);
      }
       List<SelectOption> options = new List<SelectOption>();
       for (User e1:[SELECT Name,id,Area_Controller__c,ASM__c FROM User WHERE id IN:accset])
        {
             ArConId.add(e1.ASM__c); //Getting Null in this Set eventhough value is present in database
             system.debug('ArConId'+ArConId);       
         }

       
       options.add(new selectOption('--None--','--None--'));
        for (User e:[SELECT Name,Id FROM User WHERE id IN:ArConId])
         {
             options.add(new selectOption(e.id,e.Name));
                              
         }
         return options;
    }

     

  
Hi Friends,

My requirement was I need to get completed and failed jobs during the day needs to send notification to support via email daily night @11:00PM. I have created batch apex class but I am not able to get the records via email. Please help me out...
Error:
First error: List has more than 1 row for assignment to SObject

This is my code...

global class MPE_BatchJobStatus implements Database.Batchable<sObject>,Schedulable
{
//String query;
global Database.QueryLocator start(Database.BatchableContext BC) {
    String query = 'SELECT ApexClassId,CompletedDate,Id,JobItemsProcessed,JobType,MethodName,NumberOfErrors,Status,TotalJobItems,ExtendedStatus FROM AsyncApexJob where CompletedDate =Today'; 
    
    return Database.getQueryLocator(query);
  }
   global void execute(SchedulableContext SC)
   {
     MPE_BatchJobStatus ds=new MPE_BatchJobStatus();
      database.executebatch(ds);
   }
  global void Execute(Database.BatchableContext bc,LIST<SObject> scope)
   {
     
     }
global void finish(Database.BatchableContext BC){
   //List<AsyncApexJob> a = new List<AsyncApexJob>();
   AsyncApexJob a = [SELECT ApexClassId,CompletedDate,Id,JobItemsProcessed,JobType,MethodName,NumberOfErrors,Status,TotalJobItems,ExtendedStatus FROM AsyncApexJob where CompletedDate =Today];
   Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
   attach.setFileName('BatchJobs.xls');
    // blob csvBlob = Blob.valueOf(a);
     String body;
     body = '<html><body><table><tr><td>ID</td><td>' + a.Id + '</td></tr><tr><td>ApexClassId</td><td>' + a.ApexClassId + '</td></tr><tr><td>CompletedDate</td><td>' + a.CompletedDate + '</td></tr><tr><td>JobsProcessed</td><td>' + a.JobItemsProcessed + '</td></tr><tr><td>JobType</td><td>' + a.JobType + '</td></tr><tr><td>NumberOfErrors</td><td>' + a.NumberOfErrors + '</td></tr><tr><td>Error</td><td>' + a.ExtendedStatus + '</td></tr><tr><td>TotalJobItems</td><td>' + a.TotalJobItems + '</td></tr><tr><td>Status</td><td>' + a.Status + '</td></tr></table></body></html>';
     attach.body = Blob.valueOf(body);
// Send an email to the Apex job's submitter notifying of job completion.
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   String[] toAddresses = new String[] {'vrm674@motorolasolutions.com'};// we are getting email from custom label
   mail.setToAddresses(toAddresses);
   mail.setSubject('ApexJobs');
   mail.setHtmlBody('PFA');
   mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
   mails.add(mail);
   if(!mails.isEmpty())
{
    Messaging.SendEmail(mails);
}
}

}

Regards,
kk.
When ever new record inserted in particular object.... this particular record must be copied to all the accounts which are assigned to particular template. I have written trigger for this and it is working perfectly but code coverage is 55%. I need to cover the code more than 85%. Please help me here how to increase the code coverage.

Actually the code which is in the for loop not covering.... I have highlighed the code in the BOLD

Apex trigger:

trigger PACodeUpdate on Program_Criteria_Details__c (after insert)
{
    Set<Id> parentIdSet = new Set<ID>();
   
    List<Program_Criteria_Details__c> pcdList = new List<Program_Criteria_Details__c>();
    List<Program_Requirement_detail__c> insertlist = new List<Program_Requirement_detail__c>();
    Map<String,Program_Criteria_Details__c> pcdMap = new Map<String,Program_Criteria_Details__c>();       
    for(Program_Criteria_Details__c pnew : Trigger.new)
    {
        if(Trigger.isInsert)
        {
            parentIdSet.add(pnew.ProgramTemplates__c);
        }
        pcdMap.put(pnew.ProgramTemplates__c,pnew);  
    }
   /* if(parentIdSet.size() > 0)
    {
      pcdList = [select Id,criteria__c,Metric_Status__c,ProgramTemplates__c,Target__c,Product__c from Program_Criteria_Details__c where ProgramTemplates__c in :parentIdSet];
    }*/
   
      List<Program_Level_Requirements__c> plr = [select id,Name,Account__c,Community__c,ProgramTemplates__c,Technology__c from Program_Level_Requirements__c where ProgramTemplates__c in :parentIdSet];
      for(Program_Level_Requirements__c plrlist:plr)
      {
        Program_Requirement_detail__c prd = new Program_Requirement_detail__c();
        prd.Account__c = plrlist.Account__c;
        prd.Program_Level_Requirement__c = plrlist.id;
        //prd.Community__c = plrlist.Community__c;
        //prd.Technology__c = plrlist.Technology__c;
        prd.Program_Criteria_Details__c = pcdMap.get(plrlist.ProgramTemplates__c).id;
        prd.Criteria__c = pcdMap.get(plrlist.ProgramTemplates__c).Criteria__c;
        prd.Product__c = pcdMap.get(plrlist.ProgramTemplates__c).Product__c;
        prd.Target__c = pcdMap.get(plrlist.ProgramTemplates__c).Target__c;
        prd.Measure__c = pcdMap.get(plrlist.ProgramTemplates__c).Measure__c;
        insertlist.add(prd);
      }
      insert insertlist;
}



Test Class:

@isTest(seealldata=true)
private class PACodeUpdateTest
{
   static testMethod void PATest()  
   {
     Test.startTest();
     RecordType RT = [Select Id from RecordType where Name='Partner' and SobjectType='Account' limit 1];
     Account ac1 = new Account(name='Test Account1',RecordTypeId=RT.id,Metal_Level__c='Gold',Partner_HQ_Country__c='United States',AccountNumber='11223344');
     Account ac2 = new Account(name='Test Account2',RecordTypeId=RT.id,Metal_Level__c='Gold',Partner_HQ_Country__c='United States',AccountNumber='11223345');
     list<Account> acc=new list<Account>();
     acc.add(ac1);
     acc.add(ac2);
     insert acc;
     Partner_Type__c pt1 = new Partner_Type__c(Account__c = ac1.id, Program__c = 'Mobility',Status__c='Active',Support_Services__c=True,Advanced_Services__c=True,US_Federal_Specialization__c='Authorized',Partner_Track__c='DMR');
     Partner_Type__c pt2 = new Partner_Type__c(Account__c = ac2.id, Program__c = 'Mobility',Status__c='Active',Support_Services__c=True,Advanced_Services__c=True,US_Federal_Specialization__c='Authorized',Partner_Track__c='DMR');
     list<Partner_Type__c> pt=new list<Partner_Type__c>();
     pt.add(pt1);
     pt.add(pt2);
     insert pt;
   
     Technology_Specialization__c ts1 = new Technology_Specialization__c(Partner_Program__c=pt1.id,Account__c=ac1.id,Technology_specialization__c='Mobile Computing',Technology_specialization_level__c='Authorized',Technology_Specialization_Status__c='Active',Community_Type__c='Value Added Reseller');
      Technology_Specialization__c ts2 = new Technology_Specialization__c(Partner_Program__c=pt2.id,Account__c=ac2.id,Technology_specialization__c='Mobile Computing',Technology_specialization_level__c='Authorized',Technology_Specialization_Status__c='Active',Community_Type__c='Value Added Reseller');
     list<Technology_Specialization__c> ts=new list<Technology_Specialization__c>();
     ts.add(ts1);
     ts.add(ts2);
     insert ts;
    
     ProgramTemplates__c ptp = new ProgramTemplates__c(Program__c ='Mobility',Technology__c ='Mobile Computing',Region__c ='NAMR',Status__c ='Active',Community__c='Value Added Reseller');
     List<ProgramTemplates__c> ptlst = new List<ProgramTemplates__c>();
     ptlst.add(ptp);
     insert ptlst;
     Program_Criteria_Details__c pcd = new Program_Criteria_Details__c(Criteria__c ='TestPA1',Target__c =2,Measure__c='Annually',ProgramTemplates__c =ptp.id,Product__c ='WT4090');
     List<Program_Criteria_Details__c> pcdlst = new List<Program_Criteria_Details__c>();
     pcdlst.add(pcd);
     insert pcdlst;
     Id recordtyid= Schema.SObjectType.Program_Level_Requirements__c.getRecordTypeInfosByName().get('PLR_Product Access').getRecordTypeId();
     Program_Level_Requirements__c pr1=new Program_Level_Requirements__c(Account__c=ac1.id,Technology__c=ts1.Technology_Specialization__c,Community__c=ts1.Community_Type__c, Recordtypeid=recordtyid,ProgramTemplates__c =ptp.id);
     Program_Level_Requirements__c pr2=new Program_Level_Requirements__c(Account__c=ac2.id,Technology__c=ts2.Technology_Specialization__c,Community__c=ts2.Community_Type__c, Recordtypeid=recordtyid,ProgramTemplates__c =ptp.id);
     List<Program_Level_Requirements__c> pr1lst = new List<Program_Level_Requirements__c>();
     pr1lst.add(pr1);
     pr1lst.add(pr2);
     insert pr1lst;
     /*Program_Requirement_detail__c prdetail=new Program_Requirement_detail__c(Account__c=ac1.id,Program_Level_Requirement__c=pr1.id,Program_Criteria_Details__c =pcd.id,Criteria__c = pcd.Criteria__c,Product__c =pcd.Product__c,Target__c =pcd.Target__c,Measure__c =pcd.Measure__c);
     Program_Requirement_detail__c prdetail1=new Program_Requirement_detail__c(Account__c=ac2.id,Program_Level_Requirement__c=pr2.id,Program_Criteria_Details__c =pcd.id,Criteria__c = pcd.Criteria__c,Product__c =pcd.Product__c,Target__c =pcd.Target__c,Measure__c =pcd.Measure__c);
     List<Program_Requirement_detail__c> prdetaillst = new List<Program_Requirement_detail__c>();
     prdetaillst.add(prdetail);
     prdetaillst.add(prdetail1);
     insert prdetaillst;*/
    
     List<Program_Level_Requirements__c> plrfinal= [select id,Name,Account__c,Community__c,ProgramTemplates__c,Technology__c from Program_Level_Requirements__c where ProgramTemplates__c =:ptp.id];
     List<Program_Requirement_detail__c> prdfinal = new List<Program_Requirement_detail__c>();
     for(Program_Level_Requirements__c plrrec:plrfinal)
     {
        Program_Requirement_detail__c prdinsert = new Program_Requirement_detail__c();
        prdinsert.Account__c = plrrec.Account__c;
        prdinsert.Program_Level_Requirement__c = plrrec.id;
        prdinsert.Program_Criteria_Details__c = pcd.id;
        prdinsert.Criteria__c = pcd.Criteria__c;
        prdinsert.Product__c = pcd.Product__c;
        prdinsert.Target__c = pcd.Target__c;
        prdinsert.Measure__c = pcd.Measure__c;
        prdfinal.add(prdinsert);
     }
     insert prdfinal;
     Test.stopTest();
   }
}
I am getting Heap size error while running batch class.

Error :
First error: Apex heap size too large: 12020286

I have cleared all the list components...still I am getting this error. Can you please anybody quick reply ASAP for resolution ASAP.
Hi Friends, I have a requirement like this...

In Lead standard object I have created one custom field called Compaign Name. I want to populate this field based on compaign history field called Status and Start date fields. Based on below criteria it would have populate...

If compaign history contains morethan one record then  based on most recent Date (Consider Start Date field) record compaign Name should populate on Lead object custom field. I am struggling with this requirement ...please help me.

PFA -- Screeshot

 Screenshot
Hey everyone, I'm new to the forum and to APEX in general, but was hoping someone could help me with the problem I'm having.

I have an object "Job" that has a lookup to another custom field "Well".  The Well object has a lookup back to Account standard object and the Job has a lookup to the Account object.  Job__r.Account__c is a required field.  Basically, I want our users to do the following: Click New to create a new Job record, choose the Well lookup, and the trigger needs to fire as soon as the Job__r.Well__c field is populated to populate the Job__r.Account__c field with that Well's related Account.id.  Hopefully that all makes sense!  Here is what I have so far, and the trigger is working, but I have to select an Account and save the record for the trigger to fire even when the trigger is a before insert.  If I choose an account that is not linked to the correct Well that I chose, it updates it perfectly, but I need it to automatically populate the Account field as soon as the Well is chosen.

trigger UpdateJobAccount on Job__c (before insert){
if (trigger.isBefore &&(trigger.isInsert||trigger.isUpdate))
{
  set<Id> WellIds = new set<ID>();
  for(Job__c job: trigger.new)
  {
    WellIds.add(job.Well__c);
  }
  Map<Id, Id> WellToAccountMap = new Map<Id, Id>();
  for(Well__c well :[select Id, Account__c from Well__c where id in: WellIds])
  {
       WellToAccountMap.put(well.Id,well.Account__c);
  }
  for(Job__c job: trigger.new)
  {
       job.Account__c = WellToAccountMap.get(job.Well__c);
  }
 
}
}
My Requirement was during upon selected an account on contact while creating new contact or update contact.... Account address to be populated on contact automatically. During insert the trigger is working properly but an update it is not working. Please suggest me what i need to change in below code.

trigger PopulateAccountAddress on Contact (before insert,before update)
{
  Map<id,Account> accaddress = new Map<id,Account>();
  List<Account> acclist = [Select id,BillingCity,BillingCountry,BillingPostalCode,BillingState,BillingStreet from Account];
  for(Account addaddress : acclist)
  {
    accaddress.put(addaddress.id,addaddress);
  }
  System.debug ('*****accaddress Map*****' + accaddress);
  for(Id conaddress:accaddress.keyset())
  {
      System.debug('Address ids' + conaddress);
        
         Contact c = new Contact();
        System.debug('!!!!!conaddress!!!!!!' + conaddress);
        c.MailingCity = accaddress.get(conaddress).BillingCity;
        System.debug('$$$$ MailingCity $$$$$' + c.MailingCity);
        c.MailingCountry = accaddress.get(conaddress).BillingCountry;
        c.MailingPostalCode= accaddress.get(conaddress).BillingPostalCode;
        c.MailingState = accaddress.get(conaddress).BillingState;
        c.MailingStreet= accaddress.get(conaddress).BillingStreet;
       
          
    }   
   }
I am new to Rest API. I have a requirement like this

2 instances -- S1, S2

Create one button in S1 instance - Opportunity detail page called Pust To S2. When user clicks on this button first validate the opportunity number field exist or not. If exist do not push this opportunity to S2 instance, Else by using rest API we have to create same opportunity in S2 instance and return created opportunity id to S1 Instance.

Please post me a code for this.

Please suggest how to maintain Universal picklist?

I have one picklist which is having 50 values and this picklist present in various objects. My requiremnt is when ever user get change the value (Insert,delete,update) particular value should be updated in other picklist fields present in various objects.

Please give me the code if you done in your projects


Hi,

 

I haev on requirement like if user selects picklist value to Closed all the fields makes readonly except 2 fields.

 

I used output field with rendered - But field is hiding in page if not matching the condition.

 

How do I achive this?

 

My Code :

 

<apex:sectionHeader title="IBX Lines Edit" subtitle="{!IBX_Lines__c.name}"/> 
    <apex:form >
        <apex:pageBlock mode="edit" id="pgBlockId"> 
            <apex:pageMessages escape="false" />
            <apex:pageBlockButtons location="both"> 
                <apex:commandButton value="Save" action="{!save}"/> 
                <apex:commandButton value="Save & New" action="{!save}" /> 
                <apex:commandButton value="Cancel" action="{!cancel}"/> 
            </apex:pageBlockButtons> 

            <apex:pageBlockSection title="Information" columns="2"> 
                <apex:inputField value="{!IBX_Lines__c.Name}" required="false"/> 
                <apex:inputField value="{!IBX_Lines__c.CurrencyIsoCode}" required="false"/> 
                <apex:inputField value="{!IBX_Lines__c.Opportunity__c}" required="true"/> 
                <apex:inputField value="{!IBX_Lines__c.Primary_Campaign_Source__c}" required="false"/>
                <apex:pageBlockSectionItem >
                  <apex:outputLabel value="IBX Name" for="stage"/>
                <apex:actionRegion >
                <apex:inputField value="{!IBX_Lines__c.IBX_Name__c}" required="true" id="stage">
                    <apex:actionSupport event="onchange" reRender="dependentPick" action="{!getCompetitorsFromIBX}"/>
                </apex:inputField>
                </apex:actionRegion>
                </apex:pageBlockSectionItem> 
                <apex:inputField value="{!IBX_Lines__c.Lead_Source__c}" required="false"/> 
                <apex:inputField value="{!IBX_Lines__c.Line_Type__c}" required="true"/> 
                <apex:inputField value="{!IBX_Lines__c.Cross_Region_Lead_Source__c}" required="false"/> 
                <apex:inputField value="{!IBX_Lines__c.Adjustment_Type__c}" required="false"/> 
            </apex:pageBlockSection>
             
            <apex:pageBlockSection title="Status" columns="1"> 
                <apex:inputField value="{!IBX_Lines__c.Forecast_Status__c}" required="false"/> 
                <apex:inputField value="{!IBX_Lines__c.Lost_Reason__c}" required="false"/> 
                <apex:inputField value="{!IBX_Lines__c.Closed_Won_Lost_Notes__c}" required="false"/> 
            </apex:pageBlockSection>
             
            <apex:pageBlockSection title="MRR/NRR" columns="2"> 
                <!--<apex:inputField value="{!IBX_Lines__c.Forecast_MRR__c}" required="true"/>-->
                <apex:outputField value="{!IBX_Lines__c.Forecast_MRR__c}" rendered="{!(IBX_Lines__c.Forecast_Status__c='Slipped')}" />
                <!--<apex:outputField value="{!IBX_Lines__c.Forecast_MRR__c}" rendered="{!(IBX_Lines__c.Forecast_Status__c=='Active')}" />-->
                <apex:inputField value="{!IBX_Lines__c.Forecast_NRR__c}" required="true"/>
                <!--
                <apex:inputField value="{!IBX_Lines__c.Booked_Gross_MRR__c}" required="false"/> 
                <apex:inputField value="{!IBX_Lines__c.Booked_Gross_NRR__c}" required="false"/> 
                <apex:inputField value="{!IBX_Lines__c.Booked_Net_MRR__c}" required="false"/> 
                <apex:inputField value="{!IBX_Lines__c.Booked_Net_NRR__c}" required="false"/> -->
            </apex:pageBlockSection>
             
            <apex:pageBlockSection title="Competitors" columns="2" >
                
                <!-- Temporarily commented out by SD -->
                
                <c:MultiselectPicklist leftLabel="Available Competitors" id="dependentPick" 
                                       leftOptionsName="{!allCompetitors}"
                                       rightLabel="Selected Competitors"
                                       rightOptionsName="{!selectedCompetitors}"
                                       size="14"
                                       width="150px"/>
                <apex:inputHidden value="{!IBX_Lines__c.Competitors__c}" required="false"/>
            </apex:pageBlockSection>
             
            <apex:pageBlockSection title="Comments" columns="1"> 
                <apex:inputField value="{!IBX_Lines__c.Comments__c}" required="false"/> 
            </apex:pageBlockSection> 
           </apex:pageBlock> 
    </apex:form> 
</apex:page>
                                        

Please Reply to this requirement urgently with code.

 

One Account present in salesforce (Flipcart application) and  that acclunt email id =abc@gmail.com.

 

If I send email from particular email id (abc@gmail.com) to sales@flipcart.com, automaticllay one record with Email subject should be stored in Notes & Attachment of particular account.

 

Please help me

How to write a test class for below class. The test class should work for  the bulk scenario also. Please help me.

 

public with sharing class CloneOpportunityUtil {

public static void cloneOpportunities(List<Opportunity> oppList) {

List<IBX_Lines__c> newIBXLines = new List<IBX_Lines__c>();
Set<Id> cloneOppIds = new Set<Id>();
Map<Id,Id> cloneOppToNewOppIdMap = new Map<Id,Id>();
Map<Id,List<IBX_Lines__c>> oppIdIBXListMap = new Map<Id,List<IBX_Lines__c>>();
List<IBX_Lines__c> listIBX = null;
for(Opportunity tempOpp : oppList) {
if(tempOpp.Clone_Opportunity_ID__c != null) {
cloneOppIds.add(tempOpp.Clone_Opportunity_ID__c);
cloneOppToNewOppIdMap.put(tempOpp.Clone_Opportunity_ID__c,tempOpp.Id);
}
}

if(cloneOppIds.size() > 0) {
List<IBX_Lines__c> listIBXLines = [Select IBX_Name__c,Adjustment_Type__c,Opportunity__c,Competitors__c,Forecast_MRR__c,Forecast_NRR__c,Forecast_Status__c,Lead_Source__c,Line_Type__c,Primary_Campaign_Source__c,Cross_Region_Lead_Source__c from IBX_Lines__c where Opportunity__c IN :cloneOppIds and Forecast_Status__c = 'Slipped'];
for(IBX_Lines__c tempIBX : listIBXLines) {
if(oppIdIBXListMap.keySet().contains(tempIBX.Opportunity__c)) {
oppIdIBXListMap.get(tempIBX.Opportunity__c).add(tempIBX);
} else {
listIBX = new List<IBX_Lines__c>();
listIBX.add(tempIBX);
oppIdIBXListMap.put(tempIBX.Opportunity__c,listIBX);
}
}

}
IBX_Lines__c insertIBX = null;
for(Id tempId : cloneOppToNewOppIdMap.keySet()) {
if(oppIdIBXListMap.get(tempId).size() > 0) {
for(IBX_Lines__c tempIBX : oppIdIBXListMap.get(tempId)) {
insertIBX = new IBX_Lines__c();
insertIBX.Opportunity__c = cloneOppToNewOppIdMap.get(tempId);
insertIBX.IBX_Name__c = tempIBX.IBX_Name__c;
insertIBX.Adjustment_Type__c =tempIBX.Adjustment_Type__c;
insertIBX.Competitors__c = tempIBX.Competitors__c;
insertIBX.Forecast_MRR__c = tempIBX.Forecast_MRR__c;
insertIBX.Forecast_NRR__c = tempIBX.Forecast_NRR__c;
insertIBX.Forecast_Status__c = 'New/Active';
insertIBX.Lead_Source__c = tempIBX.Lead_Source__c;
insertIBX.Line_Type__c = tempIBX.Line_Type__c;
insertIBX.Cross_Region_Lead_Source__c = tempIBX.Cross_Region_Lead_Source__c;
insertIBX.Primary_Campaign_Source__c = tempIBX.Primary_Campaign_Source__c;
newIBXLines.add(insertIBX);
}
}
}
if(newIBXLines.size() > 0)
insert newIBXLines;
}

}

Please help me writing test class for below class.

 

public class Cloneopty
{

public final String ForecastStatusIsNewActive = 'New/Active';

public void CloneoptywithIbxline(Id oldOppoID ,Id opportunityId) 
{
List<IBX_Lines__c> ibx =[Select Name,Opportunity__c,IBX_Name__c,Forecast_Status__c,Line_Type__c,Booked_Gross_MRR__c,Booked_Gross_NRR__c,Booked_Net_MRR__c,Booked_Net_NRR__c,Forecast_NRR__c,Forecast_MRR__c from IBX_Lines__c where opportunity__c =:oldOppoID AND Forecast_Status__c='Slipped'];
List<IBX_Lines__c> ibsList = new List<IBX_Lines__c>();
system.debug ('***The ibx is***'+ ibx);
for(IBX_Lines__c ib : ibx)
{
IBX_Lines__c newline = new IBX_Lines__c ();
newline.Opportunity__c= opportunityId;
newline.IBX_Name__c = ib.IBX_Name__c;

newline.Line_Type__c = ib.Line_Type__c;
newline.Forecast_Status__c = ForecastStatusIsNewActive;
newline.Forecast_NRR__c =ib.Forecast_NRR__c;
newline.Forecast_MRR__c =ib.Forecast_MRR__c;
ibsList.add(newline);

}
insert ibsList;
system.debug('***list is****'+ ibsList);
}
}

I am invoking VF page by clicking on new button. But I am getting error like 'List has no recors associtaed to SOBJECT'

 

VF page contains multiselect picklist. these values getting from another object.

My requirement is I have one lookup to some other object. Whenever the  lookup field is selected in VF page the picklist must be updated with the selected values on another object.

 

Apex class :

public class CreateEditIBXLines
{
    public IBX_Lines__c ibxLine {get;set;}
    ApexPages.StandardController controller {get;set;}
        
    public SelectOption[] selectedCompetitors { get; set; }
    public SelectOption[] allCompetitors { get; set; }
             
    public CreateEditIBXLines(ApexPages.Standardcontroller controller)
    {
        this.controller = controller;
        ibxLine=(IBX_Lines__c)controller.getRecord();
        this.selectedCompetitors = new List<SelectOption>();
        this.allCompetitors = new List<SelectOption>();
        
        // check if there are any selected competitors already
        if(controller.getId() != null)
        {
            this.ibxLine = [SELECT Id,IBX_Name__c,Competitors__c FROM IBX_Lines__c WHERE Id =: controller.getId()];
        }
        
        // adding the selected competitors to the selected list
        if(this.ibxLine != null && this.ibxLine.Competitors__c != null)
        {
            for(String s : this.ibxLine.Competitors__c.split(';'))
            {
                selectedCompetitors.add(new SelectOption(s,s));
            }           
        }
        
        // finding out all the competitors available for selected IBX on IBX lines
        IBX__c ibxInfo = [SELECT Id,Name,Competitors__c FROM IBX__c where Id =:ibxLine.IBX_Name__c];
        
        if(ibxInfo != null && ibxInfo.Competitors__c != null)
        {
            for(String s : ibxInfo.Competitors__c.split(';'))
            {
                // logic to not add the already selected competitors to available list
                if(ibxLine != null && ibxLine.Competitors__c != null && ibxLine.Competitors__c.contains(s))
                {
                    // do not add to the list                   
                }
                else
                {
                    allCompetitors.add(new SelectOption(s,s));
                }
            }   
        }
    }

    public PageReference save()
    {
        String toPopulate = null;
        for(SelectOption selected: selectedCompetitors)
        {
            if(toPopulate == null)
              toPopulate = selected.getValue();
            else
            {
                toPopulate = toPopulate + ';' + selected.getValue();
            }
        }
        this.ibxLine.Competitors__c = toPopulate;
        
        update ibxLine;
        
        return this.controller.view();
    }
}

 

VF page:

<apex:page standardController="IBX_Lines__c" extensions="CreateEditIBXLines">
    <apex:sectionHeader title="IBX Lines Edit" subtitle="{!IBX_Lines__c.name}"/>
    <apex:form >
        <apex:pageBlock mode="edit" id="pgBlockId">
            <apex:pageBlockButtons location="both">
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Save & New" action="{!save}" />
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>

            <apex:pageBlockSection title="Information" columns="2">
                <apex:inputField value="{!IBX_Lines__c.Name}" required="false"/>
                <apex:inputField value="{!IBX_Lines__c.CurrencyIsoCode}" required="false"/>
                <apex:inputField value="{!IBX_Lines__c.Opportunity__c}" required="true"/>
                <apex:inputField value="{!IBX_Lines__c.Primary_Campaign_Source__c}" required="false"/>
                <apex:inputField value="{!IBX_Lines__c.IBX_Name__c}" required="true">
                 <apex:inputField/>
                <apex:inputField value="{!IBX_Lines__c.Lead_Source__c}" required="false"/>
                <apex:inputField value="{!IBX_Lines__c.Line_Type__c}" required="true"/>
                <apex:inputField value="{!IBX_Lines__c.Cross_Region_Lead_Source__c}" required="false"/>
                <apex:inputField value="{!IBX_Lines__c.Adjustment_Type__c}" required="false"/>
            </apex:pageBlockSection>
             
            <apex:pageBlockSection title="Status" columns="2">
                <apex:inputField value="{!IBX_Lines__c.Forecast_Status__c}" required="false"/>
                <apex:inputField value="{!IBX_Lines__c.Closed_Won_Lost_Notes__c}" required="false"/>
                <apex:inputField value="{!IBX_Lines__c.Lost_Reason__c}" required="false"/>
            </apex:pageBlockSection>
             
            <apex:pageBlockSection title="MRR/NRR" columns="2">
                <apex:inputField value="{!IBX_Lines__c.Forecast_MRR__c}" required="false"/>
                <apex:inputField value="{!IBX_Lines__c.Forecast_NRR__c}" required="false"/>
                <apex:inputField value="{!IBX_Lines__c.Booked_Gross_MRR__c}" required="false"/>
                <apex:inputField value="{!IBX_Lines__c.Booked_Gross_NRR__c}" required="false"/>
                <apex:inputField value="{!IBX_Lines__c.Booked_Net_MRR__c}" required="false"/>
                <apex:inputField value="{!IBX_Lines__c.Booked_Net_NRR__c}" required="false"/>
            </apex:pageBlockSection>
             
            <apex:pageBlockSection title="Competitors" columns="2">
                <!--  
                <apex:inputField value="{!IBX_Lines__c.Competitors__c}" required="false"/>
                -->
                <c:MultiselectPicklist leftLabel="Available Competitors"
                                       leftOptionsName="{!allCompetitors}"
                                       rightLabel="Selected Competitors"
                                       rightOptionsName="{!selectedCompetitors}"
                                       size="14"
                                       width="150px"/>
            </apex:pageBlockSection>
             
            <apex:pageBlockSection title="Comments" columns="2">
                <apex:inputField value="{!IBX_Lines__c.Comments__c}" required="false"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

Please help me ASAP

 

Please help me ASAP to solve this scenario.

 

 I have one VF page on that we have a look up field  and Multiselect picklist. When ever user selects the lookup field from the custom object, automatically the corresponding picklist values should be updated. Here all are custom objects.

 

Please help me ASAP.

 

Regards,

kk