• symantecAP
  • NEWBIE
  • 55 Points
  • Member since 2010

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

I'm trying to make a validation rule so my sales floor can't enter anything but items from a picklist in the subject line of a task.  I have the formula figured out, but can't seem to add a line for the emails.  By default the subject fills in with "Email: subject wording of the email".  Is there a way to put in "Email: (wildcard value)" in my formula" so that anything starting with the subect of "Email:" would be valid, and anything following the words "Email:" would be wildcard?  Here's what I got.

 

NOT(Subject = "Intro Call"
||Subject = "Detail Call"
||Subject = "Re-close Call"
||Subject = "Maint Call"
||Subject = "Maintenance Call"
||Subject = "Not Available"
||Subject = "Available - No Order"
||Subject = "Closed Order" 
||Subject = "Call Tag Request Sent"
||Subject = "Email: *")

 

Need help on the last line.  Thanks.

 

  • August 16, 2010
  • Like
  • 0

Hi All

 

Here is my requirement. 

I have to call an external website from a custom button and display the result on a VF Page. 

I have a button on Contact Object. On the click of a button it should pick up the name field from contact and query the documents related to the name in the Website and display the documents on VF Page. 

 The place i am stuck is how to pass the cONTACT NAME to the website and pick up data.

Kindly help with the design.

Hi ALL

 

I have a question and I am looking for work around to send email Alerts.I have 2 picklist values namely Status__c and Route__c

 

Now an Email Alert should be send initially if Status__c= Submitted for Review and Rout to = checkpoint to group of user 'A'.

and if Status_c=Submitted for Review and Route to = QuickFinder then email Alert to usergroup 'B'

etc

now Route to has 16 values and 16 different groups . I dont want to create 16 different workflow rules. Is there a way we can route the emails in a single workflow.

 

Kindly help

 

Hi All

 

I have the following code and i am not able to test IF Condition in my code.

 

Here is my class and test class so far

global class updateOpportunityStage implements Database.Batchable<sObject>,Schedulable{
global string query ;

global updateOpportunityStage(){

Query = 'Select Id,BigMachines__Status__c,BigMachines__Is_Primary__c,BigMachines__Opportunity__c    from BigMachines__Quote__c where BigMachines__Is_Primary__c = true and BigMachines__Status__c like \'%unison%\' ';

}

global database.querylocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);    
}
    global void execute(SchedulableContext SC){
        integer bSize;
        integer Interval;
        try{
            Apex_Jobs_Settings__c aJob = [select id, name, batch_size__c, Run_Schedule_Interval__c, Isactive__c from Apex_Jobs_Settings__c where name = 'ContactsMerge' limit 1];
            if( aJob.IsActive__c = true){
                bSize = integer.valueOf(aJob.Batch_Size__c);
                Interval = integer.valueOf(aJob.Run_Schedule_Interval__c);
            }  
            else{
      
      
            }
        }
        catch(Exception ex){
        system.debug('ERROR: '+ ex);
        bSize=150;
        interval = 30;
    }    
        updateOpportunityStage stg = new updateOpportunityStage();
        DateTime todayMin = Datetime.now();
        DateTime today = todayMin.addMinutes(Interval);
        
        String seconds = '0';
        Integer minutes = today.minute();
        Integer hours = today.hour(); 
        Integer dayOfMonth = today.day(); 
        Integer month = today.month(); 
        Integer milisec = today.millisecond();
        String dayOfWeek = '?'; 
        Integer year = today.year(); 

        String sch = seconds + ' ' + minutes + ' ' + hours + ' ' + dayOfMonth + ' ' + month + ' ' + dayOfWeek + ' ' + year;
     
        String j = 'New Job:'+hours+':'+minutes+':'+seconds+':'+milisec;

        system.schedule(j, sch, stg);
       
        database.executebatch(stg, bSize);
        
     }

global void execute(Database.BatchableContext BC, List<sObject> scope){

     
    Set<id> liOppIds = new Set<id>();

for(sObject s : scope){

BigMachines__Quote__c quote = (BigMachines__Quote__c)s;
System.debug('Adil'+quote);
if(quote.BigMachines__Status__c.contains('Unison') && quote.BigMachines__Is_Primary__c == true)
liOppIds.add(quote.BigMachines__Opportunity__c);

}


//query all the opportunities in a single query
List<Opportunity> opp = new List<Opportunity>();
opp = [select id, StageName from Opportunity where id in :liOppIds and stagename != 'Closed Won' and  CloseDate >= Today];
for ( Opportunity opps : opp)
{
opps.StageName = 'Closed Won' ; 
}
//update all opportunities in a single DML
if(opp.size() > 0)
update opp;
 
    }
  global void finish(Database.BatchableContext BC){}  

}

 Test class is as follows

 

@isTest

Private class updateOpportunityStage_Test
{
static testMethod void Testclass(){

Opportunity Opp = new Opportunity(Name = 'Test',StageName = 'Closed Won',CloseDate= date.today());

insert opp;



BigMachines__Quote__c bmq = new BigMachines__Quote__c(BigMachines__Status__c = '%Unison%');

insert bmq;
  Apex_Jobs_Settings__c aJob = new   Apex_Jobs_Settings__c(Name ='test',batch_size__c=150,Run_Schedule_Interval__c=30,Isactive__c=true);

insert ajob;



  Test.startTest();  
// Schedule the job
            updateOpportunityStage stg = new updateOpportunityStage();

        
        ID batchprocessid = Database.executeBatch(stg,150);
              updateOpportunityStage stg1 = new updateOpportunityStage();
   String sch = '0 0 6 13 2 ?';        
     system.schedule('Schedule Test', sch, stg1);
 Test.stopTest();

}


}

 Thanks

Adil

Hi All

 

I have the following code. I want to schedule my class every 15 seconds to update parent object called Opportunity.

 

Do let me know if my code is correct to acheive that.

secondly my batch apex is only processing one record. is there any bug in my code. do let ne know

 

