• Sagar_SFDC
  • NEWBIE
  • 0 Points
  • Member since 2017
  • Salesforce Developer
  • Signity Software Solutions


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 8
    Replies
User-added image

Stuck in challenge 2 with the above issue. Below is my code.

orderTrigger  -------- 

/**
 * @name orderTrigger
 * @description
**/
trigger orderTrigger on Order(after update) {
    try{
        if(Trigger.isUpdate && Trigger.New != null){
            OrderHelper.AfterUpdate(Trigger.New,Trigger.old);
        }
    }catch(Exception e){
        System.debug('Exception in trigger -- '+e.getMessage());
    }
}


OrderHelper  --------


public with sharing class OrderHelper {

    /**
     * @name AfterUpdate
     * @description 
     * @param List<Order> newList
     * @param List<Order> oldList
     * @return void
    **/
    public static void AfterUpdate(List<Order> newList, List<Order> oldList){
        Set<Id> orderIds = new Set<Id>();
        for ( Integer i=0; i<newList.size(); i++ ){
            if (newList[i].Status == Constants.ACTIVATED_ORDER_STATUS && oldList[i].Status != Constants.ACTIVATED_ORDER_STATUS){
                orderIds.add(newList[i].Id);
            }
        }
        RollUpOrderItems(orderIds);
    }

    /**
     * @name RollUpOrderItems
     * @description Given a set of Activated Order ids, query the child Order Items and related Products to calculate Inventory levels
     * @param Set<Id> activatedOrderIds
     * @return void
    **/
    public static void RollUpOrderItems(Set<Id> activatedOrderIds){
        //ToDo: Declare a Map named "productMap" of Ids to Product2 records
        Map<Id,Product2> productMap = new Map<Id,Product2>();
        Set<Id> productIds = new Set<Id>();
        
        //ToDo: Loop through a query of OrderItems related to the activatedOrderIds
        for(OrderItem oi : [SELECT Id, Product2Id, Product2.Quantity_Ordered__c, Quantity FROM OrderItem
                            WHERE OrderId IN :activatedOrderIds]){
            productIds.add(oi.Product2Id);                         
        }
        
        //ToDo: Populate the map with the Id of the related Product2 as the key and Product2 record as the value
        productMap = new Map<Id, Product2>([SELECT Id, Quantity_Ordered__c FROM Product2 WHERE Id IN :productIds]);
        
        AggregateResult[] groupedResult = [SELECT Product2Id, SUM(Quantity) activatedQuantity FROM OrderItem
                                             WHERE Product2Id IN :productMap.keySet() GROUP BY Product2Id];
        
        //ToDo: Loop through a query that aggregates the OrderItems related to the Products in the ProductMap keyset
        for(AggregateResult ar : groupedResult){
            productMap.get((String)ar.get('Product2Id')).Quantity_Ordered__c = Integer.valueOf(ar.get('activatedQuantity'));
        }
        
        //ToDo: Perform an update on the records in the productMap
        update productMap.values();
    }

}
 
Getting Query of LOB fields caused heap usage to exceed limit​ in apex trigger in the SOQL Query on Content Version.

List<Id> ListNewRD_KB = new List<ID>(); 

List<ContentVersion> ListContentVersion  = [Select id,VersionData, Title,PathOnClient,R_D_Knowledge_Base__c,ContentBodyId   from ContentVersion  where R_D_Knowledge_Base__c  IN : ListNewRD_KB limit 1] ;

User-added image
I want to create a Cutomer in Quickbooks when any account create in Salesforce without using any third party app.
Is this possible by using API's?
User-added image

Stuck in challenge 2 with the above issue. Below is my code.

orderTrigger  -------- 

/**
 * @name orderTrigger
 * @description
**/
trigger orderTrigger on Order(after update) {
    try{
        if(Trigger.isUpdate && Trigger.New != null){
            OrderHelper.AfterUpdate(Trigger.New,Trigger.old);
        }
    }catch(Exception e){
        System.debug('Exception in trigger -- '+e.getMessage());
    }
}


OrderHelper  --------


