• Alex Sherwood 1
  • NEWBIE
  • 25 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 35
    Replies
I've downloaded an unmanaged package - Convert Lead - Custom Lead Conversion Process (https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000B4sHpEAJ) from the AppExchange which provides a template for a Lead Convert Visualforce page. I now want to add my field Annual_Settlement_Value__c to the page - it looks like I need to modify the leadConvertCoreComponent in order to do this.

But I can't find any documentation which includes sample code that resembles the code that's already in this component so I can't see where to add the field and how to format the code. If anyone could provide an example, it would be much appreciated.
<!-- This is our page component tag -->
<!-- We are using the Standard Controller for Lead and a Controller Extension called 'leadConvertController' -->

<apex:page standardController="Lead" extensions="leadConvertController">

<!-- Page section header -->

<apex:sectionHeader title="Convert Lead" subtitle="{!Lead.name}"/>

<!-- Visualforce Component with custom page header text -->

<c:leadConvertPageHeaderTextComponent />

<!-- This form tag must include any fields or buttons used in the Lead Convert operation -->
 
<apex:form id="theForm" >

    <!-- This pageBlock component is a container that includes the visual elements of the Lead Convert page -->
    <!-- All custom Components should be included within this pageBlock unless you are using more advanced custom styling -->

    <apex:pageBlock mode="edit" id="pageBlock">
   
        <!-- This component is used to display error messages on the page -->
           
        <apex:pageMessages />
           
        <!-- This pageBlockButtons component is where you can add / remove custom buttons from the Lead Convert page -->
   
        <apex:pageBlockButtons >
       
            <apex:commandButton action="{!convertLead}" value="Convert"/>
            <apex:commandButton action="{!cancel}" value="Cancel"/>
               
        </apex:pageBlockButtons>           
       
        <!-- This custom component contains the section & fields specific to converting a Lead to an Account, Contact, and Opportunity -->
          
        <c:leadConvertCoreComponent id="leadComp" thepageController="{!this}" LeadToConvert="{!leadToConvert}" rendered="True" />

        <!-- This custom component contains the section & fields specific to creating a new Task on Lead Convert -->
        <!-- If you would like to hide this section, set the rendered attribute to 'False' -->
           
        <c:leadConvertTaskInfoComponent thepageController="{!this}" rendered="true" />

        <!-- This custom component contains the section & Description field specific to the new Task on Lead Convert -->
        <!-- If you would like to hide this section, set the rendered attribute to 'False' -->
                
        <c:leadConvertTaskDescriptionComponent thepageController="{!this}" rendered="true" />

    <!-- This is the closing tag for the pageBlock component -->
    
    </apex:pageBlock>
       
<!-- This is the closing tag for the form -->

</apex:form>
   
<!-- This is the closing tag for the page -->
    
</apex:page>
<!-- This component allows for the core lead converting functionality -->

