• Joey Ho
  • NEWBIE
  • 9 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 11
    Replies
Hi All, 

This is not a problem as such but rather something that I do not quite understand.
I have writted an apex and visualforce code that has operated correctly but I do not undertand why! Hope someone can clarify my misunderstanding?

I have a apex Controller class that has a inner custom wrapper class of objects that I called "AssetLine".

To make things simple, I used maps<string, AssetLine> where the key is the unique string name for each AssetLine.

Now I created a visualforce page which dumps out using <Apex:repeat> a LIST of AssetLine which obviously comes from the Map I created earlier. In this visualforce page contains inputText fields which allow me to manimulate the AssetLine individually and update the instance dynamically.

The ODD THING IS THIS: whenever I update the values in the inputText fields, these fields automatically update the corresponding Map<string, AssetLine> without me having to write any such code in the apex controller telling the LIST to update the corresponding AssetLine in the Map...

How is this possible that the MAP is automatically updated??!!!? 

Thanks.
Regards,
Joey Ho

Hi all,

 

I have a weird problem where I am querying from my Sandbox evnironment the following using the LIKE operation using the following snippet of code:

 

string s = '%__c'; 
list<CaseHistory> hist = new list<CaseHistory>();
hist = [Select Field From CaseHistory Where Field like :s Order by Field Limit 10];

 I get a erro as follows:

 

Compile error at line 3 column 5
invalid operator on id field

 

I have no idean where I am going wrong but I seem to be following the query syntax correctly?

Is there a bug in Sandbox query with the LIKE operator?

 

Thanks for your help!

  • September 12, 2013
  • Like
  • 0

Hi All, 

 

This is driving me nuts. I can understand how to write a test class for 'customer' inbound message handlers but how do I start off righting a test method and creating a inbound test message for testing the standard Email-To-Case service that salesforce provides???

 

I'm sure it is bluntly obviously but can not figure it out!

 

Actually.... thinking about it, is creating a Case the same as testing inbound email-to-case so therefore I wouldn't need to create any such test method other than a new case?

 

Thanks.

REgards,

Joey.

Hi,

 

I have a pageBlockTable that outputs a list of custom items that I created in APEX. One of the columns extract a very long string which I only want to show part of the string the Table instead of the entire string block which makes the table big and huge.

 

I'd like to maybe display the first 3-5 lines on this block and if the user wishes to see more than they will need to click on the row to open a new window to the record.

 

Here is the VF Table code:

 

    <apex:outputPanel layout="block" style="overflow:auto;height:500px" >
        <apex:pageBlock id="timeline" title="Timeline" >
            <apex:pageBlockTable value="{!Emessages}" var="e" rendered="{!NOT(ISNULL(Emessages))}"> 
                <apex:column value="{!e.eventID}">
                    <apex:facet name="header">ID</apex:facet>
                </apex:column>  
                
                <apex:column value="{!e.eventType }">
                    <apex:facet name="header">Type</apex:facet>
                </apex:column>  
                       
                <apex:column value="{!e.eventMainBody}" > 
                    <apex:facet name="header">Main Body</apex:facet>
                </apex:column> 
                            
                <apex:column value="{!e.eventFromOrCreatedBy}"> 
                    <apex:facet name="header">Created By or From</apex:facet>
                </apex:column> 
                            
                <apex:column value="{!e.eventCreatedDate}">     
                    <apex:facet name="header">Created Date</apex:facet>
                </apex:column> 
                                   
            </apex:pageBlockTable>    
        </apex:pageBlock>
    </apex:outputPanel>

 

The line 

<apex:column value="{!e.eventMainBody}" > 

 

is the line that dumps the entire block of string which typically is a dump of the TextBody of an EmailMessage record (very long text at times!)

 

Here is what it looks like: example of VF table

 

How do I resize the column to only display a few lines instead of everything?

 

Many thanks all.

Regards,

Joey Ho.

 

Hi,

 

I have a requirement where a visualforce page with standard controller of 'Case' displays a another 'Case' record within the same page using apex:iframe however this iframe can only be read-only, i.e. links within the iframe can't be clicked.

 

I know that we can set the apex:page to readonly="true" but that would than stop my engineers from being able to edit the content on that VF page.

 

How do I just make part of the page (or specifically the iframe component) only read-only within the VF page?

 

Thanks for your help.

 

Regards.

Joey.

Hi All,

 

this may be a silly question but I am going to ask and confirm my understanding of the order in which triggers are executed when a list of records are inserted.

 