global class updateOpportunityStage implements Database.Batchable<sObject>,Schedulable{
global string query ;

global updateOpportunityStage(){

Query = 'Select Id,BigMachines__Status__c  from BigMachines__Quote__c' ;

}

global database.querylocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);    
}
    global void execute(SchedulableContext SC){
        updateOpportunityStage stg = new updateOpportunityStage();
       String cronStr = '0 0 * 30 * ?n';
        System.schedule('Process Quotes', cronStr, stg);
        database.executebatch(stg);
        
    }

global void execute(Database.BatchableContext BC, List<sObject> scope){

     
        Set<id> liOppIds = new Set<id>();
//List <Opportunity> oppList = new List<Opportunity>() ;
for(sObject s : scope){

BigMachines__Quote__c quote = (BigMachines__Quote__c)s;
// System.debug('Adil'+quote);
if(quote.BigMachines__Status__c == 'unison' && quote.BigMachines__Is_Primary__c == true)
liOppIds.add(quote.BigMachines__Opportunity__c);

}


//query all the opportunities in a single query
List<Opportunity> opp = new List<Opportunity>();
opp = [select id, StageName from Opportunity where id in :liOppIds and stagename != 'Closed Won'];
for ( Opportunity opps : opp)
{
opps.StageName = 'Closed Won' ; 
}
//update all opportunities in a single DML
if(opp.size() > 0)
update opp;
 
    }
  global void finish(Database.BatchableContext BC){}  

}

 Thanks

Adil

Hi ALL

 

I created a  Salesforce portal  using Sites. I need a functionality to subscribe to RSS Feed, Subcribe to a twitter feed or facebook page.. How can i ACHEIVE it  . Kindly help

Hi All

 

I am trying to write a class where change in child object field will change a field on Parent Object .

I will have to then schedule the same.

 

I am not sure if my logic is right. I am first querying all the Child records. and putting if statement in my database.execute to check for the field change.

Child object : BigMachines__Quote__c looks up to Opportunity

if  BigMachines__Quote__c.status__c = *unison* then Opportunity.stagename = closed won.

I have written following so far. Kindly help .

global class updateOpportunityStage implements Database.Batchable<sObject>,Schedulable{
global string query = 'SELECT id,BigMachines__Status__c from BigMachines__Quote__c ';



global database.querylocator start(Database.BatchableContext BC){


     //List<BigMachines__Quote__c> quoteList= new List<BigMachines__Quote__c>();
//BigMachines__Quote__c bmq = [Select id,BigMachines__Status__c from BigMachines__Quote__c where BigMachines__Status__c = '*unison*'];
    return Database.getQueryLocator(query);    
}
    global void execute(SchedulableContext SC){
        updateOpportunityStage stg = new updateOpportunityStage();
        database.executebatch(stg);
        
    }

global void execute(Database.BatchableContext BC, List<sObject> scope){

     
                List <Opportunity> oppList = new List<Opportunity>() ;
        for(sObject s : scope){
        
        BigMachines__Quote__c quote = (BigMachines__Quote__c)s;
        System.debug('Adil'+quote);
        
        for (List< BigMachines__Quote__c> bmq :[SELECT id,BigMachines__Status__c from BigMachines__Quote__c ]){
        
         if(quote.BigMachines__Status__c.contains ('unison') &&  quote.BigMachines__Is_Primary__c == true ){

        Opportunity opp = [select id, StageName from Opportunity where id=:quote.id];
         opp.stageName = 'Closed Won' ;
        
    }
    update oppList;
    }
    
    }
    }
  global void finish(Database.BatchableContext BC){}  

}

 Thanks in Advance

Hi All

 

Here is my requirement. I have an Object called Big Machines Quotes and there is a field which is look up to opportunity . Whenever the Status fields on Big Machine Quote is changed to "Approve" then the  stage field on Opportunity is changes to "Closed Won".

The challenge for me is I want to acheive this by Scheduling by Batch Apex. By batch apex should run every 15 mins and update the corresponding field.

 

Kindly help.

Hi All

 

I have a look up filed called Manager  on CONTACT which is a look up to USER Object. I need to update the Manager field with the creatdby users Manager.

 

Here is my code so far kindly help

trigger updateManager on Contact (before insert) {

for ( Contact c : trigger.new) {

if(c.CreatedBy != null)

{
c.Manager__c = UserInfo.getmanagerId();

}
}



}

 Thanks in ADVANCE

AP

Hi All I have written a Batch Apex to create records. ( I dont know if I can write bacth Apex to create records.) and scheduled it. I get the following error

 

First error: Argument 1 cannot be null

 

 I am posting the code below.

global class positioncreate implements Database.Batchable<sObject>{
public String query;

global database.querylocator start(Database.BatchableContext BC){
    return Database.getQueryLocator(query);
}
    
global void execute(Database.BatchableContext BC, List<sObject> scope){
Position__c newtd = new Position__c(NAME= 'Salesforce', max_pay__c = 2000, min_pay__c=1000);
 {
insert newtd;
}
       }
  global void finish(Database.BatchableContext BC){}  
}

 

global class positionsched implements Schedulable
{ 
    global void execute(SchedulableContext ctx){
        
      positioncreate accBatch = new positioncreate ();
    
                        
                         
        ID batchprocessid = Database.executeBatch(accBatch);
       
    }
}

 Kindly help as I am learning Batch Apex

 

Thanks

:)

Hi All

 

 

I am trying to send an email alert thru work flow . I need to send the article link in the work flow.

 

email alert workflow that emails the owner of the Article ,2 weeks prior to archive date. The owner of the document should be notified the document will archive with a link to the article in the SFDC Article Management tab.

 

Kindly help

 

Adil

Hi All 

 

I have a check box field on Account Object which becomes True When there is Activity History present.

I have to write a Trigger on Account which updates the checkbox field when there is Activity History.

 

Kindly help

Hi All 

 

