• Pavan Kumar 1072
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 4
    Replies
Currently, I'm working on a requirement which is to display selected records from one table named table to another table named table2 as pills. I have written the code which is working fine without pills. I am unable to see the records while using pills. Please let me know where i have missed it.
 
<apex:page controller="AccountSelectClassController" sidebar="false" showHeader="false" applyHtmlTag="false" applyBodyTag="false" docType="html-5.0" >
<html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" lang="en">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="x-ua-compatible" content="ie=edge" />
    <title>Salesforce Module</title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <!-- Import the Design System style sheet -->
    <apex:slds />
</head>
<body>
    <script type="text/javascript">
    function selectAllCheckboxes(obj,receivedInputID)
    {
        var inputCheckBox = document.getElementsByTagName("input"); 
        var inputCheckBoxs = document.getElementsByTagName("output");                 
        for(var i=0; i<inputCheckBox.length; i++)
        {          
            if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1)
            {                                    
                inputCheckBox[i].checked = obj.checked;
            }
        }
        for(var i=0; i<inputCheckBoxs.length; i++)
        {          
            if(inputCheckBoxs[i].id.indexOf(receivedInputID)!=-1)
            {                                    
                inputCheckBoxs[i].checked = obj.checked;
            }
        }
    }
</script>
<div class="slds-scope">
<div class="myapp">
<apex:form>
<apex:pageBlock>
<apex:pageBlockButtons>
    <apex:commandButton value="Show Selected Accounts" action="{!processSelected}" reRender="table,table2"/>
</apex:pageBlockButtons>             
<apex:pageblockSection title="All Accounts" collapsible="false" columns="2">
    <apex:pageBlockTable value="{!wrapAccountList}" var="accWrap" id="table" title="All Accounts">
    <apex:column >
    <apex:facet name="header">
    <apex:inputCheckbox >
    <apex:actionSupport event="onclick" action="{!processSelected}" onsubmit="selectAllCheckboxes(this,'inputId')" rerender="table,table2"/>
    </apex:inputCheckbox>
    </apex:facet>
    <apex:inputCheckbox value="{!accWrap.selected}" id="inputId">
    <apex:actionSupport event="onclick" action="{!processSelected}" rerender="table,table2"/>
    </apex:inputCheckbox>
    </apex:column>
    <apex:column value="{!accWrap.acc.Name}" />
    <apex:column value="{!accWrap.acc.BillingState}" />
    <apex:column value="{!accWrap.acc.Phone}" />
    </apex:pageBlockTable>
    <apex:pageBlockTable value="{!selectedAccounts}" var="c" id="table2" title="Selected Accounts">
        <div  class="slds-pill_container">
        <span class="slds-pill slds-pill_link">
        <a href="javascript:void(0);" class="slds-pill__action" title="Full pill label verbiage mirrored here">
        <span class="slds-pill__label">Account Name</span>
        </a>
        <button class="slds-button slds-button_icon slds-button_icon slds-pill__remove" title="Remove">
        <svg class="slds-button__icon" aria-hidden="true">
            <use xlink:href="{!URLFOR($Asset.SLDS, '/assets/icons/utility-sprite/svg/symbols.svg#close')}"></use>
        </svg>
        <span class="slds-assistive-text">Remove</span>
        </button>
        </span>
        </div>
    </apex:pageBlockTable>  
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</div>
</div> 
</body>
</html>
</apex:page>

For Reference
I have a requirement to share lead records to a particular user when team = Bangalore team.

And team field is updating based on the owner of the lead record. Now I'm trying to create a test class for this requirement. But I'm facing an issue.

System.DmlException: Upsert failed. First exception on row 0 with id 00QN0000008KXuhMAG; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Trigger: execution of AfterUpdate

caused by: System.DmlException: Insert failed. First exception on row 0 with id 01oN0000009m7uUIAQ; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]

Class.LeadSharing.BangaloreTeamShareUpdateordelete: line 47, column 1