This is my current proposed plan on my code in pseudo:

 

  • A list emal message records are inserted into Salesforce (relating to one case), i.e. more than one email inserted at the same time and updated on case - which I know is rare but it's good practice to bulkify my trigger.
  • When the list of email inserted, a BEFORE INSERT trigger and fired whick updates a string COMMON FIELD on the CASE.
  • An AFTER INSERT than attempts to call a class method that sends out SingleEmailMessage (that includes this COMMON FIELD in the email message) to the Case Team updating everyone  on the new Email Message Record that is inserted.

My question is this:

 

If the it so happens that we have a list of Email Records inserted at the same time will:

 

a) the list execute each Email Message Record individually, i.e. run the particuarly Email Message Record until it completes the BEFORE & AFTER INSERT Code meaning my COMMON FIELD that is being updated by every insert is unique to every new Email Message record?

 

b) Or does the list execute the inserts of the Email Message record list all at the same time such that it fires BEFORE INSERT first on all records, than fire the AFTER INSERT after which will evidentily cause issues where the COMMON FIELD when its being updated?

 

Thanks for your help!

 

For anyone interested, the following Code is a trigger that send an email update to Case Owner, Case Contact and Case Team (users and contacts) in the Case everytime Case has been updated with an new Email-to-Case Message.

 

I have no idea why my list of Attachments is empty in the following lines of code??? The debug logs return 0 although my email test has attachments in the email and I can see this when going to the email Message record in the case.

 

list<Attachment> allAttachmentsInEmail = [Select Name, ContentType, Body From Attachment Where parentId =:e.id];


system.debug('---->number of attachments: ' + allAttachmentsInEmail.size());

 

Hope someone knows if I did something silly with my query?

 

Full code for those interested in using it.

 

trigger SendEmailUpdateOnEmailMessageForCase on EmailMessage (before insert, after insert) { 

	try{	
		for(EmailMessage e: trigger.new){
		
			//system.debug('@@@###$$$%%^^ Inserted email' + 'trigger size = ' + trigger.new.size());
			string caseId = string.valueof(e.ParentId);
						
			if(caseId.startsWith('500')){	//This Email Message is for a Case 
				
				//Look up Case Details
				Case theCase = [SELECT Id, ContactId, OwnerID, Subject, Priority, IsClosed, EntitlementId, Description, CreatedDate, CaseNumber, AccountId, Email_Message_Body_Copy_For_Template__c  FROM Case WHERE Id =: caseId Limit 1];			
				
				if(trigger.isBefore){	
					if(e.TextBody != theCase.Email_Message_Body_Copy_For_Template__c){
						theCase.Email_Message_Body_Copy_For_Template__c = e.TextBody; //This field updates the Case so that we can dynamically merge field in the Template 'CASE_ICT_Customer_New_Case_Update'
						try{
							update theCase;
						}catch(dmlexception e2){
							system.debug('Problem with udpating Case sObject in SendEmailUpdateOnEmailMessageForCase: ' + e2.getMessage());
						}
					}				
					
				}else if(trigger.isAfter){
					
					system.debug('***** the email Id is ' + e.id);
					Set<ID> toEmailId = new Set<ID>();;
					toEmailId.add(theCase.OwnerId);
					//Get Ids of the Case Team Members
					List<CaseTeamMember> member = [Select MemberId From CaseTeamMember where ParentId =:caseId];
					
					for(CaseTeamMember m: member){
						toEmailId.add(m.MemberId);			
					}
					//system.debug('%%%List of Members %%%%% ' + toEmailId);
					
					//Get contact and user list from the set of Id's			
					List<Contact> listContactEmails = [SELECT Email FROM Contact Where ID IN: toEmailId];
					List<User> listUserEmails =  [SELECT Email FROM User Where ID IN: toEmailId]; 
		
					//Get all email address in unique set
					Set<String> setOfContactEmails = new Set<String>();
					Set<String> setOfUserEmails = new Set<String>();
					for(Contact c: listContactEmails){
						setOfContactEmails.add(c.Email);
					}
					for(User u: listUserEmails){
						setOfUserEmails.add(u.Email);
					}
								
					list<String> listOfEmails = new list<String>();
					listOfEmails.addAll(setOfContactEmails);
					listOfEmails.addAll(setOfUserEmails);
					listOfEmails.sort();		
				
					//Create the email message body
					Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
					EmailTemplate emailTemp = [Select id From EmailTemplate Where developerName = 'CASE_ICT_Customer_New_Case_Update' Limit 1]; //A email template for Cases
					email.orgWideEmailAddressId = '0D2D0000000GnPW';	//Our Org Wide default
					email.replyTo = 'support.test@ictnetworks.com.au';
		      		        email.saveAsActivity = false;
					email.settargetObjectId(theCase.ContactId);
					email.setCcAddresses(listOfEmails);
					email.setTemplateId(emailTemp.Id);
					email.setwhatId(theCase.Id);
					
					//Check for Attachments							
					system.debug('H$H$H$H$H Attachment Flag: ' + e.HasAttachment);
					if(e.HasAttachment){
						//Create list of Messageing email File Attachments
						list<Messaging.EmailFileAttachment> fileAttachments = new list<Messaging.EmailFileAttachment>();
						//Query all child Attachments relating to this email Id
					        list<Attachment> allAttachmentsInEmail = [Select Name, ContentType, Body From Attachment Where parentId =:e.id]; 
						//Add to list of Attachments to email
						system.debug('---->number of attachments: ' + allAttachmentsInEmail.size());
						for(Attachment a: allAttachmentsInEmail){
							Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
							efa.setFileName(a.Name);
							efa.setBody(a.Body);
							fileAttachments.add(efa);
						}
						email.setFileAttachments(fileAttachments);
					}	
					
					system.debug('@@@@@targetI ObjectID = ' + email.targetObjectId);
					system.debug('@@@@@emailTemp.Id = ' + emailTemp.Id);
					system.debug('@@@@@whatId = ' + email.whatId);
					//email.setPlainTextBody('Hello!'); 
					//email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); 
					//system.debug(email); 
					//Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
										
				}
			}
		}
	} catch (exception e){
		System.debug('The following exception has occurred: ' + e.getMessage());
	}		

}

 

 

 