I have a SOQL query . I would like to add a condition to the query. I would want to add a where clause that will exclude accounts that don't have any activity history?

 

 ContactLastActivityDateBatch accBatch = new ContactLastActivityDateBatch ();
    
        accBatch.query ='select Name, Last_visit_subject__c,Last_visit_level_type__c,Last_visit_description__c,Last_visit_date__c, Last_visit_assigned_to__c, Last_visit_record_type__c, Last_visit_purpose__c,  Last_visit_contact_name__c,'
                        +'(Select Subject,Owner.Name,RecordType__c,Purpose__c, whoId ,AccountId,id,ActivityDate,Level_Type__c,Description from ActivityHistories where '
                        +'Custom_Profile_Name__c in (\'Apartments.com House AC\',\'Apartments.com RM User\',\'Apartments.com Standard User\',\'Gannett Standard User\',\'LA Times Standard User\')'
                        +' AND (RecordType__c=\'Standard Event\'  OR  (RecordType__c=\'Event (Contact Optional)\' AND Level_Type__c in (\'Leases 4 Lunch\',\'Mgmt Co - Cold Call Visit\',\'Property - Cold Call Visit\')))'
                        +' AND ActivityDate <= TODAY'
                        +' AND Isdeleted =false'
                        +' order by ActivityDate desc limit 1) from Account';                     

 Thanks in Advance

Hi All 

 

Here is my question . If we are inserting Users  in  Salesforce with all mandatory fields then how is the password generated. Can we have our desired password and insert the Users.

 

Second question : How do we delete users in through Data Loader. 

and how do I schedule the Data Loader?

Hi All

 

I want to know why and when do we use a middle ware during integration. Or what are the scenarios we use middleware and when do we not use one. what difference does it make?

Hi I have an apex classes which is scheduled 1a.m everyday. The apex class aborts and gives the following error

 