public with sharing class OrderHelper {

    /**
     * @name AfterUpdate
     * @description 
     * @param List<Order> newList
     * @param List<Order> oldList
     * @return void
    **/
    public static void AfterUpdate(List<Order> newList, List<Order> oldList){
        Set<Id> orderIds = new Set<Id>();
        for ( Integer i=0; i<newList.size(); i++ ){
            if (newList[i].Status == Constants.ACTIVATED_ORDER_STATUS && oldList[i].Status != Constants.ACTIVATED_ORDER_STATUS){
                orderIds.add(newList[i].Id);
            }
        }
        RollUpOrderItems(orderIds);
    }

    /**
     * @name RollUpOrderItems
     * @description Given a set of Activated Order ids, query the child Order Items and related Products to calculate Inventory levels
     * @param Set<Id> activatedOrderIds
     * @return void
    **/
    public static void RollUpOrderItems(Set<Id> activatedOrderIds){
        //ToDo: Declare a Map named "productMap" of Ids to Product2 records
        Map<Id,Product2> productMap = new Map<Id,Product2>();
        Set<Id> productIds = new Set<Id>();
        
        //ToDo: Loop through a query of OrderItems related to the activatedOrderIds
        for(OrderItem oi : [SELECT Id, Product2Id, Product2.Quantity_Ordered__c, Quantity FROM OrderItem
                            WHERE OrderId IN :activatedOrderIds]){
            productIds.add(oi.Product2Id);                         
        }
        
        //ToDo: Populate the map with the Id of the related Product2 as the key and Product2 record as the value
        productMap = new Map<Id, Product2>([SELECT Id, Quantity_Ordered__c FROM Product2 WHERE Id IN :productIds]);
        
        AggregateResult[] groupedResult = [SELECT Product2Id, SUM(Quantity) activatedQuantity FROM OrderItem
                                             WHERE Product2Id IN :productMap.keySet() GROUP BY Product2Id];
        
        //ToDo: Loop through a query that aggregates the OrderItems related to the Products in the ProductMap keyset
        for(AggregateResult ar : groupedResult){
            productMap.get((String)ar.get('Product2Id')).Quantity_Ordered__c = Integer.valueOf(ar.get('activatedQuantity'));
        }
        
        //ToDo: Perform an update on the records in the productMap
        update productMap.values();
    }

}
 
Hi all,

I have custom save method in my code and two inputfields.
This save functionality is working,but the two inputfields are not getting saved.
I will paste my code here. Please help.Its urgent.

Thanks,
Amita Tatar
class::


public class getLabel{

Proposal_Form__c pfc;
public List<WrapperClass> listWrapper {get;set;}
public Map<String,String> labelMap;
public String resultString {get;set;} 
private ApexPages.StandardController std;

public getLabel(ApexPages.StandardController controller) {
    
    //std = controller;
    pfc = (Proposal_Form__c)controller.getRecord();
    listWrapper = new List<WrapperClass>();
    labelMap = new Map<String,String>();
    labelMap = retLabelMap('ProposalFields__c');
    for(String s : labelMap.values()){
        listWrapper.add(new WrapperClass(s,false));
    }
   
}

public class WrapperClass {  
    public Boolean checkBool {get;set;}
    public String fieldNme{get;set;}  
    public WrapperClass(String prop,Boolean checkBool ){  
        this.fieldNme = prop;  
        this.checkBool = checkBool ;  
    }  
}

public Static Map<String,String> retLabelMap(String type){
    Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe();
    Schema.SObjectType s= m.get(type);
    Map<String, Schema.SObjectField> fieldMap = s.getDescribe().fields.getMap();
    Map<String,String> aMap = new Map<String,String>();
    for (String fieldName: fieldMap.keySet()) {
        aMap.put(fieldName,fieldMap.get(fieldName).getDescribe().getLabel());
    }

    return aMap;
}

public PageReference saveCheckboxValue(){
    List<String> selectedRec = new List<String>();
    if(listWrapper!=null && listWrapper.size()>0){
        for(WrapperClass w : listWrapper){
            if(w.checkBool == true){
              // selectedRec.add(w.fieldNme);
               system.debug('**********'+ selectedRec.add(w.fieldNme));
               resultString = resultString + '  '+ w.fieldNme;
               
        }
       }
    }
     Proposal_Form__c pf = new Proposal_Form__c();
    
     pf.Fields_Associated__c = resultString; 
     insert pf;
   
     PageReference pg = new PageReference('/'+pf.id);
     return pg;
       
     }
 
}


VF



<apex:page showHeader="false" sidebar="false" standardController="Proposal_Form__c" extensions="getLabel">
<apex:form >
<style>
.panelWrapper .mainTitle {
   text-align :center;
    
}
</style>
<apex:outputPanel styleClass="panelWrapper" layout="block">
<apex:pageBlock title="Proposal Form">
<apex:pageBlockSection title="Service Requirements">
<apex:inputField value="{!Proposal_Form__c.Service_Family__c}"/>
<apex:inputField value="{!Proposal_Form__c.Service_Type__c}"/>
<apex:inputField value="{!Proposal_Form__c.Sub_Service_Category__c}"/>

