• TechEd_Programmer
  • NEWBIE
  • 35 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 26
    Questions
  • 31
    Replies
I have a flag in my Aura:if that allows me to add columns to my interface. I am able to access the controller, however, it does not appear to be updating the flag.

Component Code:
<aura:if isTrue="{!(not(v.showYear4))}">
                    	<lightning:buttonIcon name="4" iconName="utility:add" title="Add Year 4" onclick="{!c.addColumn}" />
                    </aura:if>
                </th>
                <aura:if isTrue="{!v.showYear4}">
                    <th scope="col">
                        <span class="slds-truncate" title="YR4">Year 4</span>
                    </th>
                </aura:if>
Controller Code:
addColumn : function(component, event, helper){
    	
        console.log("made it here");
        var currentTarget = event.currentTarget;
        var currentYear = currentTarget.getAttribute("name");
        component.set("v.showYear"+currentYear,true);
        console.log("v.showYear"+currentYear);
        
    }

Any help wouldd be appreciated. The code is not displaying the second console.log statement but is displaying "made it here"


 
As I need to filter out specific activities from a list, I am attempting to create the ActivityHistory and Open Activity component for a Lightning Page.

I understand how to display lists when they are different objects, however, when I am querying form the same object I am struggling with determining how to display each list where I want.

APEX Controller:
public with sharing class CH_Activity_Viewer_Controller {
@AuraEnabled
public static List<WorkOrder> getOpenAvtivities(Id recordId)
{
    System.debug(recordId);
    return [SELECT Id, (SELECT Id, Subject, Who.Name, StartDateTime, DurationInMinutes FROM OpenActivities) FROM WorkOrder WHERE Id = :recordId];
}

@AuraEnabled
public static List<WorkOrder> getActivityHistory(Id recordId)
{
    System.debug(recordId);
    return [SELECT Id, (SELECT Id, Subject, Who.Name, StartDateTime, DurationInMinutes FROM ActivityHistories) FROM WorkOrder WHERE Id = :recordId];
}
}

Lightning Controller
({
loadInterface : function(component, event, helper)
{
    $( function()
    {
        $( "#accordion" ).accordion();
    });
},

doInit : function(component, event, helper)
{
    var action1 = component.get("c.getOpenAvtivities");
    var action2 = component.get("c.getActivityHistory");
    action1.setParams({
        "recordId" : component.get("v.recordId")
    });
    action1.setCallback(this, function(response) {
        var state = response.getState();
        if (state === "SUCCESS") {
            //update all the action1 attributes in the component.
            component.set("v.action1",response.getReturnValue());               
        }
        else if (state === "ERROR") {
            var errors = response.getError();
            if (errors) {
                if (errors[0] && errors[0].message) {
                    console.log("Error message: " + 
                             errors[0].message);
                }
            } else {
                console.log("Unknown error");
            }
        }
    });
    action2.setParams({
        "recordId" : component.get("v.recordId")
    });
    action2.setCallback(this, function(response) {
        var state = response.getState();
        if (state === "SUCCESS") {
            //update all the action2 attributes in the component.
            component.set("v.action2",response.getReturnValue());               
        }
        else if (state === "ERROR") {
            var errors = response.getError();
            if (errors) {
                if (errors[0] && errors[0].message) {
                    console.log("Error message: " + 
                             errors[0].message);
                }
            } else {
                console.log("Unknown error");
            }
        }
    });

    $A.enqueueAction(action1);
    $A.enqueueAction(action2);
}  
})

Component
<aura:component controller="CH_Activity_Viewer_Controller" implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId" access="global">
<ltng:require scripts="/resource/ActivityViewer/ActivityViewer/jquery-3.2.1.min.js,/resource/ActivityViewer/ActivityViewer/jquery-ui.js" afterScriptsLoaded="{!c.loadInterface}"/>
<ltng:require styles="/resource/ActivityViewer/ActivityViewer/jquery-ui.css"/>
<aura:attribute name="action1" type="WorkOrder[]" />
<aura:attribute name="action2" type="WorkOrder[]" />
<aura:attribute name="recordId" type="Id" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />



<div id="accordion">
    <h3>Open Activities</h3>
    <div>
        <aura:iteration var="wo1" items="{!v.action1}" >
            <aura:iteration var="act1" items="{!wo1.OpenActivities}" >
            <p><b>{!act1.Subject}</b></p>
            <p>{!act1.Who.Name}</p>
            <p>{!act1.StartDateTime}</p>
            <p>{!act1.DurationInMinutes} MIN</p>
            </aura:iteration>
        </aura:iteration>
    </div>
    <h3>Activity History</h3>
    <div>
        <aura:iteration var="wo2" items="{!v.action2}" >
            <aura:iteration var="act2" items="{!wo2.OpenActivities}" >
            <p><b>{!act2.Subject}</b></p>
            <p>{!act2.Who.Name}</p>
            <p>{!act2.StartDateTime}</p>
            <p>{!act2.DurationInMinutes} MIN</p>
            </aura:iteration>
        </aura:iteration>
    </div>
</div>

Any Help is greatly appreciated.​

So here is the business case:

 

If an opportunity is ia a mature stage, prevent the deletion of all contact roles.

 

Here is the code I created to accomplish this goal. I need to stop the deletion from occuring on teh COntact Rols, but cannot write triggers on contact role. The below controller is associated to a VF Page to get it to run taht is hiddien in the standard layout.

 

public with sharing class CROppHelper {
	
	public Opportunity opp;
	public CROppHelper( ApexPages.StandardController stdController ) {
        opp = ( Opportunity )stdController.getRecord();        
    }
    public void rollupOppContactRole(){
        CROppHelper.rollupOppContactRoleFuture(opp.Id);
    }
    @future public static void rollupOppContactRoleFuture( Id oppId ) 
    {
    	Integer priCnt;
        OpportunityContactRole[] oppRoleList = [SELECT ContactId, IsPrimary FROM OpportunityContactRole
                                         WHERE OpportunityId = :oppId];
        Opportunity opp = [Select ID from Opportunity where Id =: oppId];
        If(oppRoleList.size() > 0)
        {
        	for( OpportunityContactRole oppRole : oppRoleList ) 
        	{
        		if(oppRole.IsPrimary == TRUE)
        		{
        			priCnt = 1;
        		}
        	
        		if(priCnt == 1)
        		{
        			opp.addError('Opportinuty must have a Primary Contact Role in order to be in this stage.');
        		}
        	}
        }
        update opp;
    }
}

VF Page

<apex:page standardController="Opportunity" extensions="CROppHelper" action="{!rollupOppContactRole}"/>

 

 

 When a CR is deleted the code is being triggered to run, but it is not preventing the deletion, nor is it displaying the error on the opportunity. Can I have some assistance please?

So I cannot seem to figure this one out. I do not use maps all that often and I am having a hard time determining how to update a value from it.

 

I am trying to update the inventory by subtracting the value from the map. Pleas see the code below:

trigger PO_Request_Update_Inv_Transit on PO_Request__c (after update) {

	PO_Request__c[] porequest;
	
	Set<Id> poSet = new Set<Id>();
	Set<Id> podetailSet = new Set<Id>();
	Set<Id> inventorySet = new Set<Id>();
	Map<String, Decimal> popartMap = new Map<String, Decimal>();
	List<Inventory__c> inventoryList = new List<Inventory__c>();
	List<PO_Request_Detail__c> porequestdetailList = new List<PO_Request_Detail__c>();
	
	for(PO_Request__c po:porequest)
	{
		poSet.add(po.Id);
		Decimal invQty = 0;
		
		If(po.PO_Req_Status__c == 'Approved')
		{
			porequestdetailList = [Select Id, PO_Request__c, Part_Num__c, Qty__c from PO_Request_Detail__c where PO_Request__c IN : poSet];
			
			for(PO_Request_Detail__c prd:porequestdetailList)
			{
				popartMap.put(prd.Part_Num__r.Id, prd.Qty__c);
				podetailSet.add(prd.Part_Num__c);
			}
			
			inventoryList = [Select Part_Num__r.Id, Qty__c from Inventory__c where Part_Num__c IN :podetailSet];
			
			for(Integer i = 0; i < inventoryList.size(); i++)
			{
				if(popartMap.containsKey(inventoryList[i].Part_Num__r.Id))
				{
					inventoryList[i].Qty__c = inventoryList[i].Qty__c - 
				}
				update inventoryList;
			}
		}
	}
}

 My main problem is how to get the mapped value and use it in my calculation to update.

 

inventoryList[i].Qty__c = inventoryList[i].Qty__c - ???

 

Thank you for your help.

Below is the Batch Job I have created. I am a litle fuzzy as to how to implement this in the shceduler. Can someone assist?

 