First error: SQLException [java.sql.SQLException: ORA-01013: user requested cancel of current operation
: select /*AggJoin*/ "AccountId",
"Id",
"Subject",
"OwnerId",
"RecordType__c",
"Purpose__c",
"WhoId",
"ActivityDate",
"ActivityDate.AUX",

 

Here is my code. Kindly help 

/*
Extension case#03698934
This scheduler will consider only the following Events.
Events where last modify date is yesterday and End date is less then today AND
Profile of Assigned To  = Apartments.com House AC, Apartments.com RM User, Apartments.com Standard User, Gannett Standard User, LA Times Standard User AND
Event Record Type = Standard Event OR (Event Record Type = Event (Contact Optional) AND Level – Type = “Leases 4 Lunch”,” Mgmt Co – Cold Call Visit”,”Property – Cold Call Visit”)
and update the account info on from the selected Events information  

*/

global class ContactLastActivityDateBatch implements Database.Batchable<sObject>{
public String query;

global database.querylocator start(Database.BatchableContext BC){
    return Database.getQueryLocator(query);
}
    
global void execute(Database.BatchableContext BC, List<sObject> scope){
        List<Account> accList= new List<Account>();
     
       
        for(sObject s : scope){
        
        Account acc = (Account)s;
        System.debug('Rajan Testing date 1'+acc);
         if(acc.ActivityHistories.size() > 0 && (acc.Last_visit_date__c == null || acc.Last_visit_date__c <= acc.ActivityHistories[0].ActivityDate)){
            try{
                
               ActivityHistory act = acc.ActivityHistories;                 
               acc.Last_visit_subject__c = act.Subject;
               acc.Last_visit_date__c = act.ActivityDate;
               acc.Last_visit_assigned_to__c = act.Owner.Name;
               acc.Last_visit_record_type__c = act.RecordType__c;
               acc.Last_visit_purpose__c = act.Purpose__c;
               acc.Last_visit_level_type__c=act.Level_Type__c;
               acc.Last_visit_description__c=act.Description;
               
               //Populate only if who Id in Event is populated with a Contact Name.
               if(act.whoId != null && string.valueOf(act.whoId).startsWith('003')) 
               acc.Last_visit_contact_name__c = act.whoId;
               else
               acc.Last_visit_contact_name__c = null;
               //System.debug('Rajan Testing date 2'+c.Last_Activity_Date__c + act.ActivityDate);
                 accList.add(acc);             
            }
            catch(Exception ex){
                System.debug(ex.getMessage());
            }
        }
    }
    update accList;
    
    
    }
  global void finish(Database.BatchableContext BC){}  
}

 

/*Salesforce.com Extension#03698934
This class implements apex schedular interface to update Last Activity Date on Account
*/
global class updateAccountLastActivityDate implements Schedulable
{ 
    global void execute(SchedulableContext ctx){
        
        ContactLastActivityDateBatch accBatch = new ContactLastActivityDateBatch ();
    
        accBatch.query ='select Name, Last_visit_subject__c,Last_visit_level_type__c,Last_visit_description__c,Last_visit_date__c, Last_visit_assigned_to__c, Last_visit_record_type__c, Last_visit_purpose__c,  Last_visit_contact_name__c,'
                        +'(Select Subject,Owner.Name,RecordType__c,Purpose__c, whoId ,AccountId,id,ActivityDate,Level_Type__c,Description from ActivityHistories where '
                        +'Custom_Profile_Name__c in (\'Apartments.com House AC\',\'Apartments.com RM User\',\'Apartments.com Standard User\',\'Gannett Standard User\',\'LA Times Standard User\')'
                        +' AND (RecordType__c=\'Standard Event\'  OR  (RecordType__c=\'Event (Contact Optional)\' AND Level_Type__c in (\'Leases 4 Lunch\',\'Mgmt Co - Cold Call Visit\',\'Property - Cold Call Visit\')))'
                        +' AND ActivityDate <= TODAY'
                        +' AND Isdeleted =false'
                        +' order by ActivityDate desc limit 1) from Account';                                   
                        
                         
        ID batchprocessid = Database.executeBatch(accBatch);
       
    }
}

 Thanks in Advance . 

Hi All 

 

Here is the case.

 

If my SOQL query is returning 70,000 records..( i.e hitting governor limits) How do I process the query using list in batch . Or using List. Please explain me in brief. I thank you in advance

Hi All 

 

I have a requirement of tracking all the field changes on every Object of my Salesforce Organisation. 

Is there any APP on APP exchange that supports the above functionality . 

 

Thanks In Advance

Adil

Hi All 

 

I have an extension for Opportunity Line Item and that inserts Product from the VF Page. When I try to Insert it gives me following error. I did check the Currency ISO Code. They do match . I am stuck with this exception.

 

 

System.DmlException: Insert failed. First exception on row 0; first error:, field integrity exception: PricebookEntryId (pricebook entry currency code does not match opportunity currency code): [PricebookEntryId]

public with sharing class ATFE_SelectProductClass {
    //private final User u; //User sobject
    private final OpportunityLineItem  oppLI;
    public String pricebook {
        get {
            if (System.currentPageReference().getParameters().get('pricebook') == null){
                //pricebook = '01s200000001sBQ';
            }
            else {
                pricebook = System.currentPageReference().getParameters().get('pricebook');             
            }
                return pricebook;
        } 
        
        set;
    }
    
    public Id oppID {
        get {
            if (System.currentPageReference().getParameters().get('oppID') == null){
                //oppID = '006P0000001wIxD';
            }
            else {
                oppID = System.currentPageReference().getParameters().get('oppID');             
            }
                return oppID;
        } 
        
        set;
    }
    
    public List<ATFE_SelectProductWrapper> selectedProducts {
        get {
            if (selectedProducts == null) selectedProducts = new List<ATFE_SelectProductWrapper>();
            return selectedProducts;
        }
        set;
    }     
 
    public String searchText { get; set; }
    public Double productQuanity { get; set; }
    public List<ATFE_SelectProductWrapper> dataList {get;set;}
    
    
    //initializes the private member variable u by using the getRecord method from the standard controller Child_Product_Line_Item__c
    public ATFE_SelectProductClass(ApexPages.StandardController stdController) {
        this.oppLI = (OpportunityLineItem )stdController.getRecord();
    }
    
    public ATFE_SelectProductClass(){}
    
    //builds a picklist of user names based on their profile
    public List<selectOption> getProducts() {
        List<selectOption> options = new List<selectOption>(); //new list for holding all of the picklist options
        
        options.add(new selectOption('', '- None -')); //add the first option of '- None -' in case the user doesn't want to select a value or in case no values are returned from query below
        
        //for (User users : [SELECT Id, Name FROM User WHERE Profile.Name = :username]) { //query for User records with System Admin profile
        //  options.add(new selectOption(users.Id, users.Name)); //for all records found - add them to the picklist options
        //}
        
        for (PricebookEntry pb : [SELECT IsActive, CreatedById, CreatedDate, IsDeleted, LastModifiedById, LastModifiedDate, 
                UnitPrice, Id, Pricebook2Id, ProductCode, Product2Id, Name, SystemModstamp, UseStandardPrice 
                FROM PricebookEntry where Pricebook2Id = :pricebook]) {
            options.add(new selectOption(pb.Id, pb.Name));  
        }
        
        return options; //return the picklist options
    }
    
    public List<PricebookEntry> getProductData() {
        List<PricebookEntry> pbEntry = new List<PricebookEntry>();
        Boolean selected = false;
        pbEntry = [SELECT IsActive, CreatedById, CreatedDate, IsDeleted, LastModifiedById, LastModifiedDate, 
                UnitPrice, Id, Pricebook2Id, ProductCode, Product2Id, Name, Product2.Description, Product2.Family 
                FROM PricebookEntry where Pricebook2Id = :pricebook LIMIT 100]; 
        return pbEntry;
    }
    
    public PageReference search(){
        //List<PricebookEntry> pbEntry = new List<PricebookEntry>();
        //Boolean selected = false;
        if (dataList == null) {
            dataList = new List<ATFE_SelectProductWrapper>(); // init the list if it is null
        } else {
            dataList.clear(); // clear out the current results if they exist
        }   
        
        String qry = 'SELECT IsActive, CreatedById, CreatedDate, IsDeleted, LastModifiedById, LastModifiedDate, UnitPrice, Id, Pricebook2Id, ProductCode, Product2Id, Name, Product2.Description, Product2.Family FROM PricebookEntry where IsActive = true and Pricebook2Id = \'' + pricebook + '\' and Name like \'%' + searchText + '%\'';
        system.debug('qry: ' + qry);
        for(PricebookEntry p : Database.query(qry)) { 
            dataList.add(new ATFE_SelectProductWrapper(p));
        }
        return null;
    }
    
    public PageReference next() { 
        // clear out the currently selected categories
        selectedProducts.clear();
 
        // add the selected categories to a new List
        for (ATFE_SelectProductWrapper pd : dataList) {
            if (pd.selected)
                selectedProducts.add(new ATFE_SelectProductWrapper(pd.pbe));
        }
 
        // ensure they selected at least one category or show an error message.
        if (selectedProducts.size() > 0) {            
            return Page.ATFE_SelectProductDetail;//return null;
        } else {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least one product.'));
            return null;
        } 
    }       
 
    // fired when the back button is clicked
    public PageReference back() {
        return null; //Page.ATFE_SelectProduct;
    }
    
    public PageReference save(){
        //system.debug('selectedProducts: ' + selectedProducts);
        for (ATFE_SelectProductWrapper pd : selectedProducts) {          
            OpportunityLineItem oli2 = new OpportunityLineItem();
            system.debug('oppID: ' + oppID);
            
            //Opportunity opp3 = new Opportunity(Id = oppID);
            
            oli2.Quantity = productQuanity;
            oli2.UnitPrice = pd.pbe.UnitPrice;
            oli2.PricebookEntryId = pd.pbe.Id;
            //oli2.OpportunityId = opp3.Id;  
            oli2.OpportunityId = oppID;  
            
            insert oli2;
            
        }
        //Opportunity opportunity = new Opportunity(Id = oppID);

        //PageReference opportunityPage = new ApexPages.StandardController(opportunity).view();
        PageReference opportunityPage = new PageReference('/' + oppID);
        opportunityPage.setRedirect(true);
        return opportunityPage;
        //return null;
    }       
    
}

 

 

Hi Here is my code and test class so far. please help me cover this as its not covering any class

public class ProductPriceBook23 {
    
   public class productInfo {
    
        public Product2 prod{get; set;}
        public List<PriceBookEntry> pbes {get; set;}
             

        public productInfo() {
            pbes = new List<PriceBookEntry>();
                        



        }
        
    }
    
    public List<ProductInfo> products {get; set;}
    
    public ProductPriceBook23() {
        products = new List<productInfo >();
        Map<Id, productInfo> pInfoMap = new Map<Id, productInfo>();
      for (PricebookEntry pEntry :[Select id, unitPrice, product2Id, product2.Name, product2.Description, product2.Family,product2.ATFE_Status__c, product2.ProductCode, pricebook2id, pricebook2.name from PricebookEntry where   product2.ATFE_Product_Region__c='NA' and product2.Family= 'PRODUCT' and pricebook2.IsActive=true and Pricebook2.name='NA LA (USD)'      LIMIT 1000  ]) {
            ProductInfo pInfo = new ProductInfo();
            if(!pInfoMap.containsKey(pEntry.product2Id)) {
                pInfo.prod = new Product2(id=pEntry.product2Id, Name=pEntry.product2.Name, Description=pEntry.product2.Description, Family=pEntry.product2.Family,ATFE_Status__c=pEntry.product2.ATFE_Status__c, ProductCode=pEntry.product2.ProductCode);
                pInfo.pbes.add(pEntry);

                pInfoMap.put(pEntry.product2Id, pInfo);
            } else {
                pInfo = pInfoMap.get(pEntry.product2Id);
                pInfo.pbes.add(pEntry);
            }
        }
 products = pInfoMap.values();
    }
     
    
}

 and the test class is 

 

@isTest

private class testpricebook{

private static testmethod void testpb(){

PriceBookEntry pbe1=[Select id,unitprice,Product2Id,Product2.Name,Pricebook2.name,
                        Product2.Description,Product2.Family from PriceBookEntry 
                         where product2.ATFE_Product_Region__c='NA' and product2.Family='PRODUCT'  limit 1]; 
Product2 prod = new Product2(Name='AT-iMG008GNB-10',Description='Grounded UPS without battery. Battery must be ordered separetly');

string pricebook = pbe1.Pricebook2.name;
//ProductPriceBook23.Productinfo('01t200000022vPnAAI','USD 47.00','AT-iMG008GNB-10',pricebook);
}



}

 

Please help

 

 

Hi All 

 

I have a controller and I am working to deploy it to the server and it says code coverage failed 

I am struggling with the test class. Here is the controller. 

public class PriceBookserna {
    
   public class productInfo {
    
        public Product2 prod{get; set;}
        public List<PriceBookEntry> pbes {get; set;}
                public List<PriceBookEntry> pbef {get; set;}
                                public List<PriceBookEntry> pbea {get; set;}

                                public List<PriceBookEntry> pbeb {get; set;}
                                  // public List<PriceBookEntry> pbec {get; set;}


        public productInfo() {
            pbes = new List<PriceBookEntry>();
                        pbef = new List<PriceBookEntry>();
           pbea = new List<PriceBookEntry>();
           pbeb = new List<PriceBookEntry>();
                     // pbec = new List<PriceBookEntry>();



        }
        
    }
    
    public List<ProductInfo> products {get; set;}
    
    public PriceBookserna() {
        products = new List<productInfo >();
        Map<Id, productInfo> pInfoMap = new Map<Id, productInfo>();
        for (PricebookEntry pEntry :[Select id, unitPrice, product2Id, product2.Name, product2.Description, product2.Family,product2.ATFE_Status__c, product2.ProductCode, pricebook2id, pricebook2.name from PricebookEntry where   product2.ATFE_Product_Region__c='NA' and product2.Family= 'Service' and pricebook2.IsActive=true and Pricebook2.name='NA LA (USD)'      LIMIT 1000  ]) {
            ProductInfo pInfo = new ProductInfo();
            if(!pInfoMap.containsKey(pEntry.product2Id)) {
                pInfo.prod = new Product2(id=pEntry.product2Id, Name=pEntry.product2.Name, Description=pEntry.product2.Description, Family=pEntry.product2.Family,ATFE_Status__c=pEntry.product2.ATFE_Status__c, ProductCode=pEntry.product2.ProductCode);
                pInfo.pbes.add(pEntry);

                pInfoMap.put(pEntry.product2Id, pInfo);
            } else {
                pInfo = pInfoMap.get(pEntry.product2Id);
                pInfo.pbes.add(pEntry);
            }
        }
        
        for (PricebookEntry pEntry1 :[Select id, unitPrice, product2Id, product2.Name, product2.Description, product2.Family,product2.ATFE_Status__c, product2.ProductCode, pricebook2id, pricebook2.name from PricebookEntry where   product2.ATFE_Product_Region__c='NA' and product2.Family= 'Service' and pricebook2.IsActive=true and Pricebook2.name='NA DIST (USD)'  LIMIT 1000  ]) {
            ProductInfo pInfo = new ProductInfo();
            if(!pInfoMap.containsKey(pEntry1.product2Id)) {
                pInfo.prod = new Product2(id=pEntry1.product2Id, Name=pEntry1.product2.Name, Description=pEntry1.product2.Description, Family=pEntry1.product2.Family,ATFE_Status__c=pEntry1.product2.ATFE_Status__c, ProductCode=pEntry1.product2.ProductCode);
                pInfo.pbef.add(pEntry1);

                pInfoMap.put(pEntry1.product2Id, pInfo);
            } else {
                pInfo = pInfoMap.get(pEntry1.product2Id);
                pInfo.pbef.add(pEntry1);
            }
        }
        
         for (PricebookEntry pEntry2 :[Select id, unitPrice, product2Id, product2.Name, product2.Description, product2.Family,product2.ATFE_Status__c, product2.ProductCode, pricebook2id, pricebook2.name from PricebookEntry where   product2.ATFE_Product_Region__c='NA' and product2.Family= 'Service' and pricebook2.IsActive=true and Pricebook2.name='NA AP (USD)'      LIMIT 1000  ]) {
            ProductInfo pInfo = new ProductInfo();
            if(!pInfoMap.containsKey(pEntry2.product2Id)) {
                pInfo.prod = new Product2(id=pEntry2.product2Id, Name=pEntry2.product2.Name, Description=pEntry2.product2.Description, Family=pEntry2.product2.Family,ATFE_Status__c=pEntry2.product2.ATFE_Status__c, ProductCode=pEntry2.product2.ProductCode);
                pInfo.pbea.add(pEntry2);

                pInfoMap.put(pEntry2.product2Id, pInfo);
            } else {
                pInfo = pInfoMap.get(pEntry2.product2Id);
                pInfo.pbea.add(pEntry2);
            }
        }
       
      for (PricebookEntry pEntry3 :[Select id, unitPrice, product2Id, product2.Name, product2.Description, product2.Family,product2.ATFE_Status__c, product2.ProductCode, pricebook2id, pricebook2.name from PricebookEntry where   product2.ATFE_Product_Region__c='NA' and product2.Family= 'Service' and pricebook2.IsActive=true and Pricebook2.name='NA LA (USD)'      LIMIT 1000  ]) {
            ProductInfo pInfo = new ProductInfo();
            if(!pInfoMap.containsKey(pEntry3.product2Id)) {
                pInfo.prod = new Product2(id=pEntry3.product2Id, Name=pEntry3.product2.Name, Description=pEntry3.product2.Description, Family=pEntry3.product2.Family,ATFE_Status__c=pEntry3.product2.ATFE_Status__c, ProductCode=pEntry3.product2.ProductCode);
                pInfo.pbeb.add(pEntry3);

                pInfoMap.put(pEntry3.product2Id, pInfo);
            } else {
                pInfo = pInfoMap.get(pEntry3.product2Id);
                pInfo.pbeb.add(pEntry3);
            }
        }
   /* for (PricebookEntry pEntry4 :[Select id, unitPrice, product2Id, product2.Name, product2.Description, product2.Family,product2.ATFE_Status__c, product2.ProductCode, pricebook2id, pricebook2.name from PricebookEntry where   product2.ATFE_Product_Region__c='NA' and product2.Family= 'PRODUCT' and pricebook2.IsActive=true and Pricebook2.name like'%(USD)'      LIMIT 1000  ]) {
            ProductInfo pInfo = new ProductInfo();
            if(!pInfoMap.containsKey(pEntry4.product2Id)) {
                pInfo.prod = new Product2(id=pEntry4.product2Id, Name=pEntry4.product2.Name, Description=pEntry4.product2.Description, Family=pEntry4.product2.Family,ATFE_Status__c=pEntry4.product2.ATFE_Status__c, ProductCode=pEntry4.product2.ProductCode);
                pInfo.pbec.add(pEntry4);

                pInfoMap.put(pEntry4.product2Id, pInfo);
            } else {
                pInfo = pInfoMap.get(pEntry4.product2Id);
                pInfo.pbec.add(pEntry4);
            }
        }*/
       
    
        
        products = pInfoMap.values();
    }
     
    
}

 

Please help me with the Test Class. 

 

Hi All

 

Here is my requirement. 

I have to call an external website from a custom button and display the result on a VF Page. 

I have a button on Contact Object. On the click of a button it should pick up the name field from contact and query the documents related to the name in the Website and display the documents on VF Page. 

 The place i am stuck is how to pass the cONTACT NAME to the website and pick up data.

Kindly help with the design.

Hi All

 

I have the following code and i am not able to test IF Condition in my code.

 

Here is my class and test class so far

global class updateOpportunityStage implements Database.Batchable<sObject>,Schedulable{
global string query ;

global updateOpportunityStage(){

Query = 'Select Id,BigMachines__Status__c,BigMachines__Is_Primary__c,BigMachines__Opportunity__c    from BigMachines__Quote__c where BigMachines__Is_Primary__c = true and BigMachines__Status__c like \'%unison%\' ';

}

global database.querylocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);    
}
    global void execute(SchedulableContext SC){
        integer bSize;
        integer Interval;
        try{
            Apex_Jobs_Settings__c aJob = [select id, name, batch_size__c, Run_Schedule_Interval__c, Isactive__c from Apex_Jobs_Settings__c where name = 'ContactsMerge' limit 1];
            if( aJob.IsActive__c = true){
                bSize = integer.valueOf(aJob.Batch_Size__c);
                Interval = integer.valueOf(aJob.Run_Schedule_Interval__c);
            }  
            else{
      
      
            }
        }
        catch(Exception ex){
        system.debug('ERROR: '+ ex);
        bSize=150;
        interval = 30;
    }    
        updateOpportunityStage stg = new updateOpportunityStage();
        DateTime todayMin = Datetime.now();
        DateTime today = todayMin.addMinutes(Interval);
        
        String seconds = '0';
        Integer minutes = today.minute();
        Integer hours = today.hour(); 
        Integer dayOfMonth = today.day(); 
        Integer month = today.month(); 
        Integer milisec = today.millisecond();
        String dayOfWeek = '?'; 
        Integer year = today.year(); 

        String sch = seconds + ' ' + minutes + ' ' + hours + ' ' + dayOfMonth + ' ' + month + ' ' + dayOfWeek + ' ' + year;
     
        String j = 'New Job:'+hours+':'+minutes+':'+seconds+':'+milisec;

        system.schedule(j, sch, stg);
       
        database.executebatch(stg, bSize);
        
     }

