• shambavi
  • NEWBIE
  • 40 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 5
    Replies
public with sharing class APTS_UOMConversionTriggerHandler implements ITriggerHandler {
  public static Boolean isTriggerDisabled = true;
  public class ApplicationException extends Exception {}
  
  public Boolean isDisabled(){
     try{
         Boolean disabled=false;
         if (TriggerSettings__c.getInstance().UOMConversionTrigger__c) {
           disabled=false;
         } 
         else {
           disabled=isTriggerDisabled;
         }
       return disabled;
     }catch(Exception e) {throw new ApplicationException(e);}
    }
  
    public void beforeInsert(List<SObject> newUOMConversionList){
      /
    } 
 
    public void beforeUpdate(List<SObject> newUOMConversionList, Map<Id, SObject> newUOMConversionMap, List<SObject> oldUOMConversionList, Map<Id, SObject> oldUOMConversionMap){
      
    }
    
    public void beforeDelete(List<SObject> oldUOMConversionList, Map<Id, SObject> oldUOMConversionMap){
      
    }
 
    public void afterInsert(List<SObject> newUOMConversionList, Map<Id, SObject> newUOMConversionMap){
      //Logic to check if the product is active and it is newly inserted.If so will trigger digital pricing
      try{
        onAfterInsertUOMConversion((List<APTS_UOM_Conversion__c>)newUOMConversionList);  
      }catch(DmlException e) {throw new ApplicationException(e);}

    }
  
    public void afterUpdate(List<SObject> newUOMConversionList , Map<Id, SObject> newUOMConversionMap, List<SObject> oldUOMConversionList, Map<Id, SObject> oldUOMConversionMap){
       //Logic to check if the product's isactive field has changed.If so will trigger digital pricing
      try{
        onAfterUpdateUOMConversion((Map<Id, APTS_UOM_Conversion__c>)newUOMConversionMap,(Map<Id, APTS_UOM_Conversion__c>)oldUOMConversionMap);
      }catch(DmlException e) {throw new ApplicationException(e);}
    }
    
    public void afterDelete(List<SObject> oldUOMConversionList, Map<Id, SObject> oldUOMConversionMap){
     
    }
  
    public void afterUndelete(List<SObject> newUOMConversionList, Map<Id, SObject> newUOMConversionMap){
      
    }
    
     public static void onAfterInsertUOMConversion(List<APTS_UOM_Conversion__c> newUOMConversionList){
        try{
         Set<Id> uOMConversionIdsToBeSentToSAPPO=  new Set<Id>();
           for(APTS_UOM_Conversion__c prodTrans:newUOMConversionList){
               if(prodTrans.APTS_Product_Active__c){
                  uOMConversionIdsToBeSentToSAPPO.add(prodTrans.APTS_Product__c);   
               }    
           }
           
           if(!uOMConversionIdsToBeSentToSAPPO.isEmpty()){
             APTS_IntegrationLogHandlerUtility.createIntegrationLogs(uOMConversionIdsToBeSentToSAPPO);      
           }
         }catch(Exception e) {throw new ApplicationException(e);}
     }
   
    public static void onAfterUpdateUOMConversion(Map<Id, APTS_UOM_Conversion__c> newUOMConversionMap,Map<Id, APTS_UOM_Conversion__c> oldUOMConversionMap){
        try{
    Set<Id> uOMConversionIdsToBeSentToSAPPO=new Set<Id>();
        List<Schema.FieldSetMember> relatedFieldSet=new List<Schema.FieldSetMember>();
        relatedFieldSet=APTS_IntegrationLogHandlerUtility.readFieldSet('APTS_UOMFieldsForDigitalProdIntegration','APTS_UOM_Conversion__c');    
        //List<Product2> productsToBeSentToSAPPO=  new List<Product2>();
           for(Id prodId:newUOMConversionMap.keySet()){
               if(newUOMConversionMap.get(prodId).APTS_Product_Active__c && 
                   APTS_IntegrationLogHandlerUtility.checkIfValidToSend(newUOMConversionMap.get(prodId),oldUOMConversionMap.get(prodId),relatedFieldSet)){
                      uOMConversionIdsToBeSentToSAPPO.add(newUOMConversionMap.get(prodId).APTS_Product__c);   
               }    
           }
           
           if(!uOMConversionIdsToBeSentToSAPPO.isEmpty()){
             APTS_IntegrationLogHandlerUtility.checkAndCreateIntegrationLogs(uOMConversionIdsToBeSentToSAPPO);      
           }
        }catch(Exception e) {throw new ApplicationException(e);}
     }
}
Thanks
 
Hi Guys,
 i have one agreement objcet , in this object some records will be there, in these records i want to select one primary record...
please help on this.. below is my code ..
<apex:page standardController="Apttus__APTS_Agreement__c" extensions="OnLoadController">
<apex:form >

        <apex:outputText value="{!Apttus__APTS_Agreement__c.Name}" rendered="false"/>
        <apex:outputText value="{!Apttus__APTS_Agreement__c.Apttus__Account__c}" rendered="false"/>
      
        <apex:outputText value="{!Apttus__APTS_Agreement__c.APTS_Primary__c}" rendered="false"/>

 <apex:commandButton id="btnOnLoad" action="{!onLoad}" value="On Load" style="display: none" />
        
        <script>
            var btnOnLoad = document.getElementById("{!$Component.btnOnLoad}");
        </script>
        
        <apex:pageBlock mode="edit" rendered="{!hasErrors}" >
            <apex:pageMessages />
            <apex:pageBlockButtons location="bottom" >
                    <apex:commandButton action="{!doMakePrimary}" value="Make Primary"/>  
                <apex:commandButton action="{!doCancel}" value="{!$Label.apttus__apts_agreement__cancel}" immediate="true"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
    
    <script>
        // register to invoke the function after the page load
        var hasErrors = "{!hasErrors}";
        if (hasErrors.toLowerCase() == 'false') {
            window.onload = function() { 
                // on load
                btnOnLoad.click();
            };
        }
    </script>
    