global class UpdateContactFlags implements Schedulable, Database.Batchable<sObject>{
	public string query = 'SELECT Id, Contact.Id, Campaign.Fund_s__c, Campaign.Listing_Tactic__c, Status from CampaignMember';
		
	global Database.Querylocator start(Database.BatchableContext BC)
	{
		
		return Database.getQueryLocator(query);
	}
	
	global void execute(SchedulableContext SC)
	{
		UpdateContactFlags ucfg = new UpdateContactFlags();
		database.executebatch(ucfg, 100);
	}
	
	global void execute(Database.BatchableContext BC, List<sObject> scope)
	{
	Set<id> liContIds = new Set<id>();

	for(sObject s : scope){
		CampaignMember cm = (CampaignMember)s;

		if(cm.Campaign.Fund_s__c == 'FSIC' && cm.Campaign.IsActive == TRUE && cm.Campaign.Listing_Tactic__c == 'Major Market Roadshow')
			liContIds.add(cm.Contact.Id);
		}

	//query all the contact in a single query
	List<Contact> cont = new List<Contact>();
	
	cont = [select id, Major_Market_Roadshows_Green__c from Contact where id in :liContIds and FSIC_Approved__c != NULL];
	
	for ( Contact conts : cont)
	{
		conts.Major_Market_Roadshows_Green__c = 'Y' ; 
	}

	if(cont.size() > 0)
	
	update cont;
	}
	
	global void finish(Database.BatchableContext BC){} 	
}

 Not really sure what I am missing.

 

Thank you in advance for the help.

 

Ok.....just need a bit of help to understand what I am doing wrong.

 

I have all of the attributes I need to display this page in the left subtab sidebar of the service cloud console....I think. I am not sure why it is not showing anything. I have records that should be aggregating and they are not. Can someone tell me why?

 

Controller:

public class NS_ConsoleCaseChartController {
	
	public String strContactID;
	public String strCaseID;
	
	public NS_ConsoleCaseChartController(ApexPages.StandardController stdController){
        strCaseID = ApexPages.currentPage().getParameters().get('Id');
	}
	
	public List<ChartDataItem> getChartData()
	{
		List<ChartDataItem> items = new List<ChartDataItem>();
		
		strContactId = string.valueOf(Case.ContactId);
		
		AggregateResult[] groupedTasks = [SELECT Type, Count(Id) ID FROM Task WHERE WhoId =: strContactID GROUP BY Type];
		
		for (AggregateResult ar : groupedTasks)
		{
			items.add(new ChartDataItem( String.valueOf(ar.get('Type')), Integer.valueOf(ar.get('ID'))));
		}
		
		System.debug(items);
		return items;
	}
	
	public class ChartDataItem
	{
		public String Label {get; set;}
		public Integer Value {get; set;}
		
		public ChartDataItem(String Label, Integer Value)
		{	
			this.Label = Label;
			this.Value = Value;
		}
	}
}

 VF Page:

<apex:page standardController="Case" extensions="NS_ConsoleCaseChartController">
<apex:includeScript value="/soap/ajax/26.0/connection.js"/>
<apex:includeScript value="/support/console/26.0/integration.js"/>
<script type="text/javascript">  
  function openNewSubtab() {
      sforce.console.getFocusedPrimaryTabId(Id);
  	} 
</script>  
	<apex:chart height="195" width="250" data="{!chartData}">
        <apex:pieSeries dataField="Value" labelField="Label"/>
        <apex:legend position="bottom"/>
    </apex:chart>
</apex:page>

 I am really trying to figure out what I am missing here. I am new to developing in the Service Cloud Console.

 

 

All I am writing an Inbound Message Class to handle XML in the body of the e-mail. I am struggling with one error and I am not sure how to resolve it. Any assistance would be appreciated. Below is my class. My Error is on line 95. It is Method Does Not Exist or Incorrect Signature: getDecodedString(System.XMLStreamReader) I understand that it is missing an element before 'reader', btu honestly I am not sure what it should be.

 

/**
 * Email services are automated processes that use Apex classes
 * to process the contents, headers, and attachments of inbound
 * email.
 */