global void execute(Database.BatchableContext BC, List<sObject> scope){

     
    Set<id> liOppIds = new Set<id>();

for(sObject s : scope){

BigMachines__Quote__c quote = (BigMachines__Quote__c)s;
System.debug('Adil'+quote);
if(quote.BigMachines__Status__c.contains('Unison') && quote.BigMachines__Is_Primary__c == true)
liOppIds.add(quote.BigMachines__Opportunity__c);

}


//query all the opportunities in a single query
List<Opportunity> opp = new List<Opportunity>();
opp = [select id, StageName from Opportunity where id in :liOppIds and stagename != 'Closed Won' and  CloseDate >= Today];
for ( Opportunity opps : opp)
{
opps.StageName = 'Closed Won' ; 
}
//update all opportunities in a single DML
if(opp.size() > 0)
update opp;
 
    }
  global void finish(Database.BatchableContext BC){}  

}

 Test class is as follows

 

@isTest

Private class updateOpportunityStage_Test
{
static testMethod void Testclass(){

Opportunity Opp = new Opportunity(Name = 'Test',StageName = 'Closed Won',CloseDate= date.today());

insert opp;



BigMachines__Quote__c bmq = new BigMachines__Quote__c(BigMachines__Status__c = '%Unison%');

insert bmq;
  Apex_Jobs_Settings__c aJob = new   Apex_Jobs_Settings__c(Name ='test',batch_size__c=150,Run_Schedule_Interval__c=30,Isactive__c=true);

insert ajob;



  Test.startTest();  
// Schedule the job
            updateOpportunityStage stg = new updateOpportunityStage();

        
        ID batchprocessid = Database.executeBatch(stg,150);
              updateOpportunityStage stg1 = new updateOpportunityStage();
   String sch = '0 0 6 13 2 ?';        
     system.schedule('Schedule Test', sch, stg1);
 Test.stopTest();

}


}

 Thanks

