• Rahul Bhattad 4
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 2
    Replies
I have two objects in this scenario: Main-Offer which is parent object and Sub-Offer which is child object related with Main-Offer via Lookup. I have overridden the New button of Sub-Offer object with VF page which conditionally redirects depending on condition with the help of Action attribute:
 
action="{!IF(redirectPage=true,NULL,URLFOR($Action.Sub_Offer__C.New,null,null,true))}"

​​​​​​​Now the issue is coming when I am trying to create Sub-Offer record from the related list of parent record of Main-Offer. It's not populating the value of Lookup field on the page with the Parent Record's name.
Any suggestion and ideas will be very much appreciated.
I want to display the standard Salesforce page after clicking on 'New' button for some conditions and for others I want to override the 'New' button with a VF page. I am not really sure what should be the correct approach to solve this tricky situation. Any suggestions will be really appreciated.
Hello,

I am trying to send HTML text in the request body for Rest API callout. I came to know that you cannot use Escape quotation marks used around HTML attributes like </br> as it breaks the JSON body. In Apex we cannout escape it by writing it like <\/ br> as it gives compilation error in class. How should I get around this situation so as to send HTML code without breaking JSON?
Hello,

We have two objects in our org Custom1__c and Approver__c which are linked via junction object Approval__c. I  want to build a logic in trigger on Approval Object(after update), which checks the the status(field on Approval) of previous stage approval record(s) and if they are Approved then call the future callout class with details of Approval records of next stage and if the last stage is approved then update therelated Custom1 record's Status field to Active. 

