• reema_agarwal
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 14
    Replies

Hello

 

I have written a trigger on asset name that it should be unique with no duplicate values I want to wrrite a test class 4 it can someone please help me. 

 

The trigger is as below:

 

trigger NameTrigger on Asset (before insert)
{
  list <Asset> al = new List <Asset>();
  al = [select Name from Asset];
  if(Trigger.isInsert)   
  {
     For(integer i=0;i<al.size();i++)
     {
       for(Asset a2 : Trigger.New)
         {
           if(al[i].Name == a2.Name)
             {
               a2.Name.addError('This value already Exist');
             }
         }
     }
   }
}

 

Thanks

Hello

 

I have written the code below for case escalation i am getting an exception for it can someone please help me out

 

Thanks!

 

Code is :

 

global class CaseEscalation  implements  Database.Batchable<SObject> 
{
global CaseEscalation()
{
}  
     global Database.QueryLocator start(Database.BatchableContext  ctx)
     {
         return Database.getQueryLocator([SELECT  CaseNumber, CreatedDate,Status FROM Case where CreatedDate<Today and Status!='Closed']);  
     }
      
      
     global void execute(Database.BatchableContext ctx, List<Sobject> scope)
     {
       
       List<Case> ca = (List<Case>)scope;
       //List <Case> ca =  new List<Case>();
       //for(SObject so :scope)
       //{
       //    Case c = (Case)so;
        //   ca.add(c);
       //}    
       System.debug('checking======='+ca);
       for(Case c : ca)
       {                      
           // Double Days = Math.Floor((System.now().getTime()  - c.CreatedDate.getTime())/ (1000.0*60.0*60.0*24));                       
            //if(Days > 1  &&  c.Status != 'Closed' )
             //{
                System.Debug(c);
                 String emailMessage = 'The case  ' + c.CaseNumber + ' has been ecalated ' + ' Please look into the case ' + 'Thankyou';
                 Messaging.SingleEmailMessage mail  =   new Messaging.SingleEmailMessage();
                 String[] toAddresses = new String[] {'reems.agarwal3@gmail.com'};
                 mail.setToAddresses(toAddresses);
                 mail.setSubject('Case Escalation');
                 mail.setPlainTextBody(emailMessage);
                 Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ mail });
                 c.Status = 'Escalated';
            // }
        }
if(ca.size()>0)
        update ca;
           }
   
    global void finish(Database.BatchableContext ctx)
    {
    }


}

 

I am getting the following exception:

 

Apex script unhandled exception by user/organization: 005U0000000DmS9/00DU0000000HTCU

Failed to process batch for class 'CaseEscalation' for job id '707U0000004bzCe'

caused by: System.LimitException: Too many Email Invocations: 11

Class.CaseEscalation.execute: line 35, column 1

Hello

 

I have created a vf page named asset history. in that when i search a particular asset it shows me fields like asset name,status and contact name.

 

I want to write a tigger on the fields status and contact name such that whatever changes i make in these fields it should show me an entry of it in the vf page after i search that particular asset.

 

can someone please help me.

 

Thanks!

Hello

 

I want to create a non editable visualforce page named asset history.In that page i want a look up field form which when we search the particular asset it should show the fields like Name,Status,Contact.Name.

 

Also i want to show the field caseNumber in that  page from the case object.

The relationship between case and asset is that there is an asset lookup in the case object.

 

can someone please help me.

 

Thanks!

Hello

 

I have 2 lookup fields Contact and Asset in the cases object.

When i select a contact only the Assets he owns should be shown in the aseet lookup.

Can someone please help me with this.

 

Thanks!

 

Hello

 

Initially i tried to escalate cases using workflow and escalation rules but that is not working so now  I am trying to escalate the cases using batch apex in which the conditions are like:

Date/Time opened is more then one hour and still if the status is not closed then escalate it.

I have tried to write a code but i am getting an error can someone please help me to remove the error and also help me with the code.

 

global class CaseEscalation  implements  Database.Batchable<sObject> {
 global Database.QueryLocator start(Database.BatchableContext  BC){
         return Database.getQueryLocator([SELECT  CaseNumber, CreatedDate,Status                                         
                                             FROM Case]);  
   }
      global void execute(Database.BatchableContext ctx, List<Sobject>scope){
       List <Case> ca = (List<Case>)scope;
            for(Integer  i = 0; i < ca.size(); i++){
             if(System.Today() -  ca.CreatedDate >=1  &&  ca.Status!='Closed' )
             {
              String emailMessage = 'The case  '
                       + Case.CaseNumber
                        + ' has been ecalated '
                        + ' Please look into the case '
                       + 'Thankyou';
              Messaging.SingleEmailMessage mail  =   new Messaging.SingleEmailMessage();
             String[] toAddresses = new String[] {'reems.agarwal3@gmail.com'};
             mail.setToAddresses(toAddresses);
             mail.setSubject('Case Escalation');
             mail.setPlainTextBody(emailMessage);
             Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ mail });
             Case.Status = 'Escalated';
     }
    }
   }