Hi All, 

 

There are plenty of code online that looks at inserting Attachments into Salesforce objects however I have a requirement to do something a little different to this.

 

Whenever a file is manually uploaded onto a Case object as an Attachment on the Case record, I would like to have a trigger that inserts the same Attachment into the Chatter Feed as a File on the same Case record. Although I can write the trigger of picking up the Attachments fine, I do not know where to start in APEX if I wanted to insert this Chatter Feed File using the trigger.

 

Could someone please direct me on what standared objects and calls I should be making to insert this Feed File?

 

Many thanks!

Hi All, 

 

I am having problems when I am running thi VisualForce page.

 

The error I am getting is "Unknown property 'AssetStandardController.entitlement'".

 

I am wondering if anyone has come across this problem or can identify why my code is not working?

 

<apex:page standardController="Asset" showHeader="true" > <apex:messages />
   <apex:form >
   <apex:detail relatedList="false" inlineEdit="true"/> 

  <apex:pageBlock> 
       <apex:pageblockTable title="Entitlements" value="{!entitlement}" var="e">
           <apex:column value="{!e.Name}"/> 

      </apex:pageblockTable> 
  </apex:pageBlock>
</apex:page>

 However if I was to get rid of the pageBlock code and use "<apex:relatedList list="Entitlements"/>" this works fine.????

 

Thanks for your help

Hi All,

 

this may be a silly question but I am going to ask and confirm my understanding of the order in which triggers are executed when a list of records are inserted.

 

This is my current proposed plan on my code in pseudo:

 

  • A list emal message records are inserted into Salesforce (relating to one case), i.e. more than one email inserted at the same time and updated on case - which I know is rare but it's good practice to bulkify my trigger.
  • When the list of email inserted, a BEFORE INSERT trigger and fired whick updates a string COMMON FIELD on the CASE.
  • An AFTER INSERT than attempts to call a class method that sends out SingleEmailMessage (that includes this COMMON FIELD in the email message) to the Case Team updating everyone  on the new Email Message Record that is inserted.

My question is this:

 

If the it so happens that we have a list of Email Records inserted at the same time will:

 

a) the list execute each Email Message Record individually, i.e. run the particuarly Email Message Record until it completes the BEFORE & AFTER INSERT Code meaning my COMMON FIELD that is being updated by every insert is unique to every new Email Message record?

 

b) Or does the list execute the inserts of the Email Message record list all at the same time such that it fires BEFORE INSERT first on all records, than fire the AFTER INSERT after which will evidentily cause issues where the COMMON FIELD when its being updated?

 

Thanks for your help!

 

Hi All, 

This is not a problem as such but rather something that I do not quite understand.
I have writted an apex and visualforce code that has operated correctly but I do not undertand why! Hope someone can clarify my misunderstanding?