Apex Test Class:

 
Static testmethod void testUpdateLeads()
    {
        List<Lead> leads = new List<Lead>{};
        Id queueID=[Select Queue.Id,Queue.name from QueueSObject where Queue.Name = 'Charlotte Leads' LIMIT 1].Queue.ID;
        Id userid=[Select id,name from user where name='Pavan Kumar' Limit 1].Id;
        for(Integer i = 0; i < 20; i++) 
        {
            Lead a = new Lead(lastName='TestCavalry'+ i,RecordTypeId ='0126F0000016MZP',
                              Company ='Azuga Cavalry'+ i,Status='New',Account_Category_new__c='Prospect',
                              Account_Category__c='Regular',Lead_Category__c='Sales',Lead_Type__c='Association List',
                              Lead_Source__c='NEFBA',LGS_Owner_new__c='Cavalry Test',ownerid=queueID);
            leads.add(a);
        }
        test.startTest();
        // Insert the Account records that cause the trigger to execute.
        insert leads;
        // Stop the test, this changes limit context back to test from trigger.
        test.stopTest();
        // assert that 0 shares exist
        List<LeadShare> shares = [select id from LeadShare where 
                                     LeadId IN :Leads and RowCause = 'Manual'];
        System.assertEquals(shares.size(),0);
        for(Lead leadidss:leads)
        {
            leadidss.ownerid=userid;
        }
        update leads;
        // assert that 20 shares were created
        shares = [select id from LeadShare where LeadId IN :leads and RowCause = 'Manual'];
        System.assertEquals(shares.size(),20);
        /*
        **for(Lead leadids:leads)
        {
            leadids.ownerid=QueueID;
        }**
        update leads;
        // assert that 0 shares were created
        shares = [select id from LeadShare where LeadId IN :leads and RowCause = 'Manual'];
        System.assertEquals(shares.size(),0);*/
    }

And line 47 would be.
 
for(Lead leadids:leads)
            {
                leadids.ownerid=QueueID;
            }

Apex Class:
 
public static void BangaloreTeamShareUpdateordelete(List<Lead> newleads,Map<Id,Lead> oldmapleads)
    {
        List<Id> Sharedeletionlist = new List<Id>();
        List<LeadShare> Shareinsertlist = new List<LeadShare>();
        for(Lead leadid:newleads)
        {
            if(oldmapleads.get(leadid.id).team__c == 'Bangalore Team' && 
               (leadid.Team__c <> 'Bangalore Team' || String.isBlank(leadid.Team__c)) )
            {
                Sharedeletionlist.add(leadid.id);
            }
            else if((oldmapleads.get(leadid.Id).team__c <> 'Bangalore Team' || String.isBlank(oldmapleads.get(leadid.id).team__c)) && 
                    leadid.Team__c == 'Bangalore Team')
            {
                leadshare leadshareid= new leadshare();
                leadshareid.LeadId=LeadId.Id;
                leadshareid.UserOrGroupId=userid;
                leadshareid.LeadAccessLevel='edit';
                Shareinsertlist.add(leadshareid);
            }
            if(Sharedeletionlist <> null && !Sharedeletionlist.isEmpty())
            {
                delete[Select id from leadshare where leadid IN :Sharedeletionlist AND RowCause='Manual'];
            }
            If(Shareinsertlist <> null && !Shareinsertlist.isEmpty())
            {
                insert Shareinsertlist;
            }
        }
    }

I tried multiple ways like disabling parallel apex test execution. And updating update DML statement to upsert.

Please guide me where I went wrong.
 
I have a javascript button in my organization to restrict quote creation for sales users when respective criteria met
If Person is trying to create a quote it will check whether it is assigned to the manager or not with how many days prospect with us and so.
 