There can be multiple stages of Approvers and each stage can have 1 or 2 Approvers depending on the country.
Some part of my Trigger:
if(trigger.isAfter && trigger.isUpdate){
        Set<Id> MainOfferId = new Set<Id>();
        Integer counter1 = 0;
        Integer counter2 = 0;
        Integer counter3 = 0;
        Map<ID,Approval__c> Approval = new Map<ID,Approval__c>([Select Status__c, Stage__c, Approver_Name__c, Main_Offer_Name__c from Approval__c
                                                               WHERE Stage__c = 1 AND Id =:Trigger.newMap.keySet()]);
        
        for(Approval__c app : Approval.values())
        {
            if(app.Main_Offer_Name__c != null){
                MainOfferId.add(app.Main_Offer_Name__c);
            }
        }
        
        for(Id MOId : MainOfferId){
        List<Approval__c> lstapproval1 = [Select Id from Approval__c WHERE Main_Offer_Name__c =:MOId AND Stage__c = 1];
        List<Approval__c> lstapproval2 = [Select Id from Approval__c WHERE Main_Offer_Name__c =:MOId AND Stage__c = 2];
        List<Approval__c> lstapproval3 = [Select Id from Approval__c WHERE Main_Offer_Name__c =:MOId AND Stage__c = 3];
        
        if(lstapproval1.size()>0){
        for(Approval__c app : lstapproval1)
        {
            if(app.Status__c == 'Approved')
            {
                counter1 = counter1+1;
            }
        }
            if(counter1 == lstapproval1.size())
            {
                if(lstapproval2.size()>0){
                    Set<Id> SecondAppIds = new Set<Id> (new Map<Id,SObject>(lstapproval2).keySet());
                    CreateApprovalRequestAzur.createRequest(SecondAppIds);
                }
                else
                {
                    CameleonCPQ__Custom1__c MO = [Select Id, Status__c from CameleonCPQ__Custom1__c WHERE ID=:MOId];
                    MO.Status__c = 'Active';
                    
                }
            }
            
        }
            
        if(lstapproval2.size()>0){
            for(Approval__c app : lstapproval2){
                if(app.Status__c == 'Approved')
                {
                    counter2 = counter2+1;
                }
            }
             if(counter2 == lstapproval2.size())
             {
                 if(lstapproval3.size()>0)
                 {
                     Set<Id> ThirdAppIds = new Set<Id> (new Map<Id,SObject>(lstapproval3).keySet());
                     CreateApprovalRequestAzur.createRequest(ThirdAppIds);
                 }
                 else
                {
                    CameleonCPQ__Custom1__c MO = [Select Id, Status__c from CameleonCPQ__Custom1__c WHERE ID=:MOId];
                    MO.Status__c = 'Active';
                    
                }
             }
        
        }
            
        }
If 2 stages are approved and 3rd stage Approval record is approved, then according this code, 2nd Stage Approval records will be validated again and will again call the future callout class 'CreateApprovalRequestAzur' with detials for 2nd stage Approval. I don't want this to happen. It should only check 3rd Stage directly.

 
Hello,

We have two objects in our org Custom1__c and Approver__c which are linked via junction object Approval__c. I have a vf page where I show approvers by stages by comparing Sales Price and Margin coming from Custom1 object against the approver records stored in Appover object and then I store the records in Approval object on click of Save button which is linked with Approver and Custom1. So I am basically inserting records in Approval object which are linked to respective Custom1 and Approver record.

There can be multiple stages of Approvers and each stage can have 1 or 2 Approvers depending on the country which I am managing on VF page through controller class. 

When the records are inserted in Approval object, I have a trigger written on Approval (After Insert) which calls a future callout class and sends detail of Approval records of stage 1 and related Custom1 and Approver info to webservice.

Now I want to build a logic in trigger on Approval Object(after update), which checks the the status(field on Approval) of previous stage approval record(s) and if they are Approved then call the future callout class with details of Approval records of next stage and if the last stage is approved then update the Custom1 record's Status field to Active . I am really struggling to build a dynamic logic which will do this no matter how many Approvers are there in a particular stage and how many no of stages are there.

I know this might sound confusing to many readers and I can answer any questions or doubts. Any help will be really appreciated.

Thanks in Advance!
 
I have a controller class that basically has some functionality which runs according to the values of two formula fields. Now when I am writing test class for it, the values of these two formula field aren't getting calculated and always return 0. I have added values for all the fields which are required to calculate the formulas and queried them after the record is inserted in Test class but in debug logs I see the values are always 0.

Tot_SalesPrice_Calc__c and Tot_MarginPercent_Calc__c are the two formula fields with formulas:

Tot_SalesPrice_Calc__c = Total_MainOffer_SalesPriceRounded__c + MO_Travel_Expense_Sales_Price_SCT__c

Tot_MarginPercent_Calc__c = IF( Tot_SalesPrice_Calc__c <> 0, (Tot_SalesPrice_Calc__c - Tot_Cost_Calc__c )/Tot_SalesPrice_Calc__c, 0 )

Field Tot_Cost_Calc__c used in formula field Tot_MarginPercent_Calc__c is also a formula field with formula: Tot_Cost_Calc__c = IF (MO_Tot_Cost__c > 0,( MO_Tot_Cost__c - Project_Promotion__c + MO_Travel_Expense_Cost_SCT__c) , 0)

Here is some part of my Test Class:
@isTest
public class SubmitforApprovalController_TestClass {
    public static Custom1__c objMO;
public static Custom1__c CreateMainOffer()
    {
        objMO = new Custom1__c();
        objMO.Name = 'Test Offer';
        objMO.Total_MainOffer_SalesPriceRounded__c = 150000;
        objMO.MO_Tot_Cost__c = 140000;
        objMO.Project_Promotion__c = 0;
        objMO.MO_Travel_Expense_Cost_SCT__c = 0;
        objMO.MO_Type_SCT__c='O2O';
        //bjMO.Generic_DocGen__r.Reference_Offer_Type__c = 'Project Fire Sol';
        return objMO;
      }

@isTest static void method1(){
        objUser=CreateUser();
        System.runAs(objUser){
          objMO = CreateMainOffer();
            objMO.Generic_DocGen__c = objGenericDocGen.id;
            insert objMO;
            Custom1__c QueriedMO = [SELECT Name,Tot_Cost_Calc__c, Tot_MarginPercent_Calc__c,Tot_SalesPrice_Calc__c FROM Custom1__c WHERE Id = :objMO.Id limit 1];
            system.debug('Marging ++++'+QueriedMO.Tot_MarginPercent_Calc__c);
            system.debug('salesprice ++++'+QueriedMO.Tot_SalesPrice_Calc__c);
 }
}

 
Hello All,

I have this weird requirement of sending information in HTML format to external Azure service which will then send that info to designated receiver(s) through mail. I am calling Azure web service through Rest callout and successfully tested the response coming from it. 

This HTML text which will contain merge field to send information related to that particular record. Now I am not really sure how can I send that text. Can I use Email Template for this requirement or Text Area which will contain HTML text and merged field?

Any help will be really appreciated. Thanks!
I have a VF page in which I have created a picklist using SelectList and SelectOption. I am now facing final hurdle: Selected value getting changed to default one once I click on Save. I am not sure how should I save the value of SelectList without it being revert back to default one.

This is some part of my VF page:
<apex:pageBlockSection title="Technical Approval" id="techapprovalsection" >
         <apex:pageBlock> 
           <apex:pageBlockSectionItem >
               <apex:outputLabel value="Technical Approver 1"></apex:outputLabel>
               <apex:selectList multiselect="false" required="true" value="{!TechnicalApprover1}" size="1">
                <apex:selectOptions value="{!TechnicalAppList}"/>
               </apex:selectList>
             </apex:pageBlockSectionItem>
           </apex:pageBlock>

         <apex:pageBlock >
           <apex:pageBlockButtons location="bottom">
             <apex:commandButton value="Save" action="{!dosave}"/>
           </apex:pageBlockButtons>
         </apex:pageBlock>

Below is some portion of my Controller class:
public class SubmitforApprovalController {
public SubmitforApprovalController() {
searchTechApproval(OfferType, SalesPrice, MOMargin, objMO);
}

public List<SelectOption> searchTechApproval(String OfferType, Decimal SalesPrice, Decimal MOMargin, Custom1__c objMO)
{
 QueriedTechApprovers= [Select Id, Name,                    Approval_Level__c, GID__c, Mail__c, 
                                         Offer_Type__c, SalesPrice_Range__c, Signature__c, 
                                        TotalMargin_Range__c, Max_Stages__c, Stage__c, 
                                        First_Name__c, Last_Name__c from Approver__c 
                                        Where Sales_Volume_LB__c <= :TotalPrice AND 
                                        Sales_Volume_UB__c > :TotalPrice];
if(QueriedTechApprovers.size()>0){
            TechnicalApprover1 = QueriedTechApprovers[0].Name;

if(QueriedSalesApprovers.size()>0){
        for(Approver__c app : QueriedSalesApprovers){
          lstSalesApprovers.add(new SelectOption (app.Name,app.Name));
 }
}

public pageReference dosave(){
if(!String.isEmpty(TechnicalApprover1) && QueriedTechApprovers.size()>0){
       Approver__c TechApproverChange1 = [Select Id, Name, Stage__c,First_Name__c, Last_Name__c from Approver__c WHERE ID =: TechIDs AND Name =: TechnicalApprover1 LIMIT 1];
        Approval__c apptech1 = new Approval__c();
        apptech1.Main_Offer_Name__c = objMO.Id;
        apptech1.Approver_Name__c = TechApproverChange1.Id;
        apptech1.Stage__c = TechApproverChange1.Stage__c;
        insert apptech1;
        isTechApprover = true;
     }

Whenever I click on Save button, page refreshes and value of picklist changes to default one set by controller. I want it to remain as it is.
I have trigger on Before Update event that calls a method of class with Set of IDs as input parameter. In the class I am fetching the details of couple of formula field based on Id that I have passed and then doing some opertation based on different values of these two formula fields. I have tested manually the funtionality and it's working as expected.

Now the issue is with Test Class. I have called this Class after I have  setup the data but in Raw Logs the values of these two formula field is coming 0.00.

I have used Formula.recalculateFormulas method as well between start and stop test and then called the method of the class. In Debug I can see the values correctly calculated by Formula.recalculateFormulas but once it calls the class and it's method, I can see values as 0.00 only. I am not sure what do I need to do in order to have these calculated values of formula once Test class calls the method
I have a controller class that basically has some functionality which runs according to the values of two formula fields. Now when I am writing test class for it, the values of these two formula field aren't getting calculated and always return 0. I have added values for all the fields which are required to calculate the formulas and queried them after the record is inserted in Test class but in debug logs I see the values are always 0.

Tot_SalesPrice_Calc__c and Tot_MarginPercent_Calc__c are the two formula fields with formulas:

Tot_SalesPrice_Calc__c = Total_MainOffer_SalesPriceRounded__c + MO_Travel_Expense_Sales_Price_SCT__c

Tot_MarginPercent_Calc__c = IF( Tot_SalesPrice_Calc__c <> 0, (Tot_SalesPrice_Calc__c - Tot_Cost_Calc__c )/Tot_SalesPrice_Calc__c, 0 )

Field Tot_Cost_Calc__c used in formula field Tot_MarginPercent_Calc__c is also a formula field with formula: Tot_Cost_Calc__c = IF (MO_Tot_Cost__c > 0,( MO_Tot_Cost__c - Project_Promotion__c + MO_Travel_Expense_Cost_SCT__c) , 0)

Here is some part of my Test Class:
@isTest
public class SubmitforApprovalController_TestClass {
    public static Custom1__c objMO;
public static Custom1__c CreateMainOffer()
    {
        objMO = new Custom1__c();
        objMO.Name = 'Test Offer';
        objMO.Total_MainOffer_SalesPriceRounded__c = 150000;
        objMO.MO_Tot_Cost__c = 140000;
        objMO.Project_Promotion__c = 0;
        objMO.MO_Travel_Expense_Cost_SCT__c = 0;
        objMO.MO_Type_SCT__c='O2O';
        //bjMO.Generic_DocGen__r.Reference_Offer_Type__c = 'Project Fire Sol';
        return objMO;
      }

@isTest static void method1(){
        objUser=CreateUser();
        System.runAs(objUser){
          objMO = CreateMainOffer();
            objMO.Generic_DocGen__c = objGenericDocGen.id;
            insert objMO;
            Custom1__c QueriedMO = [SELECT Name,Tot_Cost_Calc__c, Tot_MarginPercent_Calc__c,Tot_SalesPrice_Calc__c FROM Custom1__c WHERE Id = :objMO.Id limit 1];
            system.debug('Marging ++++'+QueriedMO.Tot_MarginPercent_Calc__c);
            system.debug('salesprice ++++'+QueriedMO.Tot_SalesPrice_Calc__c);
 }
}

 
I have trigger on Before Update event that calls a method of class with Set of IDs as input parameter. In the class I am fetching the details of couple of formula field based on Id that I have passed and then doing some opertation based on different values of these two formula fields. I have tested manually the funtionality and it's working as expected.

Now the issue is with Test Class. I have called this Class after I have  setup the data but in Raw Logs the values of these two formula field is coming 0.00.

I have used Formula.recalculateFormulas method as well between start and stop test and then called the method of the class. In Debug I can see the values correctly calculated by Formula.recalculateFormulas but once it calls the class and it's method, I can see values as 0.00 only. I am not sure what do I need to do in order to have these calculated values of formula once Test class calls the method