I have a apex Controller class that has a inner custom wrapper class of objects that I called "AssetLine".

To make things simple, I used maps<string, AssetLine> where the key is the unique string name for each AssetLine.

Now I created a visualforce page which dumps out using <Apex:repeat> a LIST of AssetLine which obviously comes from the Map I created earlier. In this visualforce page contains inputText fields which allow me to manimulate the AssetLine individually and update the instance dynamically.

The ODD THING IS THIS: whenever I update the values in the inputText fields, these fields automatically update the corresponding Map<string, AssetLine> without me having to write any such code in the apex controller telling the LIST to update the corresponding AssetLine in the Map...

How is this possible that the MAP is automatically updated??!!!? 

Thanks.
Regards,
Joey Ho

Hi all,

 

I have a weird problem where I am querying from my Sandbox evnironment the following using the LIKE operation using the following snippet of code:

 

string s = '%__c'; 
list<CaseHistory> hist = new list<CaseHistory>();
hist = [Select Field From CaseHistory Where Field like :s Order by Field Limit 10];

 I get a erro as follows:

 

Compile error at line 3 column 5
invalid operator on id field

 

I have no idean where I am going wrong but I seem to be following the query syntax correctly?

Is there a bug in Sandbox query with the LIKE operator?

 

Thanks for your help!

  • September 12, 2013
  • Like
  • 0

Hi,

 

I have a pageBlockTable that outputs a list of custom items that I created in APEX. One of the columns extract a very long string which I only want to show part of the string the Table instead of the entire string block which makes the table big and huge.

 

I'd like to maybe display the first 3-5 lines on this block and if the user wishes to see more than they will need to click on the row to open a new window to the record.

 

Here is the VF Table code:

 

    <apex:outputPanel layout="block" style="overflow:auto;height:500px" >
        <apex:pageBlock id="timeline" title="Timeline" >
            <apex:pageBlockTable value="{!Emessages}" var="e" rendered="{!NOT(ISNULL(Emessages))}"> 
                <apex:column value="{!e.eventID}">
                    <apex:facet name="header">ID</apex:facet>
                </apex:column>  
                
                <apex:column value="{!e.eventType }">
                    <apex:facet name="header">Type</apex:facet>
                </apex:column>  
                       
                <apex:column value="{!e.eventMainBody}" > 
                    <apex:facet name="header">Main Body</apex:facet>
                </apex:column> 
                            
                <apex:column value="{!e.eventFromOrCreatedBy}"> 
                    <apex:facet name="header">Created By or From</apex:facet>
                </apex:column> 
                            
                <apex:column value="{!e.eventCreatedDate}">     
                    <apex:facet name="header">Created Date</apex:facet>
                </apex:column> 
                                   
            </apex:pageBlockTable>    
        </apex:pageBlock>
    </apex:outputPanel>

 

The line 

<apex:column value="{!e.eventMainBody}" > 

 

is the line that dumps the entire block of string which typically is a dump of the TextBody of an EmailMessage record (very long text at times!)

 

Here is what it looks like: example of VF table

 

How do I resize the column to only display a few lines instead of everything?

 

Many thanks all.

Regards,

Joey Ho.

 

Hi,

 

I have a requirement where a visualforce page with standard controller of 'Case' displays a another 'Case' record within the same page using apex:iframe however this iframe can only be read-only, i.e. links within the iframe can't be clicked.

 

I know that we can set the apex:page to readonly="true" but that would than stop my engineers from being able to edit the content on that VF page.

 

How do I just make part of the page (or specifically the iframe component) only read-only within the VF page?

 

Thanks for your help.

 

Regards.

Joey.

Hi All,

 

this may be a silly question but I am going to ask and confirm my understanding of the order in which triggers are executed when a list of records are inserted.

 

This is my current proposed plan on my code in pseudo:

 

  • A list emal message records are inserted into Salesforce (relating to one case), i.e. more than one email inserted at the same time and updated on case - which I know is rare but it's good practice to bulkify my trigger.
  • When the list of email inserted, a BEFORE INSERT trigger and fired whick updates a string COMMON FIELD on the CASE.
  • An AFTER INSERT than attempts to call a class method that sends out SingleEmailMessage (that includes this COMMON FIELD in the email message) to the Case Team updating everyone  on the new Email Message Record that is inserted.

My question is this:

 

If the it so happens that we have a list of Email Records inserted at the same time will:

 

