• Akshay Pai
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
Hi All,

I have a Custom button which uses Visualforce page with custom controller. Custom controller's save function does some calculations and redirects to Origin record page where my custon button is placed.
VF PAGE:

<apex:page standardController="ABC__c"  extensions="CustomController" action="{!save}">

</apex:page>
 
Custom controller:

public class CustomController {
    
// Constructor and other intializations

    public PageReference save()
    {
        try{
        
           // performing some calculations
            
            //return reference. 
            String returnUrl = URL.getSalesforceBaseUrl().toExternalForm() +'/' + EncodingUtil.URLENCODE(ApexPages.currentPage().getParameters().get(retURL),'UTF-8');        
            return new Pagereference(returnUrl);
			
        }catch(System.DMLException e){
             ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,e.getDmlMessage(0))); 
            return null;
        }
            
    } 
}




This is working as expected in Salesforce classic. But in Lightening experience the return page is opening in new tab and showing origin page in classic version.  I want to redirect the page to my Origin record page where my custon button is placed in Lightening experience and in the same tab.
Can anyone please help me to achieve this? Thanks in advace.
I have a formula field in OpportunityLineItem -'Is Available'(IsAvailable__c) which takes values from product object's checkbox field -'Is Available'

FORMULA : PricebookEntry.Product2.IsAvailable__c

When I tried to create dummy OpportunityLineItem record  within test class 'Is Available' formula field in OpportunityLineItem is returning me value as false,where as I am setting this value True at product level. Because of this major part of my class is not getting code coverage.
Can anyone please help me  to find what I am doing wrong here.
 
static testmethod void TestMethod() {

        
        //Created A dummy Account and Opportunity records I.e  Acc & Opt
        
		//getting standard pricebook id
        Id pricebookId = Test.getStandardPricebookId();

		//Created a product
        Product2 prod = new Product2(
             Name = 'Product X',
             ProductCode = 'Pro-X',
             isActive = true,
             IsAvailable__c = True // setting field value as true
        );
        insert prod;
        

        //Created pricebook entry
        PricebookEntry pbEntry = new PricebookEntry(
             Pricebook2Id = pricebookId,
             Product2Id = prod.Id,
             UnitPrice = 100.00,
             IsActive = true
        );
        insert pbEntry;
        
        //created opportunity line item.
        OpportunityLineItem oli = new OpportunityLineItem(
             OpportunityId = opt.Id,
             units__c = 25,
             Type__c = 'No. Users',
             PricebookEntryId = pbEntry.Id,
             TotalPrice = 200,
             Quantity = 1
        );
        
        insert oli;
		
		system.debug('oli.IsAvailable__c ='+ oli.IsAvailable__c ); // This is returing me value as false

		Test.startTest(); 
		
		//calling my required methods here
		
		Test.stopTest();
	}

 
I have a formula field in OpportunityLineItem -'Is Available'(IsAvailable__c) which takes values from product object's checkbox field -'Is Available'

FORMULA : PricebookEntry.Product2.IsAvailable__c

When I tried to create dummy OpportunityLineItem record  within test class 'Is Available' formula field in OpportunityLineItem is returning me value as false,where as I am setting this value True at product level. Because of this major part of my class is not getting code coverage.
Can anyone please help me  to find what I am doing wrong here.
 
static testmethod void TestMethod() {

        
        //Created A dummy Account and Opportunity records I.e  Acc & Opt
        
		//getting standard pricebook id
        Id pricebookId = Test.getStandardPricebookId();

		//Created a product
        Product2 prod = new Product2(
             Name = 'Product X',
             ProductCode = 'Pro-X',
             isActive = true,
             IsAvailable__c = True // setting field value as true
        );
        insert prod;
        

        //Created pricebook entry
        PricebookEntry pbEntry = new PricebookEntry(
             Pricebook2Id = pricebookId,
             Product2Id = prod.Id,
             UnitPrice = 100.00,
             IsActive = true
        );
        insert pbEntry;
        
        //created opportunity line item.
        OpportunityLineItem oli = new OpportunityLineItem(
             OpportunityId = opt.Id,
             units__c = 25,
             Type__c = 'No. Users',
             PricebookEntryId = pbEntry.Id,
             TotalPrice = 200,
             Quantity = 1
        );
        
        insert oli;
		
		system.debug('oli.IsAvailable__c ='+ oli.IsAvailable__c ); // This is returing me value as false

		Test.startTest(); 
		
		//calling my required methods here
		
		Test.stopTest();
	}