But it is not working as expected even it didn't meet the first criteria. It is displaying an alert message.
It meets the first if criteria But it is routing to respective URL.
 
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}
var Subrecords = sforce.connection.query("SELECT Id,name from Zuora__Subscription__c where Zuora__Account__c ='{!Opportunity.AccountId}'");
records = Subrecords.getArray("records");
if('{!$User.Type__c}' == 'Bangalore' && '{!Account.Account_Status__c}' == 'Active / Green' && '{!Account.Age_of_Account_Days__c}' > 180 && '{!ISPICKVAL( Account.AM_sales__c , 'Yes')}' && '{!$User.Username}' !== 'sample@azs.com')
{
alert("You don't have sufficient access to generate quote"); 
}
else 
{
if(records.length > 0)
{
window.location.href='https://zqu.ap4.visual.force.com/apex/quoteEnhancement?oppId={!Opportunity.Id}&quoteType=Subscription&stepNumber=1';
}
else
{
window.location.href='https://zqu.ap4.visual.force.com/apex/CreateQuote?oppId={!Opportunity.Id}&quoteType=Subscription&scontrolCaching=1&stepNumber=2';
}
}
I don't where I missed it
  
I have a requirement in cases relationship with child cases.
In parent case i have a main field called orginal order Quanity and total units order.
And for every case we have total units order field.

Like Suppose i have parent P1 case with following values
P1 orginal order quantity = 50,total units ordered=30;
Difference between is 20.

So, i need to restrict my support reps to create any child cases for above parent would be equals or less than difference means 20

So i use aggregate query and with parent case values.

But the problem is it is not allowing me to save child case if i give less value equals 20 or less than too.
 
public static void ChildOrder(List<Case> CaseTriggers)
{
    Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'Customer_Order'].Id;
    List<Case> CaseIDs = new List<Case>();
    Decimal add=0,sum=0;
    system.debug('Old Values'+CaseTriggers);
    List<Id> ParentIds =new List<ID>();
    Map<Id,case> parentdetails= new Map<Id,case>();
    for (Case s : CaseTriggers)
    {
        if(s.RecordTypeId == recordTypeId && s.ParentID != null) 
        {
            // Loop through and add caseId's to the list.
            CaseIDs.add(s);
            ParentIDs.add(s.ParentId);
        }
    }
    Map<Id, AggregateResult> results = new Map<Id, AggregateResult>(
        [SELECT ParentID Id, SUM(Total_units_ordered__c) total FROM Case WHERE ParentID= :ParentIDs GROUP BY ParentID]);
        if(ParentIDs !=null && !ParentIDs.isEmpty()) 
        {
            for(case cd:[Select id,FSS_Rep__c,FSS_TL__c,Total_units_ordered__c,Original_Ordered_Qty__c from case where id =:ParentIds])
            {
                parentdetails.put(cd.id, cd);
            }
        }
    for(case cass: CaseTriggers)
    {
        if(results.get(cass.ParentID) != null)
        { 
            if((Decimal)cass.Total_units_ordered__c <= (Decimal)parentdetails.get(cass.ParentId).Original_Ordered_Qty__c - 
                                               parentdetails.get(cass.ParentId).Total_units_ordered__c-(Decimal)results.get(cass.ParentId).get('total'))
            {   
                    cass.FSS_Rep__c=parentdetails.get(cass.ParentId).FSS_Rep__c;
                    cass.FSS_TL__c=parentdetails.get(cass.ParentId).FSS_TL__c;   
            }
            else if((Decimal)cass.Total_units_ordered__c > (Decimal)(parentdetails.get(cass.ParentId).Original_Ordered_Qty__c - 
                       parentdetails.get(cass.ParentId).Total_units_ordered__c)-(Decimal)results.get(cass.ParentId).get('total'))
            {
                add=(Decimal)(parentdetails.get(cass.ParentId).Original_Ordered_Qty__c - 
                                               parentdetails.get(cass.ParentId).Total_units_ordered__c)-(Decimal)results.get(cass.ParentId).get('total');
                cass.addError('You can ship only'+' '+add+' '+'unit for this order');
            }

        }
        }   
    }

