• dharmik thummar
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 7
    Replies
public class AddDuplicateRuleEntryController {

 
    public list<Duplicate_Rule_Entries__c> listDuplicateRule{ get; set; }
    public String selectedVal{get;set;}
    public map <String,fieldwrapper> fieldmap{get;set;}
    public list<selectoption> fieldListOption {get;set;}
    public Duplicate_Rule__c rule{get;set;}
    public string recordid; 
    public string objectName;
    
    
    public AddDuplicateRuleEntryController()
    {
        fieldmap = new map <String,fieldwrapper>();
        rule = new Duplicate_Rule__c ();
        listDuplicateRule = new list<Duplicate_Rule_Entries__c>();
        fieldListOption = new list<selectoption> ();
        
        
        recordid= ApexPages.currentPage().getParameters().get('id');
        rule = [select Active__c, Object__c,Duplicate_Rule_Entry_Criteria__c,Name, On_Insert__c, On_Update__c from Duplicate_Rule__c where id =: recordid ];
		listDuplicateRule = [SELECT Id, IsDeleted, Name, Entry_Number__c, Field_Name__c, Field_API_Name__c, Field_Data_Type__c, Match__c, Duplicate_Rule__c
                              		FROM Duplicate_Rule_Entries__c
            						WHERE Duplicate_Rule__c =: recordid];
        if(listDuplicateRule.size() ==0) {
        	listDuplicateRule.add(new Duplicate_Rule_Entries__c(Duplicate_Rule__c=recordid,Entry_Number__c=1));
    	}
        if(rule != null) {
            objectName = rule.Object__c;    
        }
        fetchObjectField();
        system.debug(fieldmap);
    }
    
    
    
    Public void addDuplicateRuleEntryRow()
    {
        Duplicate_Rule_Entries__c acc = new Duplicate_Rule_Entries__c(Duplicate_Rule__c=recordid);
        acc.Entry_Number__c = listDuplicateRule.size() + 1;
        listDuplicateRule.add(acc);
       
    }
    public PageReference saveRule() {
        system.debug(fieldmap);
        system.debug(listDuplicateRule);
        list<Duplicate_Rule_Entries__c> duplicateRuleEntrylisttoInsert = new list<Duplicate_Rule_Entries__c> ();
        for(Duplicate_Rule_Entries__c  dc : listDuplicateRule)
        {
            system.debug(dc.Field_API_Name__c);
            if(dc.Field_API_Name__c != '----None----') {
                dc.Field_Data_Type__c= fieldmap.get(dc.Field_API_Name__c).DataType;
                dc.Field_Name__c= fieldmap.get(dc.Field_API_Name__c).FieldName; 
                duplicateRuleEntrylisttoInsert.add(dc);
            }            
           
        }
        upsert duplicateRuleEntrylisttoInsert;
        update rule;
        PageReference reRend = new PageReference('/'+recordid);
        reRend.setRedirect(True);
        return reRend;
    }
    public class fieldwrapper {
            public String FieldName {get; set;}
            public string FieldAPI  {get; set;}
            public string DataType  {get; set;}
          
            //This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
            public fieldwrapper(String FieldName, string FieldAPI, string DataType) {
                
                this.FieldName = FieldName;
                this.FieldAPI = FieldAPI;
                this.DataType = DataType;
                
            }
        }
    public void fetchObjectField(){
        try
        {
                fieldListOption.add(new selectoption('----None----','----None----')); 
                if(objectName != null) {
                    for(SObjectField sField: Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap().values()) {
                            DescribeFieldResult res = sField.getDescribe();
                                
                            fieldmap.put(res.getName(),new fieldwrapper(res.getLabel(), res.getName(),res.getType().name()));
                            fieldListOption.add(new selectoption(res.getName(),res.getLabel()));
                            System.debug(fieldmap);
                    }
                }
            
            }
        catch(Exception ex)
        {
            System.debug(ex.getMessage());
            System.debug(ex.getStackTraceString());
        }
       
    }