global void finish(Database.BatchableContext ctx){
       }
    }  

This is the error i am getting
Error: Compile Error: Expression cannot be assigned at line -1 column -1    

I want a list all the objects present in my salesforce application in a java application after i login into SFDC from a java api.

can someone please help me

 

Thanks!

hello,

 

I want to create a visualforce page named history of assets. i want a lookup field to search a particular asset. when i search that  asset it should show me the history related to it in a list view with fields like asset name,contact id,status,case no.

 

Any cases logged for the asset, Change of the contact owning the asset, Change in the asset status in the respective objects should be shown on this page when the particular asset is entered in the lookup.

 

Can someone please help me with this.I am new to visualforce and apex

 

Thanks!

 

I have fields like case status and date/time opened in the cases object.

If the date/time opened is more then one hour and still the status is new and the status is not approved or rejected the case should get escalated.

On escalation the status should change to escalated and the user should get a mail of escalated case assignment.

 

I am new to apex can someone please help me to write a batch apex for this.

 

Thanks!

I have made a lookup field of contacts in ma asset object.

I have made a default contact as No user in ma contacts as contact is a compulsory field in assets.

whenever i add a contact and the value is not 'No User' the status of asset should change to 'assigned' from the picklist.

when i free dat asset from that contact or make it as No User the status the status should change from assigned  to instock.

Can Someone Please help me.

 

 

trigger updateAsset on Asset (after insert, after update) {
if(trigger.new[0].Name !=null && trigger.new[0].contactid != 'No User'){
Asset assetsOwned= [select Name,status from asset where Name=:trigger.new[0].Name];
assetsOwned.status = 'Assigned';
update assetsOwned;
}
/*if( trigger.isUpdate && trigger.old[0].id !=null && trigger.old[0].id != trigger.new[0].id){
Asset assetsOwnedOld = [select id, status from asset where id=:trigger.old[0].id];
assetsOwnedOld.status = 'Instock';
update assetsOwnedOld;


}*/
}

Hello

I am new to workflows. I want to escalate a case if it is not solved within 2 days for this i have written the following rules

AND( 
NOW() - CreatedDate >= 2, 
NOT( ISPICKVAL( Status ," Closed") ), 
ISPICKVAL( Status ," Approved"), 
ISPICKVAL( Status ," Rejected") 
) 

 

where CreatedDate is the Date/Time opened field. I have activated the workflow still its is not working.Can anyone plz help me.Also if i want to escalate the case within an hr or 10 mins wat should be the Syntax.

 

Thanks!

hello,

 

I have a look up field assets_owned in my contacts object. I want to populate this look up only with those assets whose status is not assigned in the assets object. Can someone please help me.

 

Thanks!

Hello

 

I have created a lookup field named Assets in contact and i want to select more then one asset. Can anyone suggest me how can i do it.

 

Thanks!

Hi

 

I am new to salesforce platform.I need help with triggers.

I have created a look up field in contacts named Assets_owned. whenever a particular asset is selected in assets_owned i want to change the asset status to assigned from the picklist in the assets tab.

 

Thanks!

Hello

 

I have written the code below for case escalation i am getting an exception for it can someone please help me out

 

Thanks!

 

Code is :

 

global class CaseEscalation  implements  Database.Batchable<SObject> 
{
global CaseEscalation()
{
}  
     global Database.QueryLocator start(Database.BatchableContext  ctx)
     {
         return Database.getQueryLocator([SELECT  CaseNumber, CreatedDate,Status FROM Case where CreatedDate<Today and Status!='Closed']);  
     }
      
      
     global void execute(Database.BatchableContext ctx, List<Sobject> scope)
     {
       
       List<Case> ca = (List<Case>)scope;
       //List <Case> ca =  new List<Case>();
       //for(SObject so :scope)
       //{
       //    Case c = (Case)so;
        //   ca.add(c);
       //}    
       System.debug('checking======='+ca);
       for(Case c : ca)
       {                      
           // Double Days = Math.Floor((System.now().getTime()  - c.CreatedDate.getTime())/ (1000.0*60.0*60.0*24));                       
            //if(Days > 1  &&  c.Status != 'Closed' )
             //{
                System.Debug(c);
                 String emailMessage = 'The case  ' + c.CaseNumber + ' has been ecalated ' + ' Please look into the case ' + 'Thankyou';
                 Messaging.SingleEmailMessage mail  =   new Messaging.SingleEmailMessage();
                 String[] toAddresses = new String[] {'reems.agarwal3@gmail.com'};
                 mail.setToAddresses(toAddresses);
                 mail.setSubject('Case Escalation');
                 mail.setPlainTextBody(emailMessage);
                 Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ mail });
                 c.Status = 'Escalated';
            // }
        }