Please Let me know your suggestions we are went wrong. 
 
I have a requirement in cases relationship with child cases.
In parent case i have a main field called orginal order Quanity and total units order.
And for every case we have total units order field.

Like Suppose i have parent P1 case with following values
P1 orginal order quantity = 50,total units ordered=30;
Difference between is 20.

So, i need to restrict my support reps to create any child cases for above parent would be equals or less than difference means 20

So i use aggregate query and with parent case values.

But the problem is it is not allowing me to save child case if i give less value equals 20 or less than too.
 
public static void ChildOrder(List<Case> CaseTriggers)
{
    Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'Customer_Order'].Id;
    List<Case> CaseIDs = new List<Case>();
    Decimal add=0,sum=0;
    system.debug('Old Values'+CaseTriggers);
    List<Id> ParentIds =new List<ID>();
    Map<Id,case> parentdetails= new Map<Id,case>();
    for (Case s : CaseTriggers)
    {
        if(s.RecordTypeId == recordTypeId && s.ParentID != null) 
        {
            // Loop through and add caseId's to the list.
            CaseIDs.add(s);
            ParentIDs.add(s.ParentId);
        }
    }
    Map<Id, AggregateResult> results = new Map<Id, AggregateResult>(
        [SELECT ParentID Id, SUM(Total_units_ordered__c) total FROM Case WHERE ParentID= :ParentIDs GROUP BY ParentID]);
        if(ParentIDs !=null && !ParentIDs.isEmpty()) 
        {
            for(case cd:[Select id,FSS_Rep__c,FSS_TL__c,Total_units_ordered__c,Original_Ordered_Qty__c from case where id =:ParentIds])
            {
                parentdetails.put(cd.id, cd);
            }
        }
    for(case cass: CaseTriggers)
    {
        if(results.get(cass.ParentID) != null)
        { 
            if((Decimal)cass.Total_units_ordered__c <= (Decimal)parentdetails.get(cass.ParentId).Original_Ordered_Qty__c - 
                                               parentdetails.get(cass.ParentId).Total_units_ordered__c-(Decimal)results.get(cass.ParentId).get('total'))
            {   
                    cass.FSS_Rep__c=parentdetails.get(cass.ParentId).FSS_Rep__c;
                    cass.FSS_TL__c=parentdetails.get(cass.ParentId).FSS_TL__c;   
            }
            else if((Decimal)cass.Total_units_ordered__c > (Decimal)(parentdetails.get(cass.ParentId).Original_Ordered_Qty__c - 
                       parentdetails.get(cass.ParentId).Total_units_ordered__c)-(Decimal)results.get(cass.ParentId).get('total'))
            {
                add=(Decimal)(parentdetails.get(cass.ParentId).Original_Ordered_Qty__c - 
                                               parentdetails.get(cass.ParentId).Total_units_ordered__c)-(Decimal)results.get(cass.ParentId).get('total');
                cass.addError('You can ship only'+' '+add+' '+'unit for this order');
            }

        }
        }   
    }

Please Let me know your suggestions we are went wrong. 
 
I will be having email alerts sent to clients and I want their replies to go to an Email Service address. But I can't simply make that long address the "From" address because that must be an org-wide approved email address, which you cannot do with an email service address. 

So, it's been suggested to me to use an org-wide approved address (sales@company.com etc) and simply set up that email account to automatically forward all of its mail to the long email service address. However, I can't use the long email service address as a destination address in the forwarding process either. Gmail needs to send a verification to whatever email will be used and I cannot perform an approval for the email address, or at least I don't know how to.

How can I accomplish this ? 

Thank you.
  • October 02, 2015
  • Like
  • 0
Hi,  I receive the following error in a test class but have not been able to repeat them in non test running scenarios.

"System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow. 
A flow trigger failed to execute the flow with version ID 301O00000008hM6. 
Contact your administrator for help.: []"

Does anyone know if there could be an issue running flows in test class contexts but not otherwise?

Thanks.