    public PageReference redirect()
    {
            PageReference reRend = new PageReference('/'+recordid);
            reRend.setRedirect(True);
            return reRend;
    }  
  
}

Visualforce Page:
<apex:page Controller="AddDuplicateRuleEntryController">
    
    <script type="text/javascript">
        window.onload = function(){
            var elems = document.querySelectorAll('[id$="setRequired"]');
            for (var i = 0; i < elems.length; i++){
                //elems[i].required = true;
            }
         function cancelJS () {
         	alert (1);
             cancelAF();
         }   
    }
    </script>
    
    <apex:form >
    <apex:pageMessages />
        <apex:pageBlock >
            
            <apex:pageBlockTable value="{!listDuplicateRule}" var="ldr">
               
                <apex:column headerValue="Field" >
                    
                   <apex:selectList size="1" value="{!ldr.Field_API_Name__c}" id="setRequired" >
                       
                       <apex:selectOptions value="{!fieldListOption}"/>

                    </apex:selectList>
                </apex:column>
                <apex:column headerValue="Match">
                    <apex:selectList required="True" size="1" value="{!ldr.Match__c}" id="setRequiredMatch">
                        <apex:selectOption itemValue="Exact" itemLabel="Exact"></apex:selectOption>
                    </apex:selectList>
                </apex:column>
            </apex:pageBlockTable>
            <apex:outputText value="Duplicate rule Criteria: "/>
            <apex:inputField value="{!rule.Duplicate_Rule_Entry_Criteria__c}"/>
            <apex:pageBlockButtons >
                <apex:commandButton value="Add Rules Row" action="{!addDuplicateRuleEntryRow}"/>
                <apex:commandButton value="Save Rules" action="{!saveRule}" />        
               
                <apex:commandButton value="Cancel" action="{!redirect}" immediate="true" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

if(!mm1.isEmpty()){
                    For(Milestone1_Task__c mm1u: mm1){
                        mm1u.Task_Stage__c = triggerNew[0].Determine_Business_Name__c;
                        if(triggerNew[0].Determine_Business_Name__c == 'Completed'){
                            mm1u.Complete__c = true;
                            mm1u.Complete_Date__c = system.Today();
                        }
                    }
                    mtList.addAll( mm1);
        
                }

 
Hello there;
I want to get download id of record stored in files object with coding. please help me.

thanks.
Hello there,
I want to preview  image record stored in file object. I can access record via Notes & Attachments and preview url available under Notes & Attachments, but I want to access image record stored in files object via files object itself, not using Notes & Attachments. 

Thanks
I want [select id,Amount from Opportunity where Fund__c =: funRec.Id]  outside of for loop.
for(Fund__c funRec : [select id from Fund__c where id in :fundIds])
            {
                oppMap.put(funRec.Id, [select id,Amount from Opportunity where Fund__c =: funRec.Id]);
                fundMap.put(funRec.Id, funRec);
            }

 
There is two object: Fund and opportunity. and opportunity object has lookup of Fund. I've devloped one trigger that sum up the total amount from all the relative opportunity and set that amount in custom field of fund object. now problem in my code is that whenever I try to create bulk opportunity using CSV file that contain data for multiple fund at that time it sum up the total of all fund and set that only in first record fund ID. I need solution using Map.
Thannk you.

Trigger:
trigger newLeadTrigger on Opportunity (after insert , after update, after delete , after undelete) {
    
    if(trigger.isAfter && (trigger.isInsert || trigger.isUpdate || trigger.isUndelete)){
           OpportunityCustomRollup.CountRollup(Trigger.new);
    }
    
    if(Trigger.isDelete)
    {
        OpportunityCustomRollup.CountRollup(Trigger.old);
    }
}


Controller class:

public class OpportunityCustomRollup {
   