if(ca.size()>0)
        update ca;
           }
   
    global void finish(Database.BatchableContext ctx)
    {
    }


}

 

I am getting the following exception:

 

Apex script unhandled exception by user/organization: 005U0000000DmS9/00DU0000000HTCU

Failed to process batch for class 'CaseEscalation' for job id '707U0000004bzCe'

caused by: System.LimitException: Too many Email Invocations: 11

Class.CaseEscalation.execute: line 35, column 1

Hello

 

I want to create a non editable visualforce page named asset history.In that page i want a look up field form which when we search the particular asset it should show the fields like Name,Status,Contact.Name.

 

Also i want to show the field caseNumber in that  page from the case object.

The relationship between case and asset is that there is an asset lookup in the case object.

 

can someone please help me.

 

Thanks!

Hello

 

I have 2 lookup fields Contact and Asset in the cases object.

When i select a contact only the Assets he owns should be shown in the aseet lookup.

Can someone please help me with this.

 

Thanks!

 

Hello

 

Initially i tried to escalate cases using workflow and escalation rules but that is not working so now  I am trying to escalate the cases using batch apex in which the conditions are like:

Date/Time opened is more then one hour and still if the status is not closed then escalate it.

I have tried to write a code but i am getting an error can someone please help me to remove the error and also help me with the code.

 

global class CaseEscalation  implements  Database.Batchable<sObject> {
 global Database.QueryLocator start(Database.BatchableContext  BC){
         return Database.getQueryLocator([SELECT  CaseNumber, CreatedDate,Status                                         
                                             FROM Case]);  
   }
      global void execute(Database.BatchableContext ctx, List<Sobject>scope){
       List <Case> ca = (List<Case>)scope;
            for(Integer  i = 0; i < ca.size(); i++){
             if(System.Today() -  ca.CreatedDate >=1  &&  ca.Status!='Closed' )
             {
              String emailMessage = 'The case  '
                       + Case.CaseNumber
                        + ' has been ecalated '
                        + ' Please look into the case '
                       + 'Thankyou';
              Messaging.SingleEmailMessage mail  =   new Messaging.SingleEmailMessage();
             String[] toAddresses = new String[] {'reems.agarwal3@gmail.com'};
             mail.setToAddresses(toAddresses);
             mail.setSubject('Case Escalation');
             mail.setPlainTextBody(emailMessage);
             Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ mail });
             Case.Status = 'Escalated';
     }
    }
   }
global void finish(Database.BatchableContext ctx){
       }
    }  

This is the error i am getting
Error: Compile Error: Expression cannot be assigned at line -1 column -1    

I have fields like case status and date/time opened in the cases object.

If the date/time opened is more then one hour and still the status is new and the status is not approved or rejected the case should get escalated.

On escalation the status should change to escalated and the user should get a mail of escalated case assignment.

 

I am new to apex can someone please help me to write a batch apex for this.

 

Thanks!

I have made a lookup field of contacts in ma asset object.

I have made a default contact as No user in ma contacts as contact is a compulsory field in assets.

whenever i add a contact and the value is not 'No User' the status of asset should change to 'assigned' from the picklist.

when i free dat asset from that contact or make it as No User the status the status should change from assigned  to instock.

Can Someone Please help me.

 

 

trigger updateAsset on Asset (after insert, after update) {
if(trigger.new[0].Name !=null && trigger.new[0].contactid != 'No User'){
Asset assetsOwned= [select Name,status from asset where Name=:trigger.new[0].Name];
assetsOwned.status = 'Assigned';
update assetsOwned;
}
/*if( trigger.isUpdate && trigger.old[0].id !=null && trigger.old[0].id != trigger.new[0].id){
Asset assetsOwnedOld = [select id, status from asset where id=:trigger.old[0].id];
assetsOwnedOld.status = 'Instock';
update assetsOwnedOld;


}*/
}

hello,

 

I have a look up field assets_owned in my contacts object. I want to populate this look up only with those assets whose status is not assigned in the assets object. Can someone please help me.

 

Thanks!

Hello

 

I have created a lookup field named Assets in contact and i want to select more then one asset. Can anyone suggest me how can i do it.

 

Thanks!

Hi

 

I am new to salesforce platform.I need help with triggers.

I have created a look up field in contacts named Assets_owned. whenever a particular asset is selected in assets_owned i want to change the asset status to assigned from the picklist in the assets tab.

 

Thanks!

When developing a Visualforce page for overiding view page for any object, one problem that creeps up is to display the History details of a record. The standard related list Component doesn't works for History.

 

