• parth jolly
  • NEWBIE
  • 155 Points
  • Member since 2015
  • Salesforce Developer


  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 44
    Replies
trigger CreateClead on Lead(after insert){
    list<Id>deletLeadList=new list<Id>();
    if(Trigger.isInsert){
        List<Clead__c> cleadlst= new List <Clead__c>();
        for(Lead le: trigger.new){
            system.debug('==================='+le);
            if(le.LeadSource=='Job Application'){
                deletLeadList.add(le.id);
                Clead__c cl= new Clead__c ();
                cl.Name=le.LastName;
                cl.Email__c=le.Email;
                cl.Phone__c=le.Phone;
                cl.Job_Post__c=le.Subject__c;
                cl.Comments__c=le.Description;
                cl.CurrencyIsoCode='USD';
                cl.Reason__c='Available';
                cl.Status__c='Pre-Active';
                cl.Clead_Source__c='Web';
                //cl.Selling_Rate_Hr__c='Fiftydalor';
                //cl.Technology__c='SQL';
                cl.Role__c='Other';
                //cl.Current_Visa__c='H1';
                cleadlst.add(cl);
            }
        }
        insert cleadlst;
    }
    if(!deletLeadList.isEmpty())
        delete([SELECT Id FROM Lead WHERE ID IN:deletLeadList]);
}

 
Hi All,

Can we use advance multi-currency for custom objects?

Thank you.
myat
When I convert a lead in lightning experience I need to force a user to create an Opportunity. Is there any validation that will allow me to do this?
  • September 08, 2016
  • Like
  • 0
Here is the situation if Account's Laptop delivered lapp_c is not null then create a task related to it in the account through apex class.

Any idea ?
 
Hi ,

I have written the code to clone opportunity from apex trigger but i am concerned why the products are not getting clonned 
Also if productname  (i.e., ends with "-Y" ) then clonned date of opp = system.today
 
Trigger OpportunityTrigger on Opportunity(before insert, before update){
   Set<ID> Idset = new Set<ID>();
   List<Opportunity> oppLstToUpdate=new List<Opportunity>();

 
    if(Trigger.isInsert){
    List<Opportunity> clonedRecords = new List<Opportunity>();
    Opportunity newOpp= new Opportunity();
        for(Opportunity opp : Trigger.new){
            if((opp.Name == 'ServiceDesk Online - Monthly Usage' || opp.Name == 'ServiceDesk Online Purchase') && opp.StageName == 'Closed Won'){  
                newOpp = opp.clone(false, false, false, false);  
                newOpp.Name = 'ttttt';  
                newOpp.Closedate = opp.Date_After_1_Month__c;  
                newOpp.StageName = 'zzzzz';      
                clonedRecords.add(newOpp);
            }
        }    
    if(clonedRecords.size() > 0){
    insert clonedRecords;
                            
                 }
        }
    
    if(Trigger.isUpdate){
  List<Opportunity> clonedRecords = new List<Opportunity>();
        
            Opportunity newOpp= new Opportunity();
        for(Opportunity opp : Trigger.new){
            if((opp.Name == 'ServiceDesk Online - Monthly Usage' || opp.Name == 'ServiceDesk Online Purchase' )&& opp.StageName == 'Closed Won'&& opp.StageName  != trigger.oldMap.get(opp.Id).StageName){  
                newOpp = opp.clone(false, false, false, false);            
                newOpp.Name = 'ttttt';  
                newOpp.Closedate = opp.Date_After_1_Month__c; 
                newOpp.StageName = 'zzz';
                clonedRecords.add(newOpp);
            }
        }    
    if(clonedRecords.size() > 0){
    insert clonedRecords;
                            
                 }
        }
      
        }

Can anyone please advise or help me with suitable solution .
Thanks & Regards 

Paarth Jolly 
Hi Community ,

I have written the test class code for opportunity trigger and included the batch class test code in that But whenever i run it it showes error in batch class.
 
System.QueryException: unexpected token: AND

here is my test class code and batch class code .Please Check and let me know where i am doing wrong
 
