• Clay Ashworth
  • NEWBIE
  • 45 Points
  • Member since 2014

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 12
    Replies
Can anyone give me some direction on a service class I'm trying to write?  Essentially, I have a custom object called Transactions__c, which looks up to another custom object called PD_Data__c, which in turn looks up to the Account.  When a field called Amount_Due__c on a Transaction record is updated to a value greater than 0, I want to set the stage on any open oppty on the same Account to closed won. See illustration below:

User-added image

I've written some of the code, but I'm kinda stuck and I'm not sure if I'm even on the right track.

public with sharing class CloseOutOpptyService {

    public static list<Transactions__c> filterAmountDueChange(map<id, Transactions__c> oldMap, list<Transactions__c> newList) {
    	list<Transactions__c> temp=new list<Transactions__c>();
    	for (Transactions__c trxs : newList){
 			if ( 
 			      (oldMap.get(trxs.id).pd_amount_due__c == null || oldMap.get(trxs.id).pd_amount_due__c == 0) 
 			      && (trxs.pd_amount_due__c > 0)
 			      ){
 			temp.add(trxs);
 			}
    		
    	}
    	return temp;  
    }
    
	public static Set<Id> closeOpptys (list<Transactions__c> trxAccount) {        
		list<Transactions__c> trxAccountIds = [SELECT Id, Parent_PD_Data__r.SFDC_Account__r.Id FROM Transactions__c Where Id in: trxAccount];

		Set<Id> accountIds = new Set<Id>();
		for(Transactions__c trxAccountId : trxAccountIds) {
       		accountIds.add(trxAccountId.Parent_PD_Data__r.SFDC_Account__c);
		}

		return accountIds;




Any help would be greatly appreciated.  Thanks!







I am having an issue trying to pass inputField values from my VF page back to the controller using actionFunction with an onchange. The intent is that when the value in the inputField is changed by the user the new value is passed to the controller for processing.

As it stands now values for the inputFields are being passed but not the updated value of the field that was changed and triggered the onchange to fire. I have been over this for several hours and tried a few different methods of approaching this, none of which have been successful. Any help is appreciated.

VF Page:
<apex:pageBlockSection id="Detail" title="Product Detail">
    		<apex:inputField value="{!qli.Service_Location__c}" required="true"/> 		
    		<apex:inputField value="{!qli.Term__c}" required="true" label="Term (Months)"/> 
    		<apex:inputField value="{!qli.Service_Type__c}" required="true"/> 
    		<apex:inputField value="{!qli.Quantity}" required="true" id="quantity" onchange="updateQty();">
 				<apex:actionFunction name="updateQty" action="{!getdiscount}" rerender="listpricing" immediate="true">
					<apex:param name="xquantity" value="{!qli.Quantity}" assignTo="{!xquantity}"/>
					<apex:param name="xsalesMRC" value="{!qli.UnitPrice}" assignTo="{!xsalesMRC}"/>
					<apex:param name="xNRC" value="{!qli.NRC_is_Quantity_Sensitive__c}" assignTo="{!xNRC}"/> 
				</apex:actionFunction> 
			</apex:inputField>
</apex:pageBlockSection> 
<apex:pageBlockSection id="salesPricing" title="Sales Pricing">

    			<apex:inputField value="{!qli.UnitPrice}" id="CsalesMRC" label="Sales MRC" onchange="updateMRC();">
    			 	<apex:actionFunction name="updateMRC" action="{!getdiscount}" rerender="listpricing" immediate="true">
						<apex:param name="xquantity" value="{!qli.Quantity}" assignTo="{!xquantity}"/>
						<apex:param name="xsalesMRC" value="{!qli.UnitPrice}" assignTo="{!xsalesMRC}"/>
						<apex:param name="xNRC" value="{!qli.NRC_is_Quantity_Sensitive__c}" assignTo="{!xNRC}"/> 
					</apex:actionFunction> 
				</apex:inputField>	
    			<apex:inputField value="{!qli.NRC__c}" label="Sales NRC" required="true"/> 
    			<apex:outputField value="{!qli.TotalPrice}"/> 
    			<apex:outputField value="{!qli.Total_NRC__c}"/> 
    			<apex:outputField value="{!qli.Discount}" label="Discount from List"/>
    			<apex:inputField value="{!qli.NRC_is_Quantity_Sensitive__c}" onchange="updateNRC();">
    			 	<apex:actionFunction name="updateNRC" action="{!getdiscount}" rerender="listpricing" immediate="true">
						<apex:param name="xquantity" value="{!qli.Quantity}" assignTo="{!xquantity}"/>
						<apex:param name="xsalesMRC" value="{!qli.UnitPrice}" assignTo="{!xsalesMRC}"/>
						<apex:param name="xNRC" value="{!qli.NRC_is_Quantity_Sensitive__c}" assignTo="{!xNRC}"/>  
					</apex:actionFunction> 
    			</apex:inputField>
</apex:pageBlockSection>
<apex:pageBlockSection id="listpricing" title="List Pricing" >
</apex:pageBlockSection>



Controller Class:
 
public double quantity				{get; set;}
public decimal CsalesMRC			{get; set;}
public Boolean NRC 				{get; set;}

public void getDiscount() {
		//Get all variables from page
		string xNRC = ApexPages.currentPage().getParameters().get('xNRC');
			system.debug('@@@xNRC = ' + xNRC);
		NRC = boolean.valueOf(xNRC);	
			system.debug('@@@NRC = ' + NRC);
	
		string xSalesMRC = ApexPages.currentPage().getParameters().get('xsalesMRC');
			system.debug('@@@xSalesMRC = ' + xSalesMRC);
		CsalesMRC = double.valueOf(xSalesMRC);		
			system.debug('@@@CsalesMRC = ' + CsalesMRC);
						
		string xQuantity = ApexPages.currentPage().getParameters().get('xquantity');
			system.debug('@@@xQuantity = ' + xQuantity);
		quantity = decimal.valueOf(xQuantity);
			system.debug('@@@quantity = ' + quantity);
}

 
I am looking for a little guidance on my REGEX statement for a Patter/Matcher Class that extracts a specific string from the body of a plain text email.

The desired match should be as follows:
REF#:xxxx 
where xxxx represents a 4 digit number

Here is a sample of the email body I am attempting to parse with a while loop using the matcher:
Wed Dec 10 10:46:59 2014: Request 68000 was acted upon.
Transaction: Ticket created by cashworth
       Queue: New Orders
     Subject: Service Disconnect Ticket: Test Account LLC
       Owner: Nobody
  Requestors: cashworth@somedomain.net
      Status: new


Requestor: Clay Ashworth <cashworth@somedomain.net>
CustomField.{Customer Number}:TES002

Service Items for Termination:

Ref#:0000
Product: Test Product
Quantity: 1
Total MRC: 0.00
Item Description: test product
Service Location(s):
Some Location Test

Last Date of Service: 2014-12-31 00:00:00

Below is a Code Sample of the Patter and Matcher portion of the Class. The intent being to find a match to the desired string 'REF#:xxxx', strip out only the number portion of the string and then do a SOQL query against a customer object ServiceLineItem__c. where the field Disconnect_Ticket__c can be updated with a variable derived earlier in the class (ticket) and then added to a list of SObjects for a bulk update.
 
//Pattern-Matcher to find ref numbers
        		Pattern RefP = Pattern.compile('REF#:[0-9]{4}');
        		
        		Matcher RefM = RefP.matcher(email.plaintextbody);     		
        		
        		//Loop through the matches	
        		while (RefM.find()) {
        			
	       			ref = RefM.group().right(4);
        			system.debug(ref);
        		
        		//Build list of Service Line Items with ref numbers and Lookup ref numbers and update with ticket number
	
					if(ref != null) {
        				ServiceLineItem__c sli = [select Id, CIS_Id__c from ServiceLineItem__c where CIS_Id__c = :ref limit 1];
        					if(sli != null) {
        						sli.Disconnect_Ticket__c = ticket;
        						sliList.add(sli);
        					}
        					
					}
					
        		}
        			
        	}

        		
        	//Update the Service Line Items with the disconnect ticket number
        	if(sliList != null) {
        			
        		update sliList;
        			
        	}

I am having difficulty getting the REGEX to match the desisred string and could use some assistance.

Thx

 
I am looking for a little guidance on my REGEX statement for a Patter/Matcher Class that extracts a specific string from the body of a plain text email.

The desired match should be as follows:
REF#:xxxx 
where xxxx represents a 4 digit number

Here is a sample of the email body I am attempting to parse with a while loop using the matcher:
Wed Dec 10 10:46:59 2014: Request 68000 was acted upon.
Transaction: Ticket created by cashworth
       Queue: New Orders
     Subject: Service Disconnect Ticket: Test Account LLC
       Owner: Nobody
  Requestors: cashworth@somedomain.net
      Status: new


Requestor: Clay Ashworth <cashworth@somedomain.net>
CustomField.{Customer Number}:TES002

Service Items for Termination:

Ref#:0000
Product: Test Product
Quantity: 1
Total MRC: 0.00
Item Description: test product
Service Location(s):
Some Location Test

Last Date of Service: 2014-12-31 00:00:00

Below is a Code Sample of the Patter and Matcher portion of the Class. The intent being to find a match to the desired string 'REF#:xxxx', strip out only the number portion of the string and then do a SOQL query against a customer object ServiceLineItem__c. where the field Disconnect_Ticket__c can be updated with a variable derived earlier in the class (ticket) and then added to a list of SObjects for a bulk update.
 
//Pattern-Matcher to find ref numbers
        		Pattern RefP = Pattern.compile('REF#:[0-9]{4}');
        		
        		Matcher RefM = RefP.matcher(email.plaintextbody);     		
        		
        		//Loop through the matches	
        		while (RefM.find()) {
        			
	       			ref = RefM.group().right(4);
        			system.debug(ref);
        		
        		//Build list of Service Line Items with ref numbers and Lookup ref numbers and update with ticket number
	
					if(ref != null) {
        				ServiceLineItem__c sli = [select Id, CIS_Id__c from ServiceLineItem__c where CIS_Id__c = :ref limit 1];
        					if(sli != null) {
        						sli.Disconnect_Ticket__c = ticket;
        						sliList.add(sli);
        					}
        					
					}
					
        		}
        			
        	}

        		
        	//Update the Service Line Items with the disconnect ticket number
        	if(sliList != null) {
        			
        		update sliList;
        			
        	}