Adil

Hello,

 

I have a simple trigger on the Opportunity object that fires when an Opportunity is edited and forces an edit/save on the OpportunityLineItems associated with the Opportunity.  When I try to Data Load some bulk changes, I get the following error:

 

System.LimitException: Too many SOQL queries: 101

 

I'm fairly new to Apex code.  I believe the problem is that I am running SOQL inside a FOR loop, but I'm not quite sure how to resolve it.  My trigger is below.  Any help would be appreciated.  Thanks.

 

 

trigger UpdateDeliverables on Opportunity (after insert, after update) {
   // Forces Edit/Save on Deliverables in order to fire Workflow field Update to update quantity field with Q__c value    

FOR(Opportunity opp : Trigger.new)  {

    LIST<OpportunityLineItem> oppLine = [SELECT Id
    FROM OpportunityLineItem
    WHERE OpportunityId = :opp.Id
    AND Flat_Price__c != TRUE];
    
    IF(oppLine.size() > 0)
    update oppLine;
    }

}

Hi All

 

I am trying to write a class where change in child object field will change a field on Parent Object .

I will have to then schedule the same.

 

I am not sure if my logic is right. I am first querying all the Child records. and putting if statement in my database.execute to check for the field change.

Child object : BigMachines__Quote__c looks up to Opportunity