global class Email_CustomerRecord implements Messaging.InboundEmailHandler {

    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
		
		List<Account> act1;
		try
		{
			String messageBody = '';
			String action = '';
			String cust_num = '';
			String name = '';
			String cust_seq = '';
			String addr1 = '';
			String addr2 = '';
			String addr3 = '';
			String addr4 = '';
			String city = '';
			String CusCounty = '';
			String state = '';
			String country = '';
			String zip = '';
			
			messageBody = email.plainTextBody;
			messageBody = messageBody.trim();
			
			messageBody = messageBody.substring(messageBody.indexof('<?xml version="1.0" encoding="UTF-8"?>'),messageBody.indexOf('</CustomerRecord>')+12);
			
			Action = readXMLelement(messageBody,'action');
			
			String cn = readXMLelement(messageBody,'cust_num');
			List<Account> actl = [SELECT Id, Customer_Number__c, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry
									  FROM Account 
									  WHERE Customer_Number__c =: cn
									  ];
			
			if(Action == 'add')
			{
				Account act = new Account();
				
				act.Customer_Number__c = readXMLelement(messageBody,'cust_num');
				act.Name = readXMLelement(messageBody,'name');
				act.BillingStreet = readXMLelement(messageBody,'addr1') + readXMLelement(messageBody,'addr2') + readXMLelement(messageBody,'addr3') + readXMLelement(messageBody,'addr4');
				act.BillingCity  = readXMLelement(messageBody,'city');
				act.BillingState  = readXMLelement(messageBody,'state');
				act.BillingPostalCode  = readXMLelement(messageBody,'zip');
				act.BillingCountry  = readXMLelement(messageBody,'country');
				
				insert act;
			}
			if(Action == 'modify')
			{
				for(Account actList : act1)
				{
					actList.Name = readXMLelement(messageBody,'name');
					actList.BillingStreet = readXMLelement(messageBody,'addr1') + readXMLelement(messageBody,'addr2') + readXMLelement(messageBody,'addr3') + readXMLelement(messageBody,'addr4');
					actList.BillingCity  = readXMLelement(messageBody,'city');
					actList.BillingState  = readXMLelement(messageBody,'state');
					actList.BillingPostalCode  = readXMLelement(messageBody,'zip');
					actList.BillingCountry  = readXMLelement(messageBody,'country');
				}
				
				update act1;					
			}
			if(Action == 'delete')
			{
				delete act1;
			}
		}
		catch(exception e)
		{
			
		}
		
        return result;
    }
    public static String readXMLelement(String xml, String element)
    {
        String elementValue = 'NOT FOUND'; 
        
        try
        {
	        Xmlstreamreader reader = new Xmlstreamreader(xml);
	        while (reader.hasNext()) 
	        {
	            if (reader.getEventType() == XmlTag.START_ELEMENT && reader.getLocalName() == element)
	            {
	                System.debug('Found SID');
	                reader.next();
	                elementValue = getDecodedString(reader); <---Error Method Does Not Exist or Incorrect Signature: getDecodedString(System.XMLStreamReader)
	            }         
	            reader.next();
	        }
	        return elementValue;
        }
        catch(exception e)
        {
			String err;
			err = e.getMessage();
			return err;
        }
    }
}

 Thank you for your assistance.

All -

 

I am creating an email messaging service and I understand how to do it with text in the body, however this specific e-mail is being sent with XML format in the body. Does anyone know the best way to indicate the next line for this type of format? I understand the code for next line etc...but this one is new to me. Any assistance would help.

 

 

Not really sure how to write this class. I cannot seem to get any coverage, and I am stumped as to why.

 

Here is my class:

public with sharing class MyChartController {
	
	public String strCase;
	
	public MyChartController(ApexPages.StandardController stdController){
		strCase = ApexPages.currentPage().getParameters().get('Id'); 
	}
   
	public List<AggregateResult> getDatabyType(){
   		Case c = [Select id, ContactId From Case where id =: strCase LIMIT 1];
   
   		List<AggregateResult> result = [Select COUNT(Id) tskCNT, Type FROM Task WHERE WhoId =: c.ContactId GROUP BY Type];
    	return result;      
	}
}

 And here is the Test Class that has no coverage results:

@isTest
private class MyChartController_Test {

    static testMethod void MyChartController_Test() {
    	
    	PageReference pageRef1 = Page.MyChart;
    	pageRef1.getParameters().get('Id');
    	Test.setCurrentPage(pageRef1);
    	
    	Account act1 = new Account();
    	act1.LastName = 'Test';
    	act1.RecordTypeId = '012i00000006R7z';
    	
    	insert act1;
    	
    	Contact ct1 = new Contact();
    	ct1.AccountId = act1.ParentId;
    	ct1.FirstName = 'John';
    	ct1.LastName = 'Test';
    	
    	insert ct1;
    	
    	Task tsk1 = new Task();
    	tsk1.Subject = 'Other';
    	tsk1.Priority = 'High';
    	tsk1.OwnerId = '005i0000000t0F5';
    	tsk1.Type = 'Follow';
    	tsk1.Status = 'Completed';
    	tsk1.WhoId = ct1.Id;
    	
    	insert tsk1;
    	
    	Case cs1 = new Case();
    	cs1.Origin = 'Web';
    	cs1.ContactId = ct1.Id;
    	cs1.Status = 'Closed';
    	
    	insert cs1;
    	
    	ApexPages.currentPage().getParameters().put('retURL','/'+cs1.id);
    	
    	MyChartController(new ApexPages.StandardController(cs1));
    }
}

 Any assistance and guidance would be greatly appreciated.