I am having difficulty getting the REGEX to match the desisred string and could use some assistance.

Thx

 
I have a custom object called Charter with a lookup relationship with accounts. I have created an apex trigger in opportunity to create Charter records. I am not getting any errors with the trigger but the records are also not created.

Does anyone knows why is this happening or is what I am trying to do even possible?
Can anyone give me some direction on a service class I'm trying to write?  Essentially, I have a custom object called Transactions__c, which looks up to another custom object called PD_Data__c, which in turn looks up to the Account.  When a field called Amount_Due__c on a Transaction record is updated to a value greater than 0, I want to set the stage on any open oppty on the same Account to closed won. See illustration below:

User-added image

I've written some of the code, but I'm kinda stuck and I'm not sure if I'm even on the right track.

public with sharing class CloseOutOpptyService {

    public static list<Transactions__c> filterAmountDueChange(map<id, Transactions__c> oldMap, list<Transactions__c> newList) {
    	list<Transactions__c> temp=new list<Transactions__c>();
    	for (Transactions__c trxs : newList){
 			if ( 
 			      (oldMap.get(trxs.id).pd_amount_due__c == null || oldMap.get(trxs.id).pd_amount_due__c == 0) 
 			      && (trxs.pd_amount_due__c > 0)
 			      ){
 			temp.add(trxs);
 			}
    		
    	}
    	return temp;  
    }
    
	public static Set<Id> closeOpptys (list<Transactions__c> trxAccount) {        
		list<Transactions__c> trxAccountIds = [SELECT Id, Parent_PD_Data__r.SFDC_Account__r.Id FROM Transactions__c Where Id in: trxAccount];

		Set<Id> accountIds = new Set<Id>();
		for(Transactions__c trxAccountId : trxAccountIds) {
       		accountIds.add(trxAccountId.Parent_PD_Data__r.SFDC_Account__c);
		}

		return accountIds;




Any help would be greatly appreciated.  Thanks!







Hello,

So I'm a newbie to writing triggers and need help on wrting a test class so I can deploy to production...here is my situation:

I have a trigger that updates a hidden field on an Account record that was needed in order to track changes on a seperate field that is a formula field. When the field value changes, the trigger runs and captures the previous value in the Account History. Here is my trigger code in my sandbox:

trigger BusinessRatingChange on Account (before update)
{
    for(Account a:Trigger.new)
    {
        if(system.trigger.OldMap.get(a.Id).Business_Rating__c != system.trigger.NewMap.get(a.Id).Business_Rating__c)
        {
            a.Business_Rating_History__c = a.Business_Rating__c;
            }
            }
            }

This trigger works perfect in my sandbox, but with my limited knowledge on triggers and writing test classes...is there anyone out there that can assist me, or guide me to where I can understand better?? Bad news is i need to get this deployed QUICK!!!  :(

Thanks so much!!!

Eric