global class ForecastDeleteBatch implements Database.Batchable<sObject>{      
    
    global ForecastDeleteBatch(){
    
    } 

    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator('SELECT Id,StageName,Name,Created_Date_Formula__c , Date_After_1_Month__c FROM Opportunity WHERE Name = \'ServiceDesk Online - Monthly Usage\' OR Name = \'ServiceDesk Online Purchase\' AND StageName = \'Closed Won\'');
    }

    global void execute(Database.BatchableContext BC, List<sObject> scope){   
    List<Opportunity> opplist = new List<Opportunity>();
    
    
        for(Opportunity opp: (List<Opportunity>)Scope){  
        
          if(opp.Name == 'ServiceDesk Online - Monthly Usage'||opp.Name == 'ServiceDesk Online Purchase' && opp.StageName == 'Closed Won'){
              if(opp.Date_After_1_Month__c == System.today()){  
               System.debug('number'+opplist);
                  opplist.add(opp);
              }
           }
        }
         
         System.debug('number of opp'+opplist);
         if(opplist.size() > 0){
             delete opplist;
             System.debug('number of opp updated'+opplist);
         }
          
    
    }
   
    global void finish(Database.BatchableContext BC){
              
    }   
}
 
@isTest
public class OpportunityTrigger_Test{
    static testMethod void insertNewOpportunity() {
        Account act = new Account();           
            act.Name = 'Test';
            act.Territory__c = 'Israel';
            //act.CurrencyIsoCode = 'USD -U.S. Dollar';
            act.Pipeline__c = 'Database';
     
        
        insert act;
        
      /*  Product2 prod = new Product2(Name = 'Laptop X200', 
                                     Family = 'Hardware',SKU__c = 'SD-Pro-Y');
        insert prod;
        
        Id pricebookId = Test.getStandardPricebookId();
        
        PricebookEntry standardPrice = new PricebookEntry(
            Pricebook2Id = pricebookId, Product2Id = prod.Id,
            UnitPrice = 10000, IsActive = true);
        insert standardPrice;
        
        
        Pricebook2 customPB = new Pricebook2(Name='Custom Pricebook', isActive=true);
        insert customPB;
        
        PricebookEntry customPrice = new PricebookEntry(
            Pricebook2Id = customPB.Id, Product2Id = prod.Id,
            UnitPrice = 12000, IsActive = true);
        insert customPrice;
        */
        Opportunity opp= new Opportunity();
            opp.StageName = 'Responded to Buyer';
            opp.CloseDate = System.today();
            opp.Account = act;
            opp.Name = 'ServiceDesk Online - Monthly Usage' ; 
            
               
        insert opp;
        
    
        opp.StageName = 'Closed Won';

        Test.startTest();

        update opp;

            ForecastDeleteBatch btch = new ForecastDeleteBatch();
            Database.executeBatch(btch);

        Test.stopTest();
      
    }
}

 
global with sharing class AccountUtilities {
   
   webservice static String getAssociates(String accid) {

      
      Account accs = 
         [select id,
         (select id,Associates__c,Name from Contacts 
         where Status__c = 'Primary Contact') from Account 
         where id = :accid LIMIT 1];
      
      list<contact> contacttoUpdate = new list<contact>();
      if(accs.Contacts != null && accs.Contacts.size() > 0 )
      {
          
          list<string> Names = new list<string>();
          
          for(Contact con : accs.Contacts)
          {
              Names.add(con.Name);
          }
          
          for(Contact con : accs.Contacts)
          {
              system.debug('Names:'+Names);
              string Associates = '';
              integer ncount = Names.size();
              integer count = 1;
              
              for(string n : Names)
              {
                   
                  system.debug('n:'+n);
                  if(con.Name != n)
                  {
                      count++;
                      if(Associates == '')
                          Associates += n;
                      else
                      {
                          system.debug('nc::'+ncount);
                          system.debug('c::'+count);
                          
                          if(count!= 1 && count == ncount)
                              Associates += ', and '+ n;
                          else
                              Associates += ', '+ n;
                      }
                  }
                  
                     
              }        
              
              
              con.Associates__c = Associates;
              con.Email_Campaign__c = 'Enrolled';
              contacttoUpdate.add(con);
              
          }
      }
      else
      {
          return 'No Primary Contact found for this Account';
      }
      
      
      
      try {
         Database.update(contacttoUpdate);
      }
      catch (DmlException e) {
         return e.getMessage();
      }

      
      return 'Contact associated succesfully';
      
   }
}

 
global with sharing class AccountUtilities {
   
   webservice static String getAssociates(String accid) {

      
      Account accs = 
         [select id,
         (select id,Associates__c,Name from Contacts 
         where Status__c = 'Primary Contact') from Account 
         where id = :accid LIMIT 1];
      
      list<contact> contacttoUpdate = new list<contact>();
      if(accs.Contacts != null && accs.Contacts.size() > 0 )
      {
          
          list<string> Names = new list<string>();
          
          for(Contact con : accs.Contacts)
          {
              Names.add(con.Name);
          }
          
          for(Contact con : accs.Contacts)
          {
              system.debug('Names:'+Names);
              string Associates = '';
              integer ncount = Names.size();
              integer count = 1;
              
              for(string n : Names)
              {
                   
                  system.debug('n:'+n);
                  if(con.Name != n)
                  {
                      count++;
                      if(Associates == '')
                          Associates += n;
                      else
                      {
                          system.debug('nc::'+ncount);
                          system.debug('c::'+count);
                          
                          if(count!= 1 && count == ncount)
                              Associates += ', and '+ n;
                          else
                              Associates += ', '+ n;
                      }
                  }
                  
                     
              }        
              
              
              con.Associates__c = Associates;
              con.Email_Campaign__c = 'Enrolled';
              contacttoUpdate.add(con);
              
          }
      }
      else
      {
          return 'No Primary Contact found for this Account';
      }
      
      
      
      try {
         Database.update(contacttoUpdate);
      }
      catch (DmlException e) {
         return e.getMessage();
      }

      
      return 'Contact associated succesfully';
      
   }
}

 
Hi, 
 I Created a class for Future callout and trying to create a Test Class for the same. I am invoking this class through an invokeable Apex class which gets called via a process builder. I tested this in Sandbox and it works pefect but i am not sure how to write the test class and migrate it. Below is the entire code, i am not sure , i am wrighting the right code ?