    public static void CountRollup(List<Opportunity> lstOpportunity){
        
        set<id> oppIds = new set<id>();
        map<string, integer> classroomIDToDeskCountMap = new map<string, integer>();
        id objrecordtypeid = [SELECT Id FROM RecordType WHERE DeveloperName ='Fund_Raising'].Id;
        double amount = 0;
        
        try {
                for (Opportunity objOpportunity : lstOpportunity){
                    oppIds.add(objOpportunity.Fund__c);
                }
            
                Fund__c objfund = [SELECT Id, Total_opportunity_amount__c  FROM Fund__c WHERE Id = :oppIds];
                List<Opportunity> list_Opportunity = [SELECT Id, Amount FROM Opportunity WHERE Fund__c = :objfund.Id and StageName = 'Closed Won' and RecordTypeId =: objrecordtypeid];
            
            
                 for(Opportunity AmountOpportunity : list_Opportunity) {
                        amount += AmountOpportunity.amount; 
                 }
            
            
                  objfund.Total_opportunity_amount__c = amount;
                  update objfund;   
            } 
       
        
        catch (Exception e) {
                System.debug(e);
            }
        
    }

}
  
list<contact> clst = new list<contact>();
for(contact con : [Select id, otherphone from contact]) {
    con.otherphone = '768906543333';
    clst.add(con);
}
update clst;

Getting SOQL 101 Error Can Any one Correct Me. I am run this code in developer console
  • March 08, 2018
  • Like
  • 0
I want [select id,Amount from Opportunity where Fund__c =: funRec.Id]  outside of for loop.
for(Fund__c funRec : [select id from Fund__c where id in :fundIds])
            {
                oppMap.put(funRec.Id, [select id,Amount from Opportunity where Fund__c =: funRec.Id]);
                fundMap.put(funRec.Id, funRec);
            }

 
There is two object: Fund and opportunity. and opportunity object has lookup of Fund. I've devloped one trigger that sum up the total amount from all the relative opportunity and set that amount in custom field of fund object. now problem in my code is that whenever I try to create bulk opportunity using CSV file that contain data for multiple fund at that time it sum up the total of all fund and set that only in first record fund ID. I need solution using Map.
Thannk you.

Trigger:
trigger newLeadTrigger on Opportunity (after insert , after update, after delete , after undelete) {
    
    if(trigger.isAfter && (trigger.isInsert || trigger.isUpdate || trigger.isUndelete)){
           OpportunityCustomRollup.CountRollup(Trigger.new);
    }
    
    if(Trigger.isDelete)
    {
        OpportunityCustomRollup.CountRollup(Trigger.old);
    }
}


Controller class:

public class OpportunityCustomRollup {
   
    public static void CountRollup(List<Opportunity> lstOpportunity){
        
        set<id> oppIds = new set<id>();
        map<string, integer> classroomIDToDeskCountMap = new map<string, integer>();
        id objrecordtypeid = [SELECT Id FROM RecordType WHERE DeveloperName ='Fund_Raising'].Id;
        double amount = 0;
        
        try {
                for (Opportunity objOpportunity : lstOpportunity){
                    oppIds.add(objOpportunity.Fund__c);
                }
            
                Fund__c objfund = [SELECT Id, Total_opportunity_amount__c  FROM Fund__c WHERE Id = :oppIds];
                List<Opportunity> list_Opportunity = [SELECT Id, Amount FROM Opportunity WHERE Fund__c = :objfund.Id and StageName = 'Closed Won' and RecordTypeId =: objrecordtypeid];
            
            
                 for(Opportunity AmountOpportunity : list_Opportunity) {
                        amount += AmountOpportunity.amount; 
                 }
            
            
                  objfund.Total_opportunity_amount__c = amount;
                  update objfund;   
            } 
       
        
        catch (Exception e) {
                System.debug(e);
            }
        
    }

}
  
hi all,

I urgently need to edit/delete a post made by me on this discussion forum...But its not allowing me to do so and pops up
saying that 'you cant delete this question as others are interested in it'.
There are no likes and no comments on it still i am unable  to delete it
Any help would be highly appreciated

Its very urgent,
Thanks,

Hi,

 

I want to create a rollup field in Account Object with Opportunity Amount. Can any one help me on this, Actually i'm new in  trigger.