a) the list execute each Email Message Record individually, i.e. run the particuarly Email Message Record until it completes the BEFORE & AFTER INSERT Code meaning my COMMON FIELD that is being updated by every insert is unique to every new Email Message record?

 

b) Or does the list execute the inserts of the Email Message record list all at the same time such that it fires BEFORE INSERT first on all records, than fire the AFTER INSERT after which will evidentily cause issues where the COMMON FIELD when its being updated?

 

Thanks for your help!

 

For anyone interested, the following Code is a trigger that send an email update to Case Owner, Case Contact and Case Team (users and contacts) in the Case everytime Case has been updated with an new Email-to-Case Message.

 

I have no idea why my list of Attachments is empty in the following lines of code??? The debug logs return 0 although my email test has attachments in the email and I can see this when going to the email Message record in the case.

 

list<Attachment> allAttachmentsInEmail = [Select Name, ContentType, Body From Attachment Where parentId =:e.id];


system.debug('---->number of attachments: ' + allAttachmentsInEmail.size());

 

Hope someone knows if I did something silly with my query?

 

Full code for those interested in using it.

 

trigger SendEmailUpdateOnEmailMessageForCase on EmailMessage (before insert, after insert) { 

	try{	
		for(EmailMessage e: trigger.new){
		
			//system.debug('@@@###$$$%%^^ Inserted email' + 'trigger size = ' + trigger.new.size());
			string caseId = string.valueof(e.ParentId);
						
			if(caseId.startsWith('500')){	//This Email Message is for a Case 
				
				//Look up Case Details
				Case theCase = [SELECT Id, ContactId, OwnerID, Subject, Priority, IsClosed, EntitlementId, Description, CreatedDate, CaseNumber, AccountId, Email_Message_Body_Copy_For_Template__c  FROM Case WHERE Id =: caseId Limit 1];			
				
				if(trigger.isBefore){	
					if(e.TextBody != theCase.Email_Message_Body_Copy_For_Template__c){
						theCase.Email_Message_Body_Copy_For_Template__c = e.TextBody; //This field updates the Case so that we can dynamically merge field in the Template 'CASE_ICT_Customer_New_Case_Update'
						try{
							update theCase;
						}catch(dmlexception e2){
							system.debug('Problem with udpating Case sObject in SendEmailUpdateOnEmailMessageForCase: ' + e2.getMessage());
						}
					}				
					
				}else if(trigger.isAfter){
					
					system.debug('***** the email Id is ' + e.id);
					Set<ID> toEmailId = new Set<ID>();;
					toEmailId.add(theCase.OwnerId);
					//Get Ids of the Case Team Members
					List<CaseTeamMember> member = [Select MemberId From CaseTeamMember where ParentId =:caseId];
					
					for(CaseTeamMember m: member){
						toEmailId.add(m.MemberId);			
					}
					//system.debug('%%%List of Members %%%%% ' + toEmailId);
					
					//Get contact and user list from the set of Id's			
					List<Contact> listContactEmails = [SELECT Email FROM Contact Where ID IN: toEmailId];
					List<User> listUserEmails =  [SELECT Email FROM User Where ID IN: toEmailId]; 
		
					//Get all email address in unique set
					Set<String> setOfContactEmails = new Set<String>();
					Set<String> setOfUserEmails = new Set<String>();
					for(Contact c: listContactEmails){
						setOfContactEmails.add(c.Email);
					}
					for(User u: listUserEmails){
						setOfUserEmails.add(u.Email);
					}
								
					list<String> listOfEmails = new list<String>();
					listOfEmails.addAll(setOfContactEmails);
					listOfEmails.addAll(setOfUserEmails);
					listOfEmails.sort();		
				
					//Create the email message body
					Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
					EmailTemplate emailTemp = [Select id From EmailTemplate Where developerName = 'CASE_ICT_Customer_New_Case_Update' Limit 1]; //A email template for Cases
					email.orgWideEmailAddressId = '0D2D0000000GnPW';	//Our Org Wide default
					email.replyTo = 'support.test@ictnetworks.com.au';
		      		        email.saveAsActivity = false;
					email.settargetObjectId(theCase.ContactId);
					email.setCcAddresses(listOfEmails);
					email.setTemplateId(emailTemp.Id);
					email.setwhatId(theCase.Id);
					
					//Check for Attachments							
					system.debug('H$H$H$H$H Attachment Flag: ' + e.HasAttachment);
					if(e.HasAttachment){
						//Create list of Messageing email File Attachments
						list<Messaging.EmailFileAttachment> fileAttachments = new list<Messaging.EmailFileAttachment>();
						//Query all child Attachments relating to this email Id
					        list<Attachment> allAttachmentsInEmail = [Select Name, ContentType, Body From Attachment Where parentId =:e.id]; 
						//Add to list of Attachments to email
						system.debug('---->number of attachments: ' + allAttachmentsInEmail.size());
						for(Attachment a: allAttachmentsInEmail){
							Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
							efa.setFileName(a.Name);
							efa.setBody(a.Body);
							fileAttachments.add(efa);
						}
						email.setFileAttachments(fileAttachments);
					}	
					
					system.debug('@@@@@targetI ObjectID = ' + email.targetObjectId);
					system.debug('@@@@@emailTemp.Id = ' + emailTemp.Id);
					system.debug('@@@@@whatId = ' + email.whatId);
					//email.setPlainTextBody('Hello!'); 
					//email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); 
					//system.debug(email); 
					//Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
										
				}
			}
		}
	} catch (exception e){
		System.debug('The following exception has occurred: ' + e.getMessage());
	}		

}

 

 

 