Hi All -

 

I am getting the following error for a rollup trigger that I have written and I am not sure how to solve it.

 

Error is on line 45 of the code: 

RollUpUnitAmounts - Unable to update Engagement__c.
Exception encountered Invalid field Id for AggregateResult

The code is:

trigger RollUpUnitAmounts on Product__c (after insert, after update, after undelete, after delete) 
{

	Product__c[] products;

    if (trigger.isDelete)
    {
        products = Trigger.old;
    }
    else
    {
        products = Trigger.new;
    }
    
    Set<Id> set_EngageIds = new Set<Id>();
     
    for (Product__c p:products)
    {
        if (p.Engagement__c != null)
        {
        	set_EngageIds.add(p.Engagement__c);
        }
    }
	
	List<Engagement__c> engagList;
	Map<ID, Engagement__c> engagMap;
	
	try{
	Map<Id,Engagement__c> engtuMap = new Map<Id,Engagement__c>();
	Map<Id,Engagement__c> toBeUpdated = new Map<Id,Engagement__c>();
	String engagementId = '';
	
	for (Engagement__c e : (engagList = [SELECT id,Total_Units__c from Engagement__c where id IN:set_EngageIds]))
        {
        	engagMap = new Map<ID, Engagement__c>(engagList);
        	e.Total_Units__c = 0;
        	engagementId = e.Id;
        	
        	List<AggregateResult> aresults = [select SUM(Units__c)totalUnit from Product__c where id in :set_EngageIds];
        	
        	if (aresults!=null && aresults.size()>0)
        	{
        		for (AggregateResult ar : aresults)
        		{
        			Engagement__c parentEngagement = engagMap.get(String.valueOf(ar.get('Id')));
        			if (parentEngagement!=null) 
                        {
                        	if (ar.get('parentEngagement') != null) 
                                    {
                                        parentEngagement.Total_Units__c = Double.valueOf(String.valueOf(ar.get('parentEngagement'))).intValue();
                                    }
                            
                            break;
                        }
                        
                        engtuMap.put(parentEngagement.Id,parentEngagement);
        		}
        	}
        	if(engtuMap.values().size()>0)
            {
                toBeUpdated.putAll(engtuMap);
            }
        }
        if(toBeUpdated.size()>0)
        {
            update toBeUpdated.values();
        }
        else
        {
            if(engagMap.size()>0)
            {
                update engagMap.values();
            }
        }
        }
	    catch (Exception e) 
    	{
        	System.debug('\n\n>> RollUpUnitAmounts - Unable to update Engagement__c.\nException encountered ' + e.getMessage());
    	}
	}

 Thank you for any assistance you can provide.

RollUpUnitAmounts - Unable to update Engagement__c.
Exception encountered Invalid field Id for AggregateResult

All -

 

So I think I just need direction on a place to start. I have been using google Charts and Visualizations to display complex scatter charts and line graphs. They way I have accomplished this is through the use of long text fields that contain up to 4K plot point in the X and 4000 in the Y field. This has allowed me to do some really great displays.

 

Now my user is asking me if I can layer my line graphs. Each line graph has it's own X and Y. To be clear, they rarely share a location on a graph (ie...X1 != X2 or Y1 != Y2). I have read and viewed many layered sales graphs that use the same year or month, but I do not have that commonality in mine. 

 

Is there a way to do a layered line graph with up to 6 lines where the only constant is my Max and Min? Can someone point me in the right direction? I would like to use VF Charts if at all possible.

 

Thank you in advance for any assistance you can provide.

 

JP

All -

 

I have created an integration that creates over 2000 records. The reason that it is so high is that I am parsing 2 very large fields on the C# side of the integration. I desperately need to reduce my API calls so the only solution is for me to parse the data in Salesforce. I do not even know where to begin. The data would come in in two very large text fields. Each value in each field has exactly 8 characters after the decimal. I would need to parse and translate these values in pair values that create multiple recors in SFDC.

 

Can someone point me in the correct direction?

 

TechEd