=====================================================================================
public class ApexCallout { // Called Through ProcessBuilder
@InvocableMethod
public static void invokecallout(list<Lead> Leads) {
WS_Webservice.Notification(Leads[0].id, Leads[0].name)
   }
}
------------------------------------------------------------------
@isTest
private class ApexCalloutTest{
    private static testMethod void doTest() {

        Test.startTest();
        Lead l = new Lead(id = '00XXXXXXXXXXXXXX',
                          name = 'User123');
        Test.stopTest();

    }
}


======================================================================================
Global class WS_Webservice {
  @future (callout=true)
   // Receiving the Lead details from Invokable class ApexCallout.
  WebService static void Notification(id lid, String name)
        { 
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();

        req.setEndpoint('https://google.com');
        
        //Setting Method Content and Body
        req.setMethod('POST');
        req.setHeader('Content-Type','application/x-www-form-urlencoded');
        req.setBody(
        'name='+EncodingUtil.urlEncode(name, 'UTF-8')
        
      );
        req.setTimeout(120000);
        try {
         res = http.send(req);
         System.debug(res.getbody());
        
         Dom.Document docx = new Dom.Document();
         docx.load(res.getbody());
         dom.XmlNode xroot = docx.getrootelement();
         String U_Id = xroot.getAttributeValue('U_Id', null);
         system.debug(U_Id );
         Lead le = new Lead(id=lid);
         le.ID__c = U_Id;
         update le;
        } 
        catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug(res.toString());
            res.getbody();
               }
            }
       }

 
Guys! Please help me!

I set up the approval process in Salesforce. The issue is even the submitter ( who submit the discount order to approved by their manager) can also approve their discount orders (themselves)  by clicking the approve/reject button in Approval History.