With the help of some code from Community ( I now can't find the link to it :( ), I wrote my own code  then to display the history of an object. It mimics the standard list as far as possible.  

 

Heres the code. It is for the Case object but it can be used for any other object.

 1.Component Code

 

<apex:component controller="CaseHistoriesComponentController">
<!-- Attribute Definition -->
<apex:attribute name="CaseId" description="Salesforce Id of the Case whose Case History needs to be rendered" type="Id" required="true" assignTo="{!caseId}" />

<!-- Case History Related List -->
<apex:pageBlock title="Case History">
<apex:pageBlockTable value="{!histories}" var="History" >
<apex:column headerValue="Date" value="{!History.thedate}"/>
<apex:column headerValue="User"> <apex:outputLink value="/{!History.userId}"> {!History.who} </apex:outputLink></apex:column>
<apex:column headerValue="Action"><apex:outputText escape="false" value="{!History.action}"/></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:component>

 

 

 

 

2. Apex Code

 

public class CaseHistoriesComponentController {

public Id caseId {get; set;}
public cHistories[] histories;

// Variables
public Static final Map<String, Schema.SObjectField> CaseFieldmap = Schema.SObjectType.Case.fields.getMap();
public Static final List<Schema.PicklistEntry> fieldPicklistValues = CaseHistory.Field.getDescribe().getPicklistValues();

public List<cHistories> getHistories()
{
list<cHistories> histories = new list<cHistories>();
String prevDate = '';
for(CaseHistory cHistory : [Select CreatedDate, CreatedBy.Name, CreatedBy.Id, Field, NewValue, OldValue from CaseHistory where CaseId = :caseId order by CreatedDate desc])
{
if((cHistory.newValue == null && cHistory.oldValue == null)
|| (cHistory.newValue != null && !(string.valueOf(cHistory.newValue).startsWith('005') || string.valueOf(cHistory.newValue).startsWith('00G')))
|| (cHistory.oldValue != null && !(string.valueOf(cHistory.oldValue).startsWith('005') || string.valueOf(cHistory.oldValue).startsWith('00G'))))
{
cHistories tempHistory = new cHistories();
// Set the Date and who performed the action
if(String.valueOf(cHistory.CreatedDate) != prevDate)
{
tempHistory.theDate = String.valueOf(cHistory.CreatedDate);
tempHistory.who = cHistory.CreatedBy.Name;
tempHistory.userId = cHistory.CreatedBy.Id;
}
else
{
tempHistory.theDate = '';
tempHistory.who = '';
tempHistory.userId = cHistory.CreatedBy.Id;
}
prevDate = String.valueOf(cHistory.CreatedDate);

// Get the field label
String fieldLabel = CaseHistoriesComponentController.returnFieldLabel(String.valueOf(cHistory.Field));

// Set the Action value
if (String.valueOf(cHistory.Field) == 'created') { // on Creation
tempHistory.action = 'Created.';
}
else if(cHistory.OldValue != null && cHistory.NewValue == null){ // when deleting a value from a field
// Format the Date and if there's an error, catch it and re
try {
tempHistory.action = 'Deleted ' + Date.valueOf(cHistory.OldValue).format() + ' in <b>' + fieldLabel + '</b>.';
} catch (Exception e){
tempHistory.action = 'Deleted ' + String.valueOf(cHistory.OldValue) + ' in <b>' + fieldLabel + '</b>.';
}
}
else{ // all other scenarios
String fromText = '';
if (cHistory.OldValue != null) {
try {
fromText = ' from ' + Date.valueOf(cHistory.OldValue).format();
} catch (Exception e) {
fromText = ' from ' + String.valueOf(cHistory.OldValue);
}
}

String toText = '';
if (cHistory.OldValue != null) {
try {
toText = Date.valueOf(cHistory.NewValue).format();
} catch (Exception e) {
toText = String.valueOf(cHistory.NewValue);
}
}
if(toText != '')
tempHistory.action = 'Changed <b>' + fieldLabel + '</b>' + fromText + ' to <b>' + toText + '</b>.';
else
tempHistory.action = 'Changed <b>' + fieldLabel;
}

// Add to the list
histories.add(tempHistory);
}
}

return histories;
}

// Function to return Field Label of a Case field given a Field API name
public Static String returnFieldLabel(String fieldName)
{
if(CaseHistoriesComponentController.CaseFieldmap.containsKey(fieldName))
return CaseHistoriesComponentController.CaseFieldmap.get(fieldName).getDescribe().getLabel();
else
{
for(Schema.PicklistEntry pickList : fieldPicklistValues)
{
if(pickList.getValue() == fieldName)
{
if(pickList.getLabel() != null)
return pickList.getLabel();
else
return pickList.getValue();
}
}
}
return '';
}
// Inner Class to store the detail of the case histories
public class cHistories {

public String theDate {get; set;}
public String who {get; set;}
public Id userId {get; set;}
public String action {get; set;}
}
}

  Let me know your views on the code or if you have any questions