if  BigMachines__Quote__c.status__c = *unison* then Opportunity.stagename = closed won.

I have written following so far. Kindly help .

global class updateOpportunityStage implements Database.Batchable<sObject>,Schedulable{
global string query = 'SELECT id,BigMachines__Status__c from BigMachines__Quote__c ';



global database.querylocator start(Database.BatchableContext BC){


     //List<BigMachines__Quote__c> quoteList= new List<BigMachines__Quote__c>();
//BigMachines__Quote__c bmq = [Select id,BigMachines__Status__c from BigMachines__Quote__c where BigMachines__Status__c = '*unison*'];
    return Database.getQueryLocator(query);    
}
    global void execute(SchedulableContext SC){
        updateOpportunityStage stg = new updateOpportunityStage();
        database.executebatch(stg);
        
    }

global void execute(Database.BatchableContext BC, List<sObject> scope){

     
                List <Opportunity> oppList = new List<Opportunity>() ;
        for(sObject s : scope){
        
        BigMachines__Quote__c quote = (BigMachines__Quote__c)s;
        System.debug('Adil'+quote);
        
        for (List< BigMachines__Quote__c> bmq :[SELECT id,BigMachines__Status__c from BigMachines__Quote__c ]){
        
         if(quote.BigMachines__Status__c.contains ('unison') &&  quote.BigMachines__Is_Primary__c == true ){

        Opportunity opp = [select id, StageName from Opportunity where id=:quote.id];
         opp.stageName = 'Closed Won' ;
        
    }
    update oppList;
    }
    
    }
    }
  global void finish(Database.BatchableContext BC){}  

}

 Thanks in Advance

While installing the force.com IDE i will get a error JVM Terminated and some other information displayed.

 

What should i do now to resolve this issue?

 

Please anyone help me...

  • November 25, 2011
  • Like
  • 0

Dear All,

 

The problem I am facing is, I have batch apex code updating two fields in Opportunity line Item(OLI). While I run the code for complete batch the values in the field are updating correctly. However, If I spilt the batch apex in two or many, I am facing the issue of the last batch value getting updated in Opportunity line item instead of complete one.

 

for ex:- Consider 3 record of value 50 each, I am expecting the field in OLI to be updated by 150 and it is updating rightly while I run the batch for  Database.executeBatch(job,3); where as if I split the same as  Database.executeBatch(job,2); then the field is getting updated by 50 instead of 150.

 

I read, Database.Stateful can be used to maintain the state accross the batch, can someone help me with sample code for Database.stateful illustrating how to use the function.

 

Thanks in Advance!

  • August 05, 2011
  • Like
  • 0

Hi Developers 

 

I am trying to build a page to display Products and related Price Books in a VF Page. Here is the code and the error 

 