</apex:page>

and Controller code...
 
public class OnLoadController {

    public Apttus__APTS_Agreement__c agreement { get; set; }

    public OnLoadController(ApexPages.StandardController stdController){
        this.agreement = (Apttus__APTS_Agreement__c)stdController.getRecord();
    }
    
    public void doMakePrimary(){
        Apttus__APTS_Agreement__c agreementRec = [SELECT ID, APTS_Primary__c, Apttus__Related_Opportunity__c FROM Apttus__APTS_Agreement__c WHERE ID =: agreement.Id];
        //add If condition to check other agreement records
        agreementRec.APTS_Primary__c = TRUE;
        insert agreementRec;
    }
    
    public PageReference doCancel() {
        PageReference agreementPage = new PageReference('/' + agreement.id);
        return agreementPage;
    }
    
    public String hasErrors { get; set; }

    public PageReference onLoad() {
             update agreement;
        return null;
    }


}

Thanks In Advance... 
<apex:page standardController="Apttus__APTS_Agreement__c" 
           extensions="APTS_Agreement.AgreementMakePrimaryController" >
    
    <apex:form >
    
        <!--  required fields -->
        <apex:outputText value="{!Apttus__APTS_Agreement__c.Name}" rendered="false"/>
        <apex:outputText value="{!Apttus__APTS_Agreement__c.APTS_Primary__c}" rendered="false"/>
        
        <!--  hidden action buttons -->
        <apex:commandButton id="btnOnLoad" action="{!onLoad}" value="On Load" style="display: none" />
        
        <script>
            var btnOnLoad = document.getElementById("{!$Component.btnOnLoad}");
        </script>
        
        <apex:pageBlock mode="edit" rendered="{!hasErrors}" >
            <apex:pageMessages />
            <apex:pageBlockButtons location="bottom" >
                <apex:commandButton action="{!doCancel}" value="{!$Label.aApttus__APTS_Agreement__cancel}" immediate="true"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
    
    <script>
        // register to invoke the function after the page load
        var hasErrors = "{!hasErrors}";
        if (hasErrors.toLowerCase() == 'false') {
            window.onload = function() { 
                // on load
                btnOnLoad.click();
            };
        }
    </script>
    
</apex:page>
please write controller for vf page...

Thanks in Advance 
please 
global class CreatedAccounts
{
  @InvocableMethod
  global static void CreatedAccount(List<ClsCheckMDM> checkList)
  {
    Id uId = userinfo.getUserId();
    List<Account> updateList = new List<Account> ();
    User partnerCreatedUser = [SELECT Id FROM User WHERE Name = 'Partner Created Account' LIMIT 1];
    User userRec = [SELECT Id, ABB_Manager__c from user where id = :uId LIMIT 1];
    List<Id> accountIds = new List<Id> ();

    for (ClsCheckMDM check : checkList)
    {
      accountIds.add(check.accountId);
    }

    Map<Id, Account> accountMap = new Map<Id, Account> ([SELECT Id, OwnerId FROM Account WHERE Id IN :accountIds LIMIT 100]);
    Map<Id, List<Account_team__c>> accountTeamMap = new Map<Id, List<Account_team__c>> ();

    for(Account_team__c accountTeam : [SELECT Id, Account__c, Account_Access__c, User__c FROM Account_team__c WHERE Account__c IN :accountMap.keySet()])
    {
      if(accountTeamMap.containsKey(accountTeam.Account__c))
      {
        accountTeamMap.get(accountTeam.Account__c).add(accountTeam);
      }
      else
      {
        accountTeamMap.put(accountTeam.Account__c, new List<Account_team__c> { accountTeam });
      }
    }

    List<AccountShare> accountShareRecord = new List<AccountShare> ();
    for (ClsCheckMDM check : checkList)
    {

      if (accountMap.containsKey(check.accountId))
      {
        Account acc = accountMap.get(check.accountId);
        if (!check.isMDM)
        {

          if (accountTeamMap.containsKey(acc.Id))
          {
            for (Account_team__c accountTeam : accountTeamMap.get(acc.Id))
            {
              accountShareRecord.add(new AccountShare
              (
               AccountId = accountTeam.Account__c,
               UserOrGroupId = accountTeam.User__c,
               AccountAccessLevel = (accountTeam.Account_Access__c == 'Read/Write') ? 'Edit' : 'Read',
               OpportunityAccessLevel = 'Read',
               RowCause = 'Manual'
              ));

            }
          }

          acc.OwnerId = partnerCreatedUser.Id;

        }
        else
        {
          acc.OwnerId = userRec.ABB_Manager__c;
        }
        updateList.add(acc);
      }
    }
    try
    {
      update updateList;
      if (!accountShareRecord.isEmpty())
      {
        insert accountShareRecord;
      }
    }
    catch(Exception ex)
    {
      System.debug(logginglevel.ERROR, ex.getMessage());
    }
  }

  global class ClsCheckMDM
  {
    @InvocableVariable
    global Id accountId;

    @InvocableVariable
    global Boolean isMDM;
  }

}

 
Please create a Custom List View Button "New Case" that will pre-populate the Contact, Account, Email, based on the current logged in User if the User is external (community profile) and use the standard functionality if he is not
The contact field should be updated with $User.ContactID if the Record Type is Case from Communities


Thanks in Advance.......


Thanks & Regards
Gopal.