Hi All, 

 

There are plenty of code online that looks at inserting Attachments into Salesforce objects however I have a requirement to do something a little different to this.

 

Whenever a file is manually uploaded onto a Case object as an Attachment on the Case record, I would like to have a trigger that inserts the same Attachment into the Chatter Feed as a File on the same Case record. Although I can write the trigger of picking up the Attachments fine, I do not know where to start in APEX if I wanted to insert this Chatter Feed File using the trigger.

 

Could someone please direct me on what standared objects and calls I should be making to insert this Feed File?

 

Many thanks!

Hi All, 

 

I am having problems when I am running thi VisualForce page.

 

The error I am getting is "Unknown property 'AssetStandardController.entitlement'".

 

I am wondering if anyone has come across this problem or can identify why my code is not working?

 

<apex:page standardController="Asset" showHeader="true" > <apex:messages />
   <apex:form >
   <apex:detail relatedList="false" inlineEdit="true"/> 

  <apex:pageBlock> 
       <apex:pageblockTable title="Entitlements" value="{!entitlement}" var="e">
           <apex:column value="{!e.Name}"/> 

      </apex:pageblockTable> 
  </apex:pageBlock>
</apex:page>

 However if I was to get rid of the pageBlock code and use "<apex:relatedList list="Entitlements"/>" this works fine.????

 

Thanks for your help

Can someone tell me the obvious and silly mistake I am making?

 

trigger GoItemfromAsset on SchedInt__c (before update) { if(Trigger.isUpdate) { for(SchedInt__c s : Trigger.new) { if (s.ItemFromAsset__c==true) { ItemfromAsset.createItemfromAsset(); } } }}

 

 

 

The class is as follows: 

 

 

public with sharing class ItemfromAsset {
    
    public static Map<id, Asset> getAssetToCreateItem() {
        
        DateTime dT = System.now();
        String myDate = dT.format('d');
        Decimal myDay = decimal.valueOf(myDate);
        
        List<Asset> asts =  [select id, name, AccountId, Billing_Product__c, Quantity 
                                from asset 
                                where Day__c = :myDay
                                and Status = 'Active'];
        Map<id, Asset> result = new Map<id, Asset>();
        for (Asset ast : asts) {
            result.put(ast.id, ast);
        }
        return result;
    }
    

    public static void createItemsfromAsset() {
        
        DateTime dT = System.now();
        String myDate = dT.format('d');
        Decimal myDay = decimal.valueOf(myDate);
        
        Map<id, Asset> AssetIdToItem = getAssetToCreateItem();
        system.debug('got AssetIdToItem map of size ' + AssetIdToItem.size());
        
        Map<id, Asset> idToAsset = new Map<id,Asset>();
        
        List<Item__c> Items = new List<Item__c>(); 
        
        List<Asset> assets = [select id, name, AccountId, Billing_Product__c, Quantity 
                                from asset 
                                where Day__c = :myDay 
                                and Status = 'Installed'];
        System.debug('***** accounts returned = ' + assets.size());
        
        insert items;
        
        Map<id,id> astToItem = new Map<id, id>();
        System.debug('***** about to iterate throught the items');
        
        for (Item__c currItem : items) {
            astToItem.put(currItem.asset__c, currItem.id);
            System.debug('***** accid/invid = ' + currItem.account__c + '/' + currItem.id);
        }
        }
        }

 

 

 

Message Edited by Ross James on 03-01-2010 07:54 PM
Message Edited by Ross James on 03-01-2010 07:55 PM