Please help me guys!
I've saveed my company logo in the Documents object of Salesforce. I want to insert this as the very first thing inside my VisualForce page on the Top Left and the have the line "Hello ...." appear (per the  coding below. I don't know how to insert an image. Do I needto reference the entire URL that the image is under within the Documents object? I know relative URLs would be better.  A_K_Logo_png is the name of my image /01523000000I3N9 is the relative URL  that it's found under.  How can I best accomlish this? Can someone  please repost my code for it to show up accordingly? I don't know how the syntax is to do this. I did not insert the entire code following hte beginning of a table that I posted but this is probably enough.

<apex:Page >
<apex:image url="{/01523000000I3N9}"></apex:image>
{apex:image:url"("A_K_Logo_png")" ;
}

   <head>

        <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"/>
        <script src="//code.jquery.com/jquery-1.10.2.js"></script>
        <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
        <link rel="stylesheet" href="/resources/demos/style.css"/>
        <script>
            $(function() {
                $("#pv2").datepicker({changeMonth: true, changeYear: true});
                 $("#pv12").datepicker({changeMonth: true, changeYear: true});          
                $(".datepick").datepicker({changeMonth: true, changeYear: true, constrainInput: false});      
              });             
        </script>       
    </head>
<br/>

   <FONT Size="3"><i> Hello  {! $User.FirstName}</i></FONT>
    <br/>
    <br/>
    <FONT Size="3"> <i>Please use the fields below to enter your desired dates for the specified reports.</i></FONT>
    <TABLE Border= "3" CELLSPACING="1" CELLPADDING="1" >
        <br/>
        <CAPTION><B> <FONT Size="4">Salesforce Reports</FONT> </B></CAPTION>
        <br/>
        <TR style="text-align:center;font-size:12pt;background-color:#ADD8E6;">
            
            <TD  >

 
Apex Superbadge challenge 4 error

Apex Superbadge Challenge 4 Error

Challenge Not yet complete... here's what's wrong: 
The 'MaintenanceRequest' trigger does not appear to be handling bulk operations correctly. For the positive use case of inserting and updating more than 200 records, it did not produce the expected outcome.

When I debug, I see this strange SOQL:

11:07:41.744 (4865812076)|SOQL_EXECUTE_BEGIN|[35]|Aggregations:0|SELECT COUNT() FROM Case WHERE subject LIKE '%AMC Spirit%'
11:07:41.744 (4868187164)|SOQL_EXECUTE_END|[35]|Rows:201
11:07:41.744 (4868199387)|HEAP_ALLOCATE|[35]|Bytes:4
11:07:41.744 (4868273203)|EXCEPTION_THROWN|[35]|System.AssertException: Assertion Failed: Expected: 402, Actual: 201
11:07:41.744 (4868404432)|HEAP_ALLOCATE|[35]|Bytes:48
11:07:41.744 (4868515907)|FATAL_ERROR|System.AssertException: Assertion Failed: Expected: 402, Actual: 201

Debug log

I see many people passing this challenge. Kindly help!
Hi,