<apex:component controller="leadConvertCoreComponentController">
    <!-- This allows for the lookup to Account but hides the text of the selected account name leaving the magnifying glass only -->
    <style type="text/css">
        input.hiddenInput {
            width:0;
            height:0;
            border:0;
            padding:0;
            margin:0;
        }
    </style>

    <!-- This is the attribute that holds the lead to convert -->
    <apex:attribute name="LeadToConvert" 
        description="The lead to convert"
        type="Lead" 
        assignTo="{!leadConvert}"
        required="true"/>

    <!-- This attribute is used for the leadConvertController to interact with this component's controller -->
    <apex:attribute name="thepageController"
      type="PageControllerBase"
      assignTo="{!pageController}"
      required="true"
      description="The controller for the page." />
    
    <!-- Lead Convert section -->    
    <apex:pageBlockSection id="pblockconvertLead" title="Convert Lead" collapsible="no" columns="1">
    
        <!-- Leads Record Owner -->
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Record Owner" for="recordOwner" />
            <apex:inputField value="{!contactId.ownerID}" id="recordOwner" />
        </apex:pageBlockSectionItem>
        
        <!-- Checkbox indicating whether to send an email to the owner -->    
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Send Email to the Owner" for="sendOwnerEmail" />
            <apex:inputCheckbox value="{!sendOwnerEmail}" id="sendOwnerEmail" />
        </apex:pageBlockSectionItem>
        
             
        <apex:pageBlockSectionItem id="convertLeadAccountBlockSectionItem" >
            
            <!-- Account Name picklist  -->
            <apex:outputLabel value="Account Name" for="accountList" />
            <apex:outputPanel styleClass="requiredInput" id="block">
                <div class="requiredBlock"></div>
                <apex:selectList value="{!selectedAccount}" size="1" 
                    multiselect="false" id="accountList">
                    
                    <apex:actionSupport event="onchange" 
                        action="{!accountChanged}" 
                        rerender="opportunityName, ViewLink"
                         />     
                    <apex:selectOptions value="{!accounts}"/>
                    
                </apex:selectList>
                
                <!--  Account lookup to add existing accounts to the picklist -->
                <apex:inputField styleClass="hiddenInput" 
                value="{!contactId.AccountId}" id="accountId" >
                    
                    <!-- When an account is looked up, it is added to the select list -->                            
                    <apex:actionSupport event="onchange" 
                        action="{!accountLookedUp}" 
                        rerender="accountList, opportunityName, ViewLink"
                         />
                        
                </apex:inputField>
                
                <!-- This is a link which shows a view of the selected account in a new pop up window -->                
                <apex:commandLink id="ViewLink"  value="View"
                    onclick="javascript:if ('{!selectedAccount}' != 'NEW' && '{!selectedAccount}' != 'NONE' ) {var newWindow = window.open('/{!selectedAccount}/p', 'accountview', 'top=40, left=40,scrollbars=yes, height=450, width=800');newwindow.focus();} else {alert('You can only view existing accounts.');}"
                />
                
            </apex:outputPanel>
        </apex:pageBlockSectionItem>
        
        <!-- Opportunity section -->
        <apex:pageBlockSectionItem id="oppSection" >
            
            <apex:outputPanel id="oppPanel" >
                <apex:outputLabel value="Opportunity Name" for="opportunityName" />
            </apex:outputPanel>
            
            
            <apex:outputPanel id="opportunityPanel" layout="block">
                <apex:outputPanel rendered="{!NOT(doNotCreateOppty)}" styleClass="requiredInput" id="block">
                <div class="requiredBlock"></div>
                
                <!-- Opportunity Name -->
                <apex:inputField required="false" 
                    value="{!opportunityID.Name}" id="opportunityName"/>
                </apex:outputPanel>
                
                <!--  This is only shown if the Do Not Create Opportunity is true -->    
                <apex:inputText disabled="true" rendered="{!doNotCreateOppty}"  value="{!opportunityID.Name}" id="opportunityNameDisabled"/>
                <apex:outputPanel layout="block" styleClass="requiredInput">
                <apex:outputPanel layout="block" />
                
                <!-- Checkbox indicating whether to create an Opportunity -->
                <apex:inputCheckbox value="{!doNotCreateOppty}" id="doNotCreateOppty">
                    <apex:actionSupport event="onchange" 
                        
                        rerender="opportunityPanel"
                         />
                </apex:inputCheckbox>
                Do not create a new opportunity upon conversion.
            </apex:outputPanel> 
            </apex:outputPanel>
        </apex:pageBlockSectionItem>
        
        <!-- Converted Status -->
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Converted Status" for="leadStatus" />
            <apex:outputPanel styleClass="requiredInput" layout="block">
                <div class="requiredBlock"></div>
                <apex:selectList id="LeadStatusList" size="1" 
                    value="{!LeadToConvert.Status}" multiselect="false" required="true">
                    <apex:selectOptions value="{!LeadStatusOption}"/>
                </apex:selectList> 
            </apex:outputPanel>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
    
</apex:component>


 
Has anyone worked out how to set the extension of their files for GitHub Gists so that their code is rendered as Apex?

I've tried .tgr, .cls, .apex & .apx but not of those extensions are recognised by the rendering feature.

I know that Apex wasn't one of the formats that could be selected and saved for a Gist but it was an option that could be selected while editing.

So I don't know whether an extension is even supported but thought I'd ask..
I've written the following code which checks the record ID of the opportunity that's the target of the trigger against a list of IDs which are stored in a custom setting. The idea is that rather than hard coding the record IDs, I'll only need to maintain the list of IDs in the custom setting and reference that, for all of my code.
 