</apex:pageBlockSection>

<apex:pageBlockButtons location="Bottom">
<apex:commandButton value="Save" action="{!saveCheckboxValue}"/>
</apex:pageBlockButtons>

<apex:pageBlockSection title="Available fields">
<apex:repeat var="lab" value="{!listWrapper}">
<apex:pageblockSectionItem >
<apex:outputlabel value="{!lab.fieldNme}"/>
<apex:inputCheckbox value="{!lab.checkBool}"/>
</apex:pageblockSectionItem> 
</apex:repeat>

</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>

</apex:form> 
</apex:page>

 
Hi 

I am trying to write an if statement inside html email template but its not working 
below is th code I tried to use, could anyone help on this

<p>
{!IF(ISCHANGED(TargetX_Eventsb__OrgEvent__c.Name)), 
   Name: TargetX_Eventsb__OrgEvent__c.Name,
   ''
}
{!IF(ISCHANGED(TargetX_Eventsb__OrgEvent__c.TargetX_Eventsb__Description__c)),
    Description: TargetX_Eventsb__OrgEvent__c.TargetX_Eventsb__Description__c,
    ''
}
{!IF(ISCHANGED(TargetX_Eventsb__OrgEvent__c.TargetX_Eventsb__Start_Date_Time__c)),
   Start Date: TargetX_Eventsb__OrgEvent__c.TargetX_Eventsb__Start_Date_Time__c,
  ''
}
{!IF(ISCHANGED(TargetX_Eventsb__OrgEvent__c.TargetX_Eventsb__End_Date_Time__c)),
  End Date: TargetX_Eventsb__OrgEvent__c.TargetX_Eventsb__End_Date_Time__c,
  ''
}
{!IF(ISCHANGED(TargetX_Eventsb__OrgEvent__c.TargetX_Eventsb__Number_Cancelled__c)),
  Cancelled: TargetX_Eventsb__OrgEvent__c.TargetX_Eventsb__Number_Cancelled__c,
  ''
}
</p>
<apex:page controller="OppNameSearchController" >
    <apex:form id="form">
        <apex:pageBlock>
         
              <apex:pageBlockSection title="Search Filter" >
                Opportunity Name: <apex:inputText value="{!Name}"/>
                <apex:commandButton value="Search" action="{!method}" />
            </apex:pageBlockSection>
            <apex:pageMessages ></apex:pageMessages>
            
        </apex:pageBlock>
        <apex:pageblock>
<apex:pageBlockTable value="{!Opp}" var="row" rendered="{!show}">
<apex:column >
<apex:outputLink title="" value="/{!row.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;
</apex:column>

                                                                                                  
               
    <script type="text/javascript">
    function popupwindow()
    {
        var newwindow = window.open('/apex/OppNameSearchController','newwindow','height=400','width=1000','left=100','top=100'); 
       
    }
    </script>     
    <apex:commandButton action="{!edit}" value="edit" onclick="popupwindow()"/>   
            <apex:column value="{!row.Name}"/>
            <apex:column value="{!row.Amount}"/>
            </apex:pageBlockTable>
        </apex:pageblock>
           
</apex:form>
</apex:page>
 
public class OppNameSearchController {
    public list<Opportunity>Opp{set;get;}
    public string Name{set;get;}
    public Decimal amount{set;get;}
    
    public boolean show{set;get;}
    
    public OppNameSearchController()
    {
        Opp = new List<Opportunity>();
        Opp= [select id, Name, Amount from Opportunity];
    }
    public void method()
    {
      
        integer OppCount=[select count() from Opportunity where Name LIKE: Name+'%'];
        if(OppCount != 0)
        {
            Opp = [select  name, Amount from Opportunity where Name LIKE: Name+'%' ];
            show = true;
        }
        else
        {
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO,'There are no Opportunities with the Name -'+Name);
            ApexPages.addMessage(myMsg);
            show = false;
        }
    }
    
    public void save()
    {
        
        update Opp;
     
    }
     public void edit()
 {
     String oppid= ApexPages.currentPage().getParameters().get('oppid'); 
 }
 
     public void clear(){  	
  
        Opp=NULL;
                  
   }  
}

 
I want to create a Cutomer in Quickbooks when any account create in Salesforce without using any third party app.
Is this possible by using API's?