Can we add more fields in edit opportunity split page.please advise .
User-added image
trigger CreateClead on Lead(after insert){
    list<Id>deletLeadList=new list<Id>();
    if(Trigger.isInsert){
        List<Clead__c> cleadlst= new List <Clead__c>();
        for(Lead le: trigger.new){
            system.debug('==================='+le);
            if(le.LeadSource=='Job Application'){
                deletLeadList.add(le.id);
                Clead__c cl= new Clead__c ();
                cl.Name=le.LastName;
                cl.Email__c=le.Email;
                cl.Phone__c=le.Phone;
                cl.Job_Post__c=le.Subject__c;
                cl.Comments__c=le.Description;
                cl.CurrencyIsoCode='USD';
                cl.Reason__c='Available';
                cl.Status__c='Pre-Active';
                cl.Clead_Source__c='Web';
                //cl.Selling_Rate_Hr__c='Fiftydalor';
                //cl.Technology__c='SQL';
                cl.Role__c='Other';
                //cl.Current_Visa__c='H1';
                cleadlst.add(cl);
            }
        }
        insert cleadlst;
    }
    if(!deletLeadList.isEmpty())
        delete([SELECT Id FROM Lead WHERE ID IN:deletLeadList]);
}

 
Trigger:
trigger QuantityMOQValidate on OpportunityLineItem (after insert, after update) {
if(checkRecursive.runOnce()){
    Set<Id> pbeIds = new Set<Id>();
    for (OpportunityLineItem oli : Trigger.new){
        pbeIds.add(oli.pricebookentryid);
        system.debug('adding to pbeIds ------>' + oli.pricebookentry.id);
    }
    Map<Id, double> entries = new Map<Id, Decimal>();
    for(PricebookEntry pbe : [select id, MOQ__c from PricebookEntry where id IN : pbeIds]){
        entries.put(pbe.id, pbe.MOQ__c);
        system.debug('putting in a map id------>' + pbe.id);
        system.debug('putting in a map value------>' + pbe.MOQ__c);
    }
    list<OpportunityLineItem> upOLI = new list<OpportunityLineItem>();
    for(OpportunityLineItem oli: Trigger.new){
        if((oli.Quantity < entries.get(oli.pricebookEntryId)) && entries.get(oli.pricebookEntryId) != Null ){
            system.debug('Quantity less than MOQ');            
            oli.addError('Quantity less than MOQ ['+ Integer.valueof(entries.get(oli.pricebookEntryId))+']');
        }        
        system.debug('>>>>>>>>Quantity----->' + oli.Quantity+'>>MOQ val----->'+ entries.get(oli.pricebookEntryId));        
    }   
}
}

Testclass:

@istest
public class TestQuantityMOQValidate {
 static testMethod void myUnitTest() {       

//Data Prep
//Create Account, Opportunity, Product, etc.
        Account acct1 = new Account(name='test Account One1');
        insert acct1;
//Create Opportunity on Account
        Opportunity Oppty1 = new Opportunity(name='test Oppty One1');
        Oppty1.StageName = 'Selected';
        Oppty1.CloseDate = Date.today() + 30;
        insert Oppty1;         

// Create Products 
         Product2 testprod1 = new Product2 (name='test product one1');
         testprod1.productcode = 'test pd code1one';
        
                insert testprod1;
         Product2 testprod2 = new Product2 (name='test product two2');
         testprod2.productcode = 'test pd code2two';
         
         
         insert testprod2;
// Get Pricebook
         Pricebook2 testpb = [select id from Pricebook2 where IsStandard = true];
         testpb.IsActive=true;
         update testpb;   
// Add to pricebook
        PriceBookEntry pbe1 = new PricebookEntry();
        pbe1.UnitPrice = 100;
        pbe1.Product2Id = testprod1.Id;
        pbe1.Pricebook2Id = testpb.id;
        pbe1.IsActive = true;
        pbe1.useStandardPrice = false;
        insert pbe1;
        PriceBookEntry pbe2 = new PricebookEntry();
        pbe2.UnitPrice = 200;
        pbe2.Product2Id = testprod2.Id; 
        pbe2.Pricebook2Id = testpb.id;
        pbe2.IsActive = true;
        pbe2.useStandardPrice = false;
        insert pbe2;

Test.startTest();

Oppty1.StageName='Selected';
update Oppty1;
System.assertNotEquals('Prospecting', Oppty1.StageName); 

Test.stopTest();
}
}
Hi All,

Can you please anyone give a test class for me to the below Apex Class.

Public class AccountDisplatRecClsExtn{
Public id Current_Acc_Id;
    public AccountDisplatRecClsExtn(ApexPages.StandardController controller) {
Current_Acc_Id = controller.getRecord().id;
    }
     

  public List<Question__c> getcontList(){
   List<Question__c> accList = [select id,Name,AssessmentId__c,AssessmentId__r.Name,External_ID__c,Friendly_Name__c,Question_Plain__c,Question_Style__c,Sort_Order__c,(Select Id,Name,Red_Flag__c,Scoring__c from answers__r) from Question__c where AssessmentId__c=:Current_Acc_Id ORDER by Sort_Order__c ASC];
   return accList;
  
  }
    }

