• domdick
  • NEWBIE
  • 10 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 56
    Questions
  • 82
    Replies
Hello,

I have data on CSV format that needs to sync with salesforce object. I know i can use Data loader as batch update but i would like to make this an automation.
The CSV contains the value as External Id (that related with object's custom field)

How can i update / upsert the CSV file every hour / other times to SF object? Bulk API or Schedule APEX class?

Can someone please provide an example code to kick off?

Thanks, 
Hello,

I am trying to insert 2 parents and multiple parent's child records but it ended with an error "cannot specify Id in an insert call".
Can anyone add some inputs?

Thanks!

public class Notes{
	
    public Id scId { get; set; }
    public Id newScId { get; set; }
    public Date newScDate { get; set; }
    public Date firstDayScDate { get; set; }
    private Subscription__c sc { get; set; }
        
    public Notes(ApexPages.StandardController controller) {
        newScId = ApexPages.currentPage().getParameters().get('newSc');
		newScDate = Date.valueOf(ApexPages.currentPage().getParameters().get('newScDate')); 
    }
    
    public PageReference saveNotes() {
        Savepoint spCredit = Database.setSavepoint();
        try{
            /******* the following query is returning two records *********/
            for(Parent__c pc : [Select Id, Name, Quantity, Price__c, Discount from Parent__c Where Subscription__c =: newScId]) {
            	Parent__c newPc = pc.clone(false);
                newPc.Subscription__c = newScId;
                newPc.ServiceDate = Date.today();
              	
                insert newPc;
                
                // Lets insert Parent's children
                // the following query is returning multiple records.
                List<Childs__c> seChilds = new List<Childs__c>();
                List<Childs__c> getChilds = [Select Id, Type__c, Quantity, ExpiaryDate From Childs__c Where Parent__c =: pc.Id];
                for(Childs__c ChildsSch : getChilds) {                    
                    Childs__c newChilds = ChildsSch.clone(false);
                    newChilds.Parent__c = newPc.Id;
                    newChilds.Type__c = 'Rollup';
                    
                    seChilds.add(newChilds);
                }
                insert seChilds;
            }
        } catch (Exception ex) {
            Database.rollback(spCredit);
            ApexPages.addMessages(ex);
            return null;
        }
        return new PageReference('/');
    }
}

Hi,

How to find no. of days between multiple dates (whether it's a weekly or monthly schedule) in APEX?

records into the sobject...
Multiple_Date__c     Payment__c
01/05/2014               200.00 
08/05/2014               200.00 
15/05/2014               200.00 
22/05/2014               200.00 
29/05/2014               200.00 
05/06/2014               200.00

Thanks!!
Hello,

I have following entries on perio__c sObject.

Id                use__c          aggregated_use__c      year
a2vL.......       0                                                       2013
a2vLi......       2                                                       2013
a2vLu.....       0                                                       2013
a2vLe.....       2                                                       2013
a3vK3.....       1                                                       2014
a3vK4.....       2                                                       2014

I would like to aggregat "use__c" values and update on aggregated_use__c field. So the result would be on perio__c sObject....

Id                use__c          aggregated_use__c      year
a2vL.......       0                           0                          2013
a2vLi......       2                           2                          2013
a2vLu.....       0                           2                          2013
a2vLe.....       2                           4                          2013
a3vK3.....       1                           1                          2014
a3vK4.....       2                           3                          2014         
Can anyone add some intputs with an example?

Many thanks,
Hello,

I have following trigger that validate some field's value before Opportunity Won and specific profile can revoke this trigger validation.
It works fine as expected but struggling to get 100% test code coverage on the .addError method

Can someone help me here?

Thanks,

Trigger:

trigger validSchedule on Opportunity (before update) {
   
    List<Id> oppsIDs = new List<Id>();  
  
        Id distributionId = '00e200000';
        for(Opportunity opp : Trigger.new) {
            if(opp.StageName == 'Confirmation') {
                oppsIds.add(opp.Id);               
            }           
        }       
            List<OpportunityLineItem> oli = [Select Id, Schedule_start_date__c, Contract_start_date__c, HasRevenueSchedule from OpportunityLineItem where Opportunity.Id in :oppsIds];           
            if(oli.size() > 0) {               
                for (OpportunityLineItem olis : oli) {  
                    if(olis.Schedule_start_date__c < olis.Contract_start_date__c && olis.HasRevenueSchedule == true
                      && UserInfo.getProfileId() != distributionId) {
                        Trigger.new[0].addError('My ERROR Message');  /* Does not get the code coverage */
                    }
              }
       }
}

Test Class:

@isTest(SeeAllData=true)
private class validScheduleTest{

    static testMethod void myUnitForvalidScheduleTest() {
      Pricebook2 pb = [Select Id, Name From Pricebook2 Where IsStandard = true Limit 1];
       
       Account act = [SELECT Id from Account LIMIT 1];      
       
        // Create a test Opportunity for the Subscription contract
        Opportunity o  = new Opportunity();
        o.Name         = 'TEST valid Contract';
        o.AccountId    = act.Id;
        o.CloseDate    = Date.today();
        o.StageName    = 'Interest';      
        insert o;

        // Create a test product2
        Product2 p = new Product2();
        p.Name     = 'TEST valid Sub';
        p.CanUseRevenueSchedule = true;
        p.NumberOfRevenueInstallments = 2;

        insert p;
       
        // Create a test pricebook entry.
        PricebookEntry pbe = new PricebookEntry();
        pbe.Pricebook2Id = pb.id;
        pbe.Product2Id   = p.id;       
        pbe.IsActive     = true;
        pbe.UnitPrice    = 500.00;
       
        insert pbe;
       
        // Create a test Opportunity line item
        OpportunityLineItem i = new OpportunityLineItem();
        i.opportunityId       = o.id;
        i.pricebookentryid    = pbe.id;
        i.quantity            = 1;
        i.TotalPrice = 1000.00;
        i.ServiceDate = Date.today();
        insert i;
       
        OpportunityLineItemSchedule[] OliSchInsert = new OpportunityLineItemSchedule[]{};
            Date curDate = Date.today().addDays(-2);
            for(Integer x=0; x < 3; x++) {
             OpportunityLineItemSchedule OliSchIn = new OpportunityLineItemSchedule();
                OliSchIn.OpportunityLineItemId = i.Id;
                OliSchIn.Revenue = 500.00;
                OliSchIn.Type = 'Revenue';
                OliSchIn.ScheduleDate = curDate;
               
                OliSchInsert.add(OliSchIn);
               
                curDate = Date.today().addMonths(2);               
            }
         insert OliSchInsert;      
       
        o.StageName = 'Confirmation';
        try{
            update o;
         }
         catch(Exception ex){
             Boolean expectedExceptionThrown =  ex.getMessage().contains('My Error Message') ? true : false;
                System.AssertEquals(expectedExceptionThrown, true);
         }
     }
}

Hello,

 

How can i concat mulitple line items to single string value?

 

For an example: Object B have 3 line items records like Test1, Test2, Test3

So set a single field (textarea) on the Object A with list of all line items records in Object B.

 

Thanks in advanced!

Dinesh

Hello,

 

I would like to insert parent and multiple child records in single click.

Basically, i am trying to create a parent VF page. So if the use hit "save" button then insert the parent record and insert multiple child records same time.

 

How can i solve this via apex class? Any example?

 

Thanks,

Dinesh

Hello,

I have following formula that works fine if the start date is 01/10/2013 and terms_month is 3 then it gives me the result on end date 31/12/2013

But the business prospective we need to add additional day on the end date so the results would auto calculate end date to 01/01/2014.

Any idea with an example???

formula so far:
DATE(Year(start_date__c)+ floor((MONTH(start_date__c) + term_months__c -1) / 12) ,
mod(MONTH(start_date__c) + term_months__c-1, 12) + 1 ,
day(start_date__c)) - 1

Hello,

 

I am trying to write a test class for the follwing Apex class controller but getting only 61% code coverage. Can some one please help to get the maximum?

 

Thanks,

Dinesh

 

Apex class:

Public Class AddItemsOnMarktActivities {
    Public List<Marketing_Activities__c> MAToInsert { get; set; } 
    Public Integer numberOfRowToRemove { get; set; }
    Public Online_events__c opp { get; set; }
    Public Integer num { get; set; }
    
    Public AddItemsOnMarktActivities(ApexPages.StandardController stdController)
    {
        MAToInsert = new List<Marketing_Activities__c>();
        this.opp = (Online_events__c)stdcontroller.getRecord();        
    }

    // The method to add a new item(s) to the list
    Public PageReference addNewMAItem(){    /******* NOT GETTING TEST COVERAGE FOR THIS SECTION ******************/
        for(Integer i = 0; i < num ; i++) {
            Marketing_Activities__c MAnewItems = new Marketing_Activities__c(Online_Events__c = opp.id);
            MAToInsert.add(MAnewItems);
        }
        return null;
    }

    // The method to remove an item(s) from the list
    Public PageReference removeNewMA(){    /******* NOT GETTING TEST COVERAGE FOR THIS SECTION ******************/
        MAToInsert.remove(numberOfRowToRemove);  

        return null;
    }
        
    // The method to save an item(s) to the sObject.
    public PageReference onSave() {
        try {
            if(MAToInsert.size()>0)                  
                insert(MAToInsert);                  
            }
            catch(Exception e) {      /******* NOT GETTING TEST COVERAGE FOR THIS SECTION ******************/
                ApexPages.addMessages(e);
                return null;
            }
            return new PageReference('/' + ApexPages.currentPage().getParameters().get('Id'));
    }
}

 

Test class so far:

@isTest
private class AddItemsMarktActivitiesTest {
    static testMethod void myUnitAddItemsMarktActivitiesTest() {
        Online_Events__c oe = new Online_Events__c();
        oe.Name = 'Add Items MA'; oe.Event_Title__c = 'Add Items MA Title'; oe.Event_Date__c = Date.today(); oe.Event_type__c = 'Test';       
        insert (oe);        
        
        List<Marketing_Activities__c> marc = new List<Marketing_Activities__c>{};
        for(Integer i = 0; i < 2 ; i++) {
            Marketing_Activities__c marcItems = new Marketing_Activities__c(Online_Events__c = oe.id);
            marc.add(marcItems);
        }        
        insert (marc);
                                
        PageReference MAref = new PageReference('/apex/NewMarketingActivities?Id=' + oe.Id);
    	Test.setCurrentPage(MAref);
    	
    	Apexpages.Standardcontroller controllers = new Apexpages.Standardcontroller(oe);
    	AddItemsOnMarktActivities addItemsMar = new AddItemsOnMarktActivities(controllers);
    	
    	ApexPages.currentPage().getParameters().put('id',+oe.Id);
    	
    	addItemsMar.addNewMAItem();
    	addItemsMar.onSave();    	
    }
}

 

Hello,

 

I have an opportunity with OLI item added and i would like display line item on VF page with subtotal and minus discount (if any) number. I am struggling to write a query results / produce solution to display below.

 

VF should display:

Service   ListPrice   Discount  Terms  TotalPrice

TEst1      480           10%         5          2400.00

Test2       500            5%          10        5000.00

Test3       100            0%          10        1000.00

 

SubTotal                                              8400.00

Discount number                                -  740.00   (This number based on if there is any discount applicable from above OLI)

 

Thanks a lot for helping me here!

 

Hi,

 

I have following code on VF page.

              <apex:column headerValue="theField">
                    <apex:inputField value="{!pc.numericVal}" required="false" id="Field" />                                       
                </apex:column>

when hit "save" button, I would like to pass the value (Non-blank) if user doensn't fill out above inputfield?

 

Any solutions?

 

Thanks

Hello,

 

Background:

Currently I have Custom controller that will select the Product services and insert OLI into relevant Opportunity. And OLI is creating revenue schedule if there is any.(via trigger after insert)

 

Also:

I have validation rule (under OLI) in place that check: AND(Hasrevenueschedule, Ischanged(unitprice))

 

How can i insert the child record(OLI schedule) after parent(OLI) has been saved. Can i use same controller class to insert child record? so i can avoid validation to execute.

 

Thanks,

Hello,

 

I am trying to figure out how to update the custom lookup field on custom object.

Process:

1. i have got random number like "2346" that match with Opportunity object --> booknumber__c

2. now i would like to update above booking number's Id to  memoryCh__c object --> relatedBookingNumber__c (lookup field)

3. how can i make sure trigger should work on batch insert/update as well.

 

Any help would be much appriciated with an exmaple!

 

Thanks,

Hello,

 

I have extension class for Opportunity that redirect after save. I have written test method as well for this but I am struggling to get full code coverage.

 

so the test method doesn't cover "return contoller.save()" from extension class. Can someone please point me where i am doing wrong?

 

Thanks,

 

Class:

Public Class NewBookingExtension {

    Public Opportunity opps {get; set;}
    Private ApexPages.StandardController controller;    
    
    Public NewBookingExtension(ApexPages.StandardController controller){
        this.controller = controller;        
    }
    
    Public PageReference saveAndService() {        
        if(controller.save() !=null) {
            PageReference saveAndServ = Page.AddServices;
            saveAndServ.setRedirect(true);
            saveAndServ.getParameters().put('id',controller.getId());
        
            return saveAndServ; 
        }
        return controller.save();  /* this line doesn't cover on test method. */       
    }
}

 

Test Class:

@IsTest(SeeAllData=true)
private class NewBookingExtensionTest {

    static testMethod void myUnitForExtensionTest() {
        Pricebook2 pb = [Select Id, Name From Pricebook2 Where IsStandard = true Limit 1];

        /* Setup a basic opportunity */
        Account act = [SELECT Id from Account LIMIT 1];
        Opportunity o  = new Opportunity();
        o.Name         = 'TEST for new booking';
        o.AccountId    = act.Id;
        o.CloseDate    = Date.today();
        o.StageName    = 'Insert';
        
        Database.insert(o);                                   
        
        Apexpages.Standardcontroller controllers = new Apexpages.Standardcontroller(o);
        NewBookingExtension newBooking = new NewBookingExtension(controllers);        
        ApexPages.currentPage().getParameters().put('id',+o.Id);
        System.assert(newBooking.saveAndService()!=null);        
    }

 

 

 

 

Hello,

 

How can i make sure that just only few users should redirect to the custom visualforce page and rest of other should redirect to the standard add product service page when opportunity has been created?

 

Can someone please help with an example?

 

Thanks,

 

Hello,

 

I have apex controller to check if opportunity has a pricebook associated yet or not. It works fine as user point of view but strugling to make a test class for this.

 

Much appriciate any help with an example!

 

thanks

 

 

 

Hello All,

 

I am inserting a OpportunityLineItem using Apex controller class which has a default revenue schedule defined. The product is added correctly but no revenue schedule created. If i will create the same line item via the UI then the default schedule has been created as expected.

 

How can i achieve this? any sample code will help.

 

thanks,

Dinesh

Hello,

 

I have 1000 list of product names like

Name:

8 online

12 lives

34 services

Additional

Pages

Landing

Build

 

Now i need to build a list which can be filtered based on the straight alphabet.

A | B | C | D | .....| Other |

 

so query will be

 

Query: [ Select Name from Catelog__c where Name Like :string ]
//:string will get the param by selection like A% or B%  

 But i am strugling to make solution if the current page get param value == 'Other' then Query should display non-alphabetic values.

 

Any solution?

 

Thanks

 

 

 

 

 

Hi,

 

I have following class for VF page. But without the test class, i can not process to Production site.

Can someone please help me to write a test class?

 

Many thanks in advace!

 

Class:

public String sortExpression {
        get {
            return sortExp;
        }
        set {
            //if the column is clicked on then switch between Ascending and Descending modes
            if(value == sortExp)
                sortDirection = (sortDirection == 'Asc')? 'Desc' : 'Asc';
            else
                sortDirection = 'Asc';
            sortExp = value;
        }
    }
    
    public String getSortDirection() {
        //if not column is selected 
    	if (sortExpression == null || sortExpression == '')
      		return 'Asc';
    	else
     		return sortDirection;
    }
    
    public void setSortDirection(String value) {
        sortDirection = value;
    }

 

Hello,

 

I am trying to display product line items into a visualforce template and i'd like the product to SortOrder the same way they are in Opportunity.

 

Does anyone know how to make it possible? here is my code...

 

Thanks,

 

controller:

public class OppsControllerExtension {

    private final Opportunity opps;
            
    // The extension constructor initializes the private member 
    
    // variable opps by using the getRecord method from the standard 
    
    // controller. 
        
   public OppsControllerExtension(ApexPages.StandardController stdController) {
        this.opps = (Opportunity)stdController.getRecord();
               
  }
    

public List<OpportunityLineItem> OppsLicence = [SELECT id, ServiceDate, Opportunity.name, TotalPrice_quote__c FROM OpportunityLineItem 
                                         WHERE License_service__c = 1 AND Opportunity.id = 
            :System.currentPageReference().getParameters().get('id') Order by SortOrder Asc];

        public integer getLicenceRowNumber() {
            if (OppsLicence.size() >= 1)
            return OppsLicence.size() - 1;
                       
        else
            return 0;
        }
    
        public list <OpportunityLineItem> getLicenceServicelist () {
        return [SELECT id, ServiceDate, License_service__c, PricebookEntry.Product2.Quote_service_group__c, PricebookEntry.Product2.Quote_service_schedule__c, Opportunity.name FROM OpportunityLineItem 
                                         WHERE License_service__c = 1 AND Opportunity.id = 
            :System.currentPageReference().getParameters().get('id') Order by SortOrder Asc];
     }
      
}

 

Visualforce page:

<apex:page standardController="Opportunity" showHeader="false" renderAs="pdf" extensions="OppsControllerExtension">  

<apex:repeat value="{!Opportunity.OpportunityLineItems}" var="line">

<apex:panelGrid width="100%" cellspacing="0" cellpadding="0" rendered="{!line.PricebookEntry.Product2.Quote_service_group__c=='Licence'}">
             <apex:outputText value="{!line.PricebookEntry.Product2.Service_name_external__c}" />
             <apex:outputText value="{!line.Quantity}" />
             <apex:outputText value="{!line.PricebookEntry.Product2.Channel_capacity__c}"/>
             <apex:outputText value="{0, number, 0}" >
                 <apex:param value="{!line.RevenueSchedule__c}"/>
             </apex:outputText>
             <apex:outputText value="{!line.Currency_ISO_short__c} {!line.TotalPrice_quote__c}" />
             
            </apex:panelGrid>
            
         </apex:repeat>

</apex:page>

 

This formula return the number of the month but, if it is in january it will only return "1" and i need the "01".
Can anyone help? thanks in advance!!
Hello,

I have data on CSV format that needs to sync with salesforce object. I know i can use Data loader as batch update but i would like to make this an automation.
The CSV contains the value as External Id (that related with object's custom field)

How can i update / upsert the CSV file every hour / other times to SF object? Bulk API or Schedule APEX class?

Can someone please provide an example code to kick off?

Thanks, 
Hello,

I have following entries on perio__c sObject.

Id                use__c          aggregated_use__c      year
a2vL.......       0                                                       2013
a2vLi......       2                                                       2013
a2vLu.....       0                                                       2013
a2vLe.....       2                                                       2013
a3vK3.....       1                                                       2014
a3vK4.....       2                                                       2014

I would like to aggregat "use__c" values and update on aggregated_use__c field. So the result would be on perio__c sObject....

Id                use__c          aggregated_use__c      year
a2vL.......       0                           0                          2013
a2vLi......       2                           2                          2013
a2vLu.....       0                           2                          2013
a2vLe.....       2                           4                          2013
a3vK3.....       1                           1                          2014
a3vK4.....       2                           3                          2014         
Can anyone add some intputs with an example?

Many thanks,

Hello,

I want to display selected records in vf page ..

i tried but it s not working..

how can resolve this issue..

 

 

 

 

<apex:page standardController="Account" recordSetVar="Thenumber">
    <apex:form >
        <apex:pageblock >
            <apex:pageBlockSection >
                 <apex:pageBlockTable value="{!Thenumber}" var="num" cellpadding="10" cellspacing="15" >
                    <apex:column headerValue="name" >
                        {!num.Name}
                        
                   <!-- <apex:actionSupport event="onclick" reRender="out" status="mystatus">
                                 <apex:param name="numId" value="{!num.Id}"/>  
                                  </apex:actionSupport> -->                    
                    </apex:column>
                    <apex:column headerValue="Account Number">
                    

                    <apex:outputText value="{!IF((num.accountnumber == null),'N/A',num.accountnumber)}"/>                    
                    </apex:column>
                    <apex:column headerValue="Action">
                        <apex:inputCheckbox >
                           <apex:actionSupport event="onclick" reRender="out" status="mystatus">
                                     <apex:param id="numId" value="{!num.Id}"/>
                                </apex:actionSupport>
                        </apex:inputCheckbox>
                    </apex:column>
                      
                </apex:pageBlockTable>       
            </apex:pageBlockSection>
        </apex:pageblock>
        <apex:actionStatus id="mystatus" startText="Buffering...........">
            <apex:facet name="stop">
                <apex:outputPanel id="out">
                    <apex:detail subject="{!$CurrentPage.parameters.numId}" relatedList="false"/>
                </apex:outputPanel>
            </apex:facet>        
        </apex:actionStatus>
    </apex:form>
</apex:page>

 

  • December 04, 2013
  • Like
  • 0

Hello,

 

I am trying to write a test class for the follwing Apex class controller but getting only 61% code coverage. Can some one please help to get the maximum?

 

Thanks,

Dinesh

 

Apex class:

Public Class AddItemsOnMarktActivities {
    Public List<Marketing_Activities__c> MAToInsert { get; set; } 
    Public Integer numberOfRowToRemove { get; set; }
    Public Online_events__c opp { get; set; }
    Public Integer num { get; set; }
    
    Public AddItemsOnMarktActivities(ApexPages.StandardController stdController)
    {
        MAToInsert = new List<Marketing_Activities__c>();
        this.opp = (Online_events__c)stdcontroller.getRecord();        
    }

    // The method to add a new item(s) to the list
    Public PageReference addNewMAItem(){    /******* NOT GETTING TEST COVERAGE FOR THIS SECTION ******************/
        for(Integer i = 0; i < num ; i++) {
            Marketing_Activities__c MAnewItems = new Marketing_Activities__c(Online_Events__c = opp.id);
            MAToInsert.add(MAnewItems);
        }
        return null;
    }

    // The method to remove an item(s) from the list
    Public PageReference removeNewMA(){    /******* NOT GETTING TEST COVERAGE FOR THIS SECTION ******************/
        MAToInsert.remove(numberOfRowToRemove);  

        return null;
    }
        
    // The method to save an item(s) to the sObject.
    public PageReference onSave() {
        try {
            if(MAToInsert.size()>0)                  
                insert(MAToInsert);                  
            }
            catch(Exception e) {      /******* NOT GETTING TEST COVERAGE FOR THIS SECTION ******************/
                ApexPages.addMessages(e);
                return null;
            }
            return new PageReference('/' + ApexPages.currentPage().getParameters().get('Id'));
    }
}

 

Test class so far:

@isTest
private class AddItemsMarktActivitiesTest {
    static testMethod void myUnitAddItemsMarktActivitiesTest() {
        Online_Events__c oe = new Online_Events__c();
        oe.Name = 'Add Items MA'; oe.Event_Title__c = 'Add Items MA Title'; oe.Event_Date__c = Date.today(); oe.Event_type__c = 'Test';       
        insert (oe);        
        
        List<Marketing_Activities__c> marc = new List<Marketing_Activities__c>{};
        for(Integer i = 0; i < 2 ; i++) {
            Marketing_Activities__c marcItems = new Marketing_Activities__c(Online_Events__c = oe.id);
            marc.add(marcItems);
        }        
        insert (marc);
                                
        PageReference MAref = new PageReference('/apex/NewMarketingActivities?Id=' + oe.Id);
    	Test.setCurrentPage(MAref);
    	
    	Apexpages.Standardcontroller controllers = new Apexpages.Standardcontroller(oe);
    	AddItemsOnMarktActivities addItemsMar = new AddItemsOnMarktActivities(controllers);
    	
    	ApexPages.currentPage().getParameters().put('id',+oe.Id);
    	
    	addItemsMar.addNewMAItem();
    	addItemsMar.onSave();    	
    }
}

 

Hi,

 

I have following code on VF page.

              <apex:column headerValue="theField">
                    <apex:inputField value="{!pc.numericVal}" required="false" id="Field" />                                       
                </apex:column>

when hit "save" button, I would like to pass the value (Non-blank) if user doensn't fill out above inputfield?

 

Any solutions?

 

Thanks

Hello,

 

I have extension class for Opportunity that redirect after save. I have written test method as well for this but I am struggling to get full code coverage.

 

so the test method doesn't cover "return contoller.save()" from extension class. Can someone please point me where i am doing wrong?

 

Thanks,

 

Class:

Public Class NewBookingExtension {

    Public Opportunity opps {get; set;}
    Private ApexPages.StandardController controller;    
    
    Public NewBookingExtension(ApexPages.StandardController controller){
        this.controller = controller;        
    }
    
    Public PageReference saveAndService() {        
        if(controller.save() !=null) {
            PageReference saveAndServ = Page.AddServices;
            saveAndServ.setRedirect(true);
            saveAndServ.getParameters().put('id',controller.getId());
        
            return saveAndServ; 
        }
        return controller.save();  /* this line doesn't cover on test method. */       
    }
}

 

Test Class:

@IsTest(SeeAllData=true)
private class NewBookingExtensionTest {

    static testMethod void myUnitForExtensionTest() {
        Pricebook2 pb = [Select Id, Name From Pricebook2 Where IsStandard = true Limit 1];

        /* Setup a basic opportunity */
        Account act = [SELECT Id from Account LIMIT 1];
        Opportunity o  = new Opportunity();
        o.Name         = 'TEST for new booking';
        o.AccountId    = act.Id;
        o.CloseDate    = Date.today();
        o.StageName    = 'Insert';
        
        Database.insert(o);                                   
        
        Apexpages.Standardcontroller controllers = new Apexpages.Standardcontroller(o);
        NewBookingExtension newBooking = new NewBookingExtension(controllers);        
        ApexPages.currentPage().getParameters().put('id',+o.Id);
        System.assert(newBooking.saveAndService()!=null);        
    }

 

 

 

 

Hello,

 

How can i make sure that just only few users should redirect to the custom visualforce page and rest of other should redirect to the standard add product service page when opportunity has been created?

 

Can someone please help with an example?

 

Thanks,

 

Hello,

 

I have apex controller to check if opportunity has a pricebook associated yet or not. It works fine as user point of view but strugling to make a test class for this.

 

Much appriciate any help with an example!

 

thanks

 

 

 

Hello,

 

I have 1000 list of product names like

Name:

8 online

12 lives

34 services

Additional

Pages

Landing

Build

 

Now i need to build a list which can be filtered based on the straight alphabet.

A | B | C | D | .....| Other |

 

so query will be

 

Query: [ Select Name from Catelog__c where Name Like :string ]
//:string will get the param by selection like A% or B%  

 But i am strugling to make solution if the current page get param value == 'Other' then Query should display non-alphabetic values.

 

Any solution?

 

Thanks

 

 

 

 

 

Hi,

 

I have following class for VF page. But without the test class, i can not process to Production site.

Can someone please help me to write a test class?

 

Many thanks in advace!

 

Class:

public String sortExpression {
        get {
            return sortExp;
        }
        set {
            //if the column is clicked on then switch between Ascending and Descending modes
            if(value == sortExp)
                sortDirection = (sortDirection == 'Asc')? 'Desc' : 'Asc';
            else
                sortDirection = 'Asc';
            sortExp = value;
        }
    }
    
    public String getSortDirection() {
        //if not column is selected 
    	if (sortExpression == null || sortExpression == '')
      		return 'Asc';
    	else
     		return sortDirection;
    }
    
    public void setSortDirection(String value) {
        sortDirection = value;
    }

 

Hello,

 

I would like to write a trigger on First__c object. Trigger objective is

- if new First__c created then udpate User role into custom field on First__c object

- Only if First__c.OwnerId field value change then update User role into custom field on First__c object

 

Can someone share any example?

 

Thanks,

Hello,

 

I am trying to right a trigger to if ServiceDate (from OpportunityLineItem object) change then count ScheduleDate from OpportunityLineItemSchedule object and upate the results on custom field 'RevenueSchedule__c' on OLI standard object.

 

the code may not proper to use. can someone help to get it right please?

 

Many Thanks,

 

trigger revenueUpdate on OpportunityLineItem (after insert, after update) {

    //List<Id> OLIIds = New List<Id>();
    public Double res {get; set;}
    
    List<OpportunityLineItem>updateField = new List<OpportunityLineItem>();
    Set<Id> pbeIds = new Set<Id>();
    for (OpportunityLineItem oli : Trigger.new)
    {
        OpportunityLineItem oldOLI = Trigger.oldMap.get(oli.Id);
        if(oli.ServiceDate != oldOLI.ServiceDate){
            pbeIds.add(oldOLI.Id);
        }
    }
    LIST<AggregateResult> groupedResults  = [Select count(ScheduleDate)OLIsch FROM OpportunityLineItemSchedule where OpportunityLineItemId In: pbeIds ];//Group by OpportunityLineItemId];
    LIST<OpportunityLineItem> Opls = [Select RevenueSchedule__c from OpportunityLineItem where Id In: pbeIds];
    Map<id, OpportunityLineItem> OLINum = new Map<id, OpportunityLineItem>();
    for (OpportunityLineItem oli : Trigger.new){
        OLINum.put(oli.Id,oli);
    }
    for(Integer i=0; i<groupedResults.size(); i++){
        Object numberof = groupedResults[i].get('OLIsch');
        //updateField.RevenueSchedule__c = groupedResults[i].get('OLIsch');
        res =Double.ValueOf(groupedResults[i].get('OLIsch'));
        
    }
    //update updateField;
     Opls.RevenueSchedule__c = res; 
}

 

Hi,

 

we have custom button that render as PDF for Opportunity with their opportunitylineitems.

Now the user will add another opportunitylineitem on same Opportunity and generate the PDF BUT how can i make sure it does include the one that added recently.

 

ex.

1)Opprtunity with 3 lineitem

2) custom button generate PDF with step 1

3) user add another lineitem on same Opportunity

4) custom button generate PDF with step 3 and not include step 1 (3 lineitems)?? HOW???

 

I would appriciate if someone can help.

 

Many thanks,

 

  • September 24, 2012
  • Like
  • 0

Hi,

 

I am working with a client that wants to produce a quote that lists all OpportunityLineItems sub-divded by Product family. I have controller that display Opportunitylineitems on VF page as below...

 

Basic                 1.0  1    03/08/2012  12  USD 149.0  USD 1788.0
                            1.0  12  25/07/2012  10  USD 300.0  USD 3000.0
                            1.0  12  16/08/2012  11   USD 273.0 USD 3003.0

                                                                                              subtotal????

 

Custom              1.0   03/08/2012   USD 1800.0
Single                 1.0    03/08/2012  USD 5500.0
                                                             subtotal????

 

How can i do the subtotal of each product family? Here is the controller that works fine without subtotal.

class:

public class OppsControllerExtension {

    private final Opportunity opps;
    
   public OppsControllerExtension(ApexPages.StandardController stdController) {
        this.opps = (Opportunity)stdController.getRecord();

}

List<OpportunityLineItem> OppsLicence = [SELECT id, ServiceDate, Opportunity.name FROM OpportunityLineItem 
                                         WHERE License_service__c = 1 AND Opportunity.id = 
            :System.currentPageReference().getParameters().get('id')];
   
        public integer getLicenceRowNumber() {
            if (OppsLicence.size() >= 1)
            return OppsLicence.size() - 1;       
           
        else
            return 0;
        }
        public list <OpportunityLineItem> getLicenceServicelist () {
        return [SELECT id, ServiceDate, License_service__c, PricebookEntry.Product2.Quote_service_group__c, PricebookEntry.Product2.Quote_service_schedule__c, Opportunity.name FROM OpportunityLineItem 
                                         WHERE License_service__c = 1 AND Opportunity.id = 
            :System.currentPageReference().getParameters().get('id')];
     }
        
List<OpportunityLineItem> OppsSponsor = [SELECT id, ServiceDate, Opportunity.name FROM OpportunityLineItem 
                                         WHERE Sponsorship_Service__c = 1 AND Opportunity.id = 
            :System.currentPageReference().getParameters().get('id')];
    
     
    public integer getSponsorRowNumber() {
        if (OppsSponsor.size() >= 1) 
                 return OppsSponsor.size() - 1;
        else
            return 0;
        }
    
    public list <OpportunityLineItem> getSponsorServicelist () {
        return [SELECT id, ServiceDate, Sponsorship_Service__c, PricebookEntry.Product2.Quote_service_group__c, PricebookEntry.Product2.Quote_service_schedule__c, Opportunity.name FROM OpportunityLineItem 
                                         WHERE Sponsorship_Service__c = 1 AND Opportunity.id = 
            :System.currentPageReference().getParameters().get('id')];
     }
}

 

Many thanks,