trigger FSRUpdate2 on Opportunity (before insert, before update) {

            
    Set<Id> recordTypesIds = new Set<Id>();
    Map<String, WEID__c> allOpps = WEID__c.getAll();

    for (Opportunity opp : Trigger.new){
        
        if (recordTypesIds.contains(opp.RecordTypeId)) {
            if(opp.Annual_Settlement_Value__c > 0 && opp.Interchange_Rate_Revenue_as_a_percentag__c > 0)
            {
                Decimal fsr = opp.Annual_Settlement_Value__c * opp.Interchange_Rate_Revenue_as_a_percentag__c;
            
                opp.FSR_Estimate_on_Contract_Signature__c = fsr;
                
            } else {
                opp.Annual_Settlement_Value__c = null;
                opp.FSR_Estimate_on_Contract_Signature__c = null;
            
            insert opp;
            }
        }
    }
}



I don't have any code coverage for lines 9 and beyond so I'm assuming that the test class is not finding the matching ID in my custom setting (it's definitely there), even though line 10 has code coverage because I've tested when the values required for the calculation are available and when they aren't.
 
@isTest
public class CP_FSRUpdate2Test {
    
    static testMethod void testFSR(){
        
        Opportunity opp = new Opportunity();
        opp.name = 'Test Opp';
        opp.RecordTypeId = '012700000005qig';
        opp.StageName = '1) Suspect';
        opp.CloseDate = date.newInstance(2045, 01, 01);

        
        //cover Credit Agreement Details Required validation rule
        opp.Credit_Limit__c = 100.00;
        opp.Date_Credit_Limit_Approved__c = date.newInstance(1901, 01, 01);
        opp.Payment_Terms_Days__c = 5;
        opp.Billing_Cycle__c = 'Daily';
        
        //cover Revenue Values Required validation rule (and provide values required for calculation)
        opp.Annual_Settlement_Value__c = 100.00;
        opp.Average_transaction_Value_POS__c = 1.00;
        
        opp.Interchange_Rate_Revenue_as_a_percentag__c = 0.1;
        
        insert opp;
        
        
        //Check Record Type
        Opportunity usOpp = new Opportunity();
        
        usOpp.RecordTypeId = '012700000005r08';
        
        usOpp.name = 'US Opp';
        //usOpp.campaign = 'Online Application Form';
        usOpp.StageName = '1) Suspect';
        usOpp.CloseDate = date.newInstance(2045, 01, 01);
        usOpp.Credit_Limit__c = 100;
        usOpp.Date_Credit_Limit_Approved__c = date.newInstance(1901, 01, 01);
        usOpp.Payment_Terms_Days__c = 5;
        usOpp.Billing_Cycle__c = 'Daily';
        usOpp.Annual_Settlement_Value__c = 1000000.00;
        usOpp.Average_transaction_Value_POS__c = 100.00;
        usOpp.Interchange_Rate_Revenue_as_a_percentag__c = 0.1;
        try{
            insert usOpp;
        } catch (Exception a) {
            System.debug('Wrong record type caused trigger to fail');
        }

        //Check no interchange rate
        Opportunity noIntOpp = new Opportunity();  
        
        noIntOpp.name = 'No Interchange Opp';
        noIntOpp.RecordTypeId = '012700000005qig';
        noIntopp.StageName = '1) Suspect';
        noIntopp.CloseDate = date.newInstance(2045, 01, 01);      
        //noIntOpp.campaign = 'Online Application Form';
        noIntOpp.Credit_Limit__c = 100.00;
        noIntOpp.Date_Credit_Limit_Approved__c = date.newInstance(1901, 01, 01);
        noIntOpp.Payment_Terms_Days__c = 5;
        noIntOpp.Billing_Cycle__c = 'Daily';
        noIntOpp.Average_transaction_Value_POS__c = 100;
        noIntOpp.Annual_Settlement_Value__c = 0;
        noIntOpp.Interchange_Rate_Revenue_as_a_percentag__c = 0;
        
        system.AssertEquals(noIntOpp.FSR_Estimate_on_Contract_Signature__c,null);
        
        try{
            insert noIntOpp;
        } catch (Exception b) {
            System.debug('No interchange % caused trigger to fail');
        }
    }

}



I can't find any examples of a list custom setting being used to store IDs (as opposed to a hierachy), can this be done and if so have I referenced the right objects in my Set / Map - I don't get an error if I change Id to String?
I can't find any resources which explain how to format a percentage in an apex class.

I'm writing a test class and need to assign a value to a field.
 
opp.Interchange_Rate_Revenue_as_a_percentag__c = 0.1;


Gives me "System.NullPointerException: Attempt to de-reference a null object".
I'm completely new to coding and this is the second piece that I've written.
 
trigger FSRUpdate2 on Opportunity (before insert, before update) {
   
    FOR (Opportunity opportunityInLoop : Trigger.new){
        
        if(opportunityInLoop.Annual_Settlement_Value__c > 0 && opportunityInLoop.Interchange_Rate_Revenue_as_a_percentag__c > 0)
        {
            Function CalculateAmount()
            {
                Decimal Settlement = Annual_Settlement_Value__c;
                Decimal interchangeRate = Interchange_Rate_Revenue_as_a_percentag__c;
            
                Decimal FSR = Settlement * interchangeRate;
            
                opportunityInLoop.FSR_Estimate_on_Contract_Signature__c = FSR;
            }
        } else {
            opportunityInLoop.Annual_Settlement_Value__c = null;
            opportunityInLoop.Interchange_Rate_Revenue_as_a_percentag__c = null;
        }
    }
    Update opportunityInLoop;
}



I thought it was going ok, having found the CalculateAmount() function in another post, until I realised that it's not appearing in any other samples of code when I google it. When I search multiply and apex, every result is referring to dates, am I trying to do something that shouldn't be done with apex code?

I also need to check the Id of the opportunity that's the target of this trigger against the following list of Record Type Ids:
 
    ('012700000005qie');
    ('012700000005qif');
    ('012700000005qig');
    ('012700000005qia');
    ('012700000005r08');
    ('012700000005qzy');
    ('012700000005r0D');
    ('012700000005qib');
    ('012700000005qic');
    ('012700000005rA9');
    ('012700000005rAA');
    ('012700000005rAB');
    ('012700000005qzo');
    ('012700000005rAC');
    ('012700000005r0I');
    ('012700000005r0N');
    ('012700000005qzt');
    ('012700000005qid');

And if there's no match, stop the trigger from running. But I'm not sure how that list should be structured or which function to use to compare it's contents with the Id of the target opportuntiy.

What I'm trying to do here is replicate a workflow rule which calculates the FSR figure for an opportunity: settlement (currency) x interchange (percentage). The reason why I'm using Apex for this is that 2 field updates need to take place at the same time when an opportunity is created and they're firing in the wrong sequence. Since the other field update populates the % interchange figure, I end up with a 0 for the FSR figure every time. I'm also not sure whether my trigger should fire before or after insert & update so that it fires after the field update?

As you can probably tell I'm slightly lost here so any suggestions would be much appreciated!
I'm completely new to Apex (or coding of any kind) and have been trying to figure out how to write a trigger to update the priority of certain tasks for the past couple of days but I don't think I've come close.

The problem that I have is that I can't find a basic enough example of a trigger, which only performs the one action and isn't referening another object, to use as a template.

Ideally I'd like the trigger to just update the task, without referencing accounts or opportunities etc. so that I can adapt it to update any field on any object.

The task will be triggered using the new process builder feature. The new priority should be high. If it is necessary to reference another object, then these tasks will be related to opportunities.

I have written the rest of the trigger but it's just fragments of code pulled from various sources and probably makes no sense. The part that I'm really struggling with is selecting the list of selected records from my SOQL query so that I can update them.
 
trigger TaskPriorityUpdate on Task (before update) {
    
    for (Task myTasks : Trigger.new)  {
        
        List<Task> tasksToUpdate = [SELECT Priority FROM Task WHERE RecordTypeId = '012700000005ofQ' AND Status != 'Completed' AND Activity_Type__c = 'Administration' AND Subject = 'Opportunity Close Date Check'];
             
        if (tasksToUpdate.size() > 0) {
                 
            update tasksToUpdate.Priority__c = 'High';
             }
    }
}

I'd really appreciate any guidance!
I've downloaded an unmanaged package - Convert Lead - Custom Lead Conversion Process (https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000B4sHpEAJ) from the AppExchange which provides a template for a Lead Convert Visualforce page. I now want to add my field Annual_Settlement_Value__c to the page - it looks like I need to modify the leadConvertCoreComponent in order to do this.

But I can't find any documentation which includes sample code that resembles the code that's already in this component so I can't see where to add the field and how to format the code. If anyone could provide an example, it would be much appreciated.
<!-- This is our page component tag -->
<!-- We are using the Standard Controller for Lead and a Controller Extension called 'leadConvertController' -->

<apex:page standardController="Lead" extensions="leadConvertController">

<!-- Page section header -->

<apex:sectionHeader title="Convert Lead" subtitle="{!Lead.name}"/>

<!-- Visualforce Component with custom page header text -->

<c:leadConvertPageHeaderTextComponent />

<!-- This form tag must include any fields or buttons used in the Lead Convert operation -->
 
<apex:form id="theForm" >

    <!-- This pageBlock component is a container that includes the visual elements of the Lead Convert page -->
    <!-- All custom Components should be included within this pageBlock unless you are using more advanced custom styling -->

    <apex:pageBlock mode="edit" id="pageBlock">
   
        <!-- This component is used to display error messages on the page -->
           
        <apex:pageMessages />
           
        <!-- This pageBlockButtons component is where you can add / remove custom buttons from the Lead Convert page -->
   
        <apex:pageBlockButtons >
       
            <apex:commandButton action="{!convertLead}" value="Convert"/>
            <apex:commandButton action="{!cancel}" value="Cancel"/>
               
        </apex:pageBlockButtons>           
       
        <!-- This custom component contains the section & fields specific to converting a Lead to an Account, Contact, and Opportunity -->
          
        <c:leadConvertCoreComponent id="leadComp" thepageController="{!this}" LeadToConvert="{!leadToConvert}" rendered="True" />

        <!-- This custom component contains the section & fields specific to creating a new Task on Lead Convert -->
        <!-- If you would like to hide this section, set the rendered attribute to 'False' -->
           
        <c:leadConvertTaskInfoComponent thepageController="{!this}" rendered="true" />

        <!-- This custom component contains the section & Description field specific to the new Task on Lead Convert -->
        <!-- If you would like to hide this section, set the rendered attribute to 'False' -->
                
        <c:leadConvertTaskDescriptionComponent thepageController="{!this}" rendered="true" />

    <!-- This is the closing tag for the pageBlock component -->
    
    </apex:pageBlock>
       
<!-- This is the closing tag for the form -->

</apex:form>
   
<!-- This is the closing tag for the page -->
    
</apex:page>
<!-- This component allows for the core lead converting functionality -->

<apex:component controller="leadConvertCoreComponentController">
    <!-- This allows for the lookup to Account but hides the text of the selected account name leaving the magnifying glass only -->
    <style type="text/css">
        input.hiddenInput {
            width:0;
            height:0;
            border:0;
            padding:0;
            margin:0;
        }
    </style>

    <!-- This is the attribute that holds the lead to convert -->
    <apex:attribute name="LeadToConvert" 
        description="The lead to convert"
        type="Lead" 
        assignTo="{!leadConvert}"
        required="true"/>

    <!-- This attribute is used for the leadConvertController to interact with this component's controller -->
    <apex:attribute name="thepageController"
      type="PageControllerBase"
      assignTo="{!pageController}"
      required="true"
      description="The controller for the page." />
    
    <!-- Lead Convert section -->    
    <apex:pageBlockSection id="pblockconvertLead" title="Convert Lead" collapsible="no" columns="1">
    
        <!-- Leads Record Owner -->
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Record Owner" for="recordOwner" />
            <apex:inputField value="{!contactId.ownerID}" id="recordOwner" />
        </apex:pageBlockSectionItem>
        
        <!-- Checkbox indicating whether to send an email to the owner -->    
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Send Email to the Owner" for="sendOwnerEmail" />
            <apex:inputCheckbox value="{!sendOwnerEmail}" id="sendOwnerEmail" />
        </apex:pageBlockSectionItem>
        
             
        <apex:pageBlockSectionItem id="convertLeadAccountBlockSectionItem" >
            
            <!-- Account Name picklist  -->
            <apex:outputLabel value="Account Name" for="accountList" />
            <apex:outputPanel styleClass="requiredInput" id="block">
                <div class="requiredBlock"></div>
                <apex:selectList value="{!selectedAccount}" size="1" 
                    multiselect="false" id="accountList">
                    
                    <apex:actionSupport event="onchange" 
                        action="{!accountChanged}" 
                        rerender="opportunityName, ViewLink"
                         />     
                    <apex:selectOptions value="{!accounts}"/>
                    
                </apex:selectList>
                
                <!--  Account lookup to add existing accounts to the picklist -->
                <apex:inputField styleClass="hiddenInput" 
                value="{!contactId.AccountId}" id="accountId" >
                    
                    <!-- When an account is looked up, it is added to the select list -->                            
                    <apex:actionSupport event="onchange" 
                        action="{!accountLookedUp}" 
                        rerender="accountList, opportunityName, ViewLink"
                         />
                        
                </apex:inputField>
                
                <!-- This is a link which shows a view of the selected account in a new pop up window -->                
                <apex:commandLink id="ViewLink"  value="View"
                    onclick="javascript:if ('{!selectedAccount}' != 'NEW' && '{!selectedAccount}' != 'NONE' ) {var newWindow = window.open('/{!selectedAccount}/p', 'accountview', 'top=40, left=40,scrollbars=yes, height=450, width=800');newwindow.focus();} else {alert('You can only view existing accounts.');}"
                />
                
            </apex:outputPanel>
        </apex:pageBlockSectionItem>
        
        <!-- Opportunity section -->
        <apex:pageBlockSectionItem id="oppSection" >
            
            <apex:outputPanel id="oppPanel" >
                <apex:outputLabel value="Opportunity Name" for="opportunityName" />
            </apex:outputPanel>
            
            
            <apex:outputPanel id="opportunityPanel" layout="block">
                <apex:outputPanel rendered="{!NOT(doNotCreateOppty)}" styleClass="requiredInput" id="block">
                <div class="requiredBlock"></div>
                
                <!-- Opportunity Name -->
                <apex:inputField required="false" 
                    value="{!opportunityID.Name}" id="opportunityName"/>
                </apex:outputPanel>
                
                <!--  This is only shown if the Do Not Create Opportunity is true -->    
                <apex:inputText disabled="true" rendered="{!doNotCreateOppty}"  value="{!opportunityID.Name}" id="opportunityNameDisabled"/>
                <apex:outputPanel layout="block" styleClass="requiredInput">
                <apex:outputPanel layout="block" />
                
                <!-- Checkbox indicating whether to create an Opportunity -->
                <apex:inputCheckbox value="{!doNotCreateOppty}" id="doNotCreateOppty">
                    <apex:actionSupport event="onchange" 
                        
                        rerender="opportunityPanel"
                         />
                </apex:inputCheckbox>
                Do not create a new opportunity upon conversion.
            </apex:outputPanel> 
            </apex:outputPanel>
        </apex:pageBlockSectionItem>
        
        <!-- Converted Status -->
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Converted Status" for="leadStatus" />
            <apex:outputPanel styleClass="requiredInput" layout="block">
                <div class="requiredBlock"></div>
                <apex:selectList id="LeadStatusList" size="1" 
                    value="{!LeadToConvert.Status}" multiselect="false" required="true">
                    <apex:selectOptions value="{!LeadStatusOption}"/>
                </apex:selectList> 
            </apex:outputPanel>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
    
</apex:component>


 
I've written the following code which checks the record ID of the opportunity that's the target of the trigger against a list of IDs which are stored in a custom setting. The idea is that rather than hard coding the record IDs, I'll only need to maintain the list of IDs in the custom setting and reference that, for all of my code.
 
trigger FSRUpdate2 on Opportunity (before insert, before update) {

            
    Set<Id> recordTypesIds = new Set<Id>();
    Map<String, WEID__c> allOpps = WEID__c.getAll();

    for (Opportunity opp : Trigger.new){
        
        if (recordTypesIds.contains(opp.RecordTypeId)) {
            if(opp.Annual_Settlement_Value__c > 0 && opp.Interchange_Rate_Revenue_as_a_percentag__c > 0)
            {
                Decimal fsr = opp.Annual_Settlement_Value__c * opp.Interchange_Rate_Revenue_as_a_percentag__c;
            
                opp.FSR_Estimate_on_Contract_Signature__c = fsr;
                
            } else {
                opp.Annual_Settlement_Value__c = null;
                opp.FSR_Estimate_on_Contract_Signature__c = null;
            
            insert opp;
            }
        }
    }
}



I don't have any code coverage for lines 9 and beyond so I'm assuming that the test class is not finding the matching ID in my custom setting (it's definitely there), even though line 10 has code coverage because I've tested when the values required for the calculation are available and when they aren't.
 
@isTest
public class CP_FSRUpdate2Test {
    
    static testMethod void testFSR(){
        
        Opportunity opp = new Opportunity();
        opp.name = 'Test Opp';
        opp.RecordTypeId = '012700000005qig';
        opp.StageName = '1) Suspect';
        opp.CloseDate = date.newInstance(2045, 01, 01);

        
        //cover Credit Agreement Details Required validation rule
        opp.Credit_Limit__c = 100.00;
        opp.Date_Credit_Limit_Approved__c = date.newInstance(1901, 01, 01);
        opp.Payment_Terms_Days__c = 5;
        opp.Billing_Cycle__c = 'Daily';
        
        //cover Revenue Values Required validation rule (and provide values required for calculation)
        opp.Annual_Settlement_Value__c = 100.00;
        opp.Average_transaction_Value_POS__c = 1.00;
        
        opp.Interchange_Rate_Revenue_as_a_percentag__c = 0.1;
        
        insert opp;
        
        
        //Check Record Type
        Opportunity usOpp = new Opportunity();
        
        usOpp.RecordTypeId = '012700000005r08';
        
        usOpp.name = 'US Opp';
        //usOpp.campaign = 'Online Application Form';
        usOpp.StageName = '1) Suspect';
        usOpp.CloseDate = date.newInstance(2045, 01, 01);
        usOpp.Credit_Limit__c = 100;
        usOpp.Date_Credit_Limit_Approved__c = date.newInstance(1901, 01, 01);
        usOpp.Payment_Terms_Days__c = 5;
        usOpp.Billing_Cycle__c = 'Daily';
        usOpp.Annual_Settlement_Value__c = 1000000.00;
        usOpp.Average_transaction_Value_POS__c = 100.00;
        usOpp.Interchange_Rate_Revenue_as_a_percentag__c = 0.1;
        try{
            insert usOpp;
        } catch (Exception a) {
            System.debug('Wrong record type caused trigger to fail');
        }

        //Check no interchange rate
        Opportunity noIntOpp = new Opportunity();  
        
        noIntOpp.name = 'No Interchange Opp';
        noIntOpp.RecordTypeId = '012700000005qig';
        noIntopp.StageName = '1) Suspect';
        noIntopp.CloseDate = date.newInstance(2045, 01, 01);      
        //noIntOpp.campaign = 'Online Application Form';
        noIntOpp.Credit_Limit__c = 100.00;
        noIntOpp.Date_Credit_Limit_Approved__c = date.newInstance(1901, 01, 01);
        noIntOpp.Payment_Terms_Days__c = 5;
        noIntOpp.Billing_Cycle__c = 'Daily';
        noIntOpp.Average_transaction_Value_POS__c = 100;
        noIntOpp.Annual_Settlement_Value__c = 0;
        noIntOpp.Interchange_Rate_Revenue_as_a_percentag__c = 0;
        
        system.AssertEquals(noIntOpp.FSR_Estimate_on_Contract_Signature__c,null);
        
        try{
            insert noIntOpp;
        } catch (Exception b) {
            System.debug('No interchange % caused trigger to fail');
        }
    }

}



I can't find any examples of a list custom setting being used to store IDs (as opposed to a hierachy), can this be done and if so have I referenced the right objects in my Set / Map - I don't get an error if I change Id to String?
I can't find any resources which explain how to format a percentage in an apex class.

I'm writing a test class and need to assign a value to a field.
 
opp.Interchange_Rate_Revenue_as_a_percentag__c = 0.1;


Gives me "System.NullPointerException: Attempt to de-reference a null object".

Hi All,

 

Sorry to mark it urgent, as i need to implement this soon...

 

I have a custom object with Master detail Relationship, now i want to make this field as lookp field (reason: i may not have the master record each time for the detail record). Please let me know the way of converting the master field to Lookup, or any other Data Type.

 

or else, is there any way to to mark the Master Detail field as non-mandatory on the detail objects page layout

 

Please let me know..

 

Thanks