Error : System.LimitException: Too many query rows: 50001

 

 

 

 

public class ProductPriceBook {

    public class productInfo {
    
        public Product2 prod{get; set;}
        public List<PriceBook2> priceBooks {get; Set;}
        public productInfo() {
        priceBooks = new List<PriceBook2>();
        
        }
        
    }
    
    public List<ProductInfo> products {get; set;}
    
    public ProductPriceBook() {
        products = new List<productInfo >();
       
        List<Product2> prods = [Select Name, Description, Family, id from Product2];
       
        List<PricebookEntry> pEntries = [Select id, product2Id, pricebook2id from PricebookEntry ];
        Map<Id, Pricebook2> priceBooks = new Map<id, Pricebook2>([Select id, name from PriceBook2]);
        
        
        for (Product2 prod : prods ) {
            
            ProductInfo pInfo = new ProductInfo();
            pInfo.prod = prod;
            for (PricebookEntry pe : pEntries)  {
                if (pe.product2Id == prod.id) {
                    pInfo.pricebooks.add(priceBooks.get(pe.pricebook2id));
                }
            }
            products.add(pInfo );
            
        }
        
        
        
        
    }
}

 

 

 

 

<apex:page controller="ProductPriceBook">
    <apex:pageBlock >
         <apex:pageblockTable value="{!products}" var="product">
             <apex:column value="{!product.prod.name}" />
              <apex:column >           
                  <apex:repeat value="{!product.pricebooks}" var="priceBook">
                      {!priceBook.name} <br/>
                  </apex:repeat>
                </apex:column>  
                <apex:column value="{!product.prod.Description}" />
                 <apex:column value="{!product.prod.Family}" />           
           </apex:pageblockTable>
    </apex:pageBlock>
</apex:page>

 

 

Hello all,

 

Can you please let me know the steps to make sure that I run the batch apex every 30 minutes all day and everyday...In the UI i can schedule everyday but here i want to execute my batch class everyday and on each and every single day i have to run this Batch Apex every 30 minutes?Please let me know the sequence of actions that i need to take...

 

Here is my schedulable class

 

 

global class ProcessAccs implements Schedulable{
   
    global void execute(SchedulableContext sc) {
        //  Instantiate batch class 
        BatchProcessAccs B = new BatchProcessAccs();
        database.executebatch(B,200);
    }
    
}

Hi

 

I want to write a trigger (before insert and after update) to set a single field on the Account record which is the concatentation of a field from many child records (from ERP_Account). 

 

For exmaple: if the ACCOUNT record has many ERP_Accounts with the value in field ACCOUNTNO as 'TEST1','TEST2','TEST3' respectively, then I want to set ACCOUNTNOS field in the Account record with the value 'TEST1, TEST2, TEST3,' 

 

Dont know where to start - any help would be greatly appreciated.

 

Thanks

Ross

  • April 15, 2011
  • Like
  • 0

 After running a Batch script, a New Apex job gets created. So Whenever I run the batch again, it throws an exception saying:

"The Apex job named "New Job" is already scheduled for execution".

 

then I delete the existing Apex job from Setup -> Monitoring -> Scheduled jobs to resolve the exception.

I need to delete the existing apex jobs automatically once they are completed.  

Are there any possible workarounds for this? 

 

Plz help, its urgent

I have a batch Apex job (A) that, upon completion, needs to launch another batch Apex job (B). Since you can't launch a batch Apex job from from a batch Apex job, job A schedules job B to run 2 seconds later. (JobB is both batchable and schedulable. JobB's schedulable execute() method launches the JobB batch job.)

 

Here's the code from job A's finish() method:

 

 

global void finish(Database.BatchableContext bc) {
// Seconds Minutes Hours Day_of_month Month Day_of_week optional_year
String str = Datetime.now().addSeconds(2).format('s m H d M ?');
JobB cls = new JobB();
System.Schedule('Job B', str, cls);
return;
}

 

Most of the time, this works just fine. However, every now and then, instead of being scheduled to run 2 seconds later, JobB gets scheduled to run 1 year later. For example, I'll see a job in the Scheduled Jobs queue that has a Submitted time of "11/10/2010 5:00PM" and a Next Scheduled Run time of "11/10/2011 5:00PM."

 

I just changed my code to wait 10 seconds instead of just 2 seconds to schedule JobB, which will hopefully eliminate the problem. However, I'm left wondering why 2 seconds isn't sufficient. Any thoughts? Has anybody else run into this kind of problem?

 

  • November 11, 2010
  • Like
  • 0

Hello,

 

My requirement is to delete all the completed scheduled jobs (becoz of 10 limit in org) and then kick off a process every n minutes.

 

Somehow I am not getting any job in completed state although some of the jobs have run in past. All the jobs show in Waiting state.


Here is the sample code (where i am deleting all jobs which is not right ) :

 

List<CronTrigger> completedJobs =[Select c.State, c.EndTime, c.OwnerId, c.Id,c.TimesTriggered, c.NextFireTime,
    c.CronExpression From CronTrigger c ];

 

 //where c.State = 'Completed'
    //where c.EndTime < :currentTime
    
    try{
        System.debug('Scheduled Job Size is ::'+completedJobs.size());
        for(CronTrigger cronJob:completedJobs){
            System.debug(':: Job to Abort::'+String.valueOf(cronJob) + ' c.TimesTriggered ' + cronJob.TimesTriggered
            + ' c.NextFireTime ' +cronJob.NextFireTime);


           // to exclude current job to be deleted

           if(cronJob.Id !=triggerId ) {
                System.abortJob(cronJob.id);
                System.debug(':: Job aborted ::'+String.valueOf(cronJob) );
            }
            else
            {
                System.debug(':: Cannot abort this Job ::'+String.valueOf(cronJob) );
            }
        } 

 

I am stuck so as to how to identify completed jobs and then delete them.

 

Is it some sfdc bug that the schedule job is never shown in completed state? Can anybody let me know if I am missing something?

 

thanks

Anjali