Thanks,
Raj
 
Hi all,
I have 2 objects claim__c and intake__c.
Claim__c has 2 field sets: marine1 and marine2
marine1 has fields :
vesselName1
vesselName2 and so on
simmilarly
marine2 has fields:
vesselName1
vesselName2 and so on
 Intake__c has a fieldset named marine_intake
it has values vesselName1,vesselNumber and so on

What I have to do in my trigger is
if(vesselName1 of marine1 fieldset == 'ferry')
then I have to copy vesselName1 from marine2 fieldset(claim object) to vesselName1 in marine_intake fieldset(intake obj)
I am really confused with these field sets. can anyone plz help me to write the logic for this.
I 'm writing this class with its test class and I can save my code because there aren't errors but test class don't cover code of the class.
Can we help me to solve problems? 
Thank you.

This is Class : 

public class Ordine_Aziendale {


   public Quote preventivo{get; set;}
   public List<Account> account{get; set;}
   public Opportunity opportunita{get; set;}
   public List<QuoteLineItem> qtl{get; set;}
   public Integer cont{get;set;}
   
   public User utente{get; set;}  
    
    public Ordine_Aziendale(ApexPages.StandardController stdcontroller) {
    
      this.preventivo = (Quote)stdController.getRecord();
    
   // Product2 p2 = new Product2 (name='test');
      //  insert p2;
        
        qtl = [SELECT id , product2.id, product2.name, product2.ProductCode, Quantity, UnitPrice FROM QuoteLineItem  WHERE Quote.id =: preventivo.id];
        cont = qtl.size();
        
      // account = [SELECT id,Name,BillingAddress,ShippingAddress FROM Account WHERE id =: preventivo.id];
     // opportunita = [SELECT id,Name,BillingAddress,ShippingAddress FROM Account WHERE id =: preventivo.AccountId];
    }
}


This is my test class :

@isTest
public class Ordine_Aziendale_Test {
    static testMethod void Costruttore_Test()
    {
     
 /************************* START TEST   *************************************/      
 
     test.startTest();
      
     List<Account> l_acc = new List<Account>();
     Account acc = new Account(name='Test Account', billingStreet='Test', billingCity='Test', billingState='Test', billingCountry='Test');
     insert acc;
     l_acc.add(acc);
  
     List<Opportunity> l_opp = new List<Opportunity>();
     Opportunity opp = new Opportunity();
     opp.Accountid = acc.id;
     opp.Name = 'test';
     opp.StageName = 'Prospecting';
     opp.CloseDate = date.today();
     opp.Type = 'New Client';
     opp.NextStep = 'Test';
     opp.LeadSource = 'Business Development';
     insert opp;
     l_opp.add(opp);
      
     List<Quote> l_preventivi = new List<Quote>();  
     Quote preventivo = new Quote(Name = 'Test',OpportunityId = opp.id, N_Offerta__c = 'test');
     insert preventivo;
     l_preventivi.add(preventivo);
     
     // Pricebook2 standardPB = [select id from Pricebook2 where isStandard=true];
        
     Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book 2009', Description = 'Price Book 2009 Products', IsActive = true);
     insert pb;
        
      Product2 prod = new Product2(Name = 'Anti-infectives 2007', Family = 'Best Practices', IsActive = true);
      insert prod;

     List<QuoteLineItem> l_qtl = new List<QuoteLineItem>();
     QuoteLineItem qtl = new quotelineitem(quoteid = preventivo.id,quantity = 1,unitprice = 1); 
     insert qtl;
     l_qtl.add(qtl);

      ApexPages.StandardController controller = new ApexPages.StandardController(preventivo);
      Ordine_Aziendale stdController = new Ordine_Aziendale(controller);



/********************************************** FINISH TEST   *************************************/      
 
   test.stopTest();

   }
  
 }

 
When I convert a lead in lightning experience I need to force a user to create an Opportunity. Is there any validation that will allow me to do this?
  • September 08, 2016
  • Like
  • 0
How to clone opportunity with opp products in a trigger.
I have all my functionality set in trigger .I want Line items to be cloned to new cloned opportunities.

Please help