• rajat Maheshwari 6
  • SMARTIE
  • 873 Points
  • Member since 2017

  • Chatter
    Feed
  • 27
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 264
    Replies
Hi there,

Hope you are doing great !!!

Could you please help me to resolve this issue  - 

ApexTrigger get delete from "RealDesk"Managed Released Package before 7 days, that need to be undelete but when we click on undelete it giving option "The record you attempted to access has been deleted. The user who deleted this record may be able to recover it from the Recycle Bin. Deleted data is stored in the Recycle Bin for 15 days. " but those trigger Not available in Recycle Bin to recover and those are still accessible with query
"select ID,Name from ApexTrigger where Status='deleted'" 
Id Name
1 01qi0000000jWjIAAU AccountTrigger
2 01qi0000000jWjKAAU TaskTrigger
3 01qi0000000jWjOAAU ContactTrigger

we want those 3 trigger to be undelete.

Thanks
Rajat Maheshwari

 
{ "destination_addresses" : [ "Bengaluru, Karnataka, India" ], "origin_addresses" : [ "Hyderabad, Telangana, India" ], "rows" : [ { "elements" : [ { "distance" : { "text" : "576 km", "value" : 575574 }, "duration" : { "text" : "8 hours 33 mins", "value" : 30763 }, "status" : "OK" } ] } ], "status" : "OK" }


Thanks
 
I need to modify our Docusign button , but I'm not sure if it's attainable. Basically , I need the button to be inactive ( annot click) unless 2 checkbox fields on the record are True. Is it possible to add the fields above the Page Call Out?  Thanks ,I'm new to Apex.

{!REQUIRESCRIPT("/apex/dsfs__DocuSign_JavaScript")}
//* iframe check *//
function inIframe() {
try {
return window.self !== window.top;
}
catch(e) {
return true;
}
}
//* iframe check *//
//********* Option Declarations (Do not modify )*********//
var RC = '';var RSL='';var RSRO='';var RROS='';var CCRM='';var CCTM='';var CCNM='';var CRCL='';var CRL='';var OCO='';var DST='';var LA='';var CEM='';var CES='';var STB='';var SSB='';var SES='';var SEM='';var SRS='';var SCS ='';var RES='';
//*************************************************//
DST='{!Order.DocuSign_DST__c}';
CRL='{!Order.DocuSign_CRL__c}';
CCRM='Customer~Signer 1';
//********* Page Callout (Do not modify) *********//
if(inIframe()) {
window.open("{!$Site.BaseUrl}/apex/dsfs__DocuSign_CreateEnvelope?nw=1&DSEID=0&SourceID={!Order.Id}&RC="+RC+"&RSL="+RSL+"&RSRO="+RSRO+"&RROS="+RROS+"&CCRM="+CCRM+"&CCTM="+CCTM+"&CRCL="+CRCL+"&CRL="+CRL+"&OCO="+OCO+"&DST="+DST+"&CCNM="+CCNM+"&LA="+LA+"&CEM="+CEM+"&CES="+CES+"&SRS="+SRS+"&STB="+STB+"&SSB="+SSB+"&SES="+SES+"&SEM="+SEM+"&SRS="+SRS+"&SCS="+SCS+"&RES="+RES,"Popup","location=1,status=1,scrollbars=1,resizable=1,directories=1,toolbar=1,titlebar=1,width=1200");
} else {
window.location.href ="/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID={!Order.Id}&RC="+RC+"&RSL="+RSL+"&RSRO="+RSRO+"&RROS="+RROS+"&CCRM="+CCRM+"&CCTM="+CCTM+"&CRCL="+CRCL+"&CRL="+CRL+"&OCO="+OCO+"&DST="+DST+"&CCNM="+CCNM+"&LA="+LA+"&CEM="+CEM+"&CES="+CES+"&SRS="+SRS+"&STB="+STB+"&SSB="+SSB+"&SES="+SES+"&SEM="+SEM+"&SRS="+SRS+"&SCS="+SCS+"&RES="+RES;
}
//*******************************************//
Hello,
Please anyone help me to write test class for execute method and list function! Hear i am give you my full apex class..

APEX Class:
global class CopyLoginHistory  {
   

    public List <LoginHistory> getLoginHistory()
    {
            return [SELECT ApiType,
                                                    ApiVersion,
                                                    Application,
                                                    Browser,
                                                    
                                                    Id,
                                                    ClientVersion,
                                                    LoginType,
                                                    LoginUrl,
                                                    Platform,
                                                    SourceIp,
                                                    Status,
                                                    UserId
                                            FROM LoginHistory
                                            WHERE LoginTime <: System.now()
                                            limit 1000];
    }
    
    public void execute ()
    {
        List <LoginHistory> lh = new List <LoginHistory> ();
        {
            lh = [SELECT ApiType, ApiVersion, Application, Browser, Id, ClientVersion, LoginType, LoginUrl, Platform, SourceIp, Status,
                   UserId FROM LoginHistory WHERE LoginTime <: System.now() limit 1000];
            
            string APIType;
            string APIVersion;
            string App;
            string Browser;
            string ClientVersion;
            string ID1;
           // DateTime LoginTime;
            string LoginType;
            string LoginURL;
            string Platform;
            string SourceIP;
            string Status;
            string UserID;
            
            for (LoginHistory login: lh)
            {
                APIType = login.ApiType;
                APIVersion = login.ApiVersion;
                App = login.Application;
                Browser = login.Browser;
                ID1 = login.Id;
                ClientVersion = login.ClientVersion;
              //  LoginTime = login.LoginTime;
                LoginType = login.LoginType;
                LoginURL = login.LoginUrl;
                Platform = login.Platform;
                SourceIP = login.SourceIp;
                Status = login.Status;
                UserID = login.UserId;
            }
            
            if (!lh.isEmpty())
            {
                List <TrackLoginHistory__c> trl = new List <TrackLoginHistory__c> ();
                User LogUser = [SELECT id, Name, Profile.Name, CompanyName, Email, Address FROM User WHERE ID =: UserID];
                for (LoginHistory login1: lh)
                {                
                    trl.add(new TrackLoginHistory__c (ApiType__c = APIType, 
                                         ApiVersion__c = APIVersion, 
                                         Application__c = App,
                                         Browser__c = Browser, 
                                         ClientVersion__c = ClientVersion, 
                                         ID__c = ID1,
                                        // LoginTime__c = String.valueOf(LoginTime),
                                         LoginType__c = LoginType,
                                         LoginURL__c = LoginURL,
                                         Platform__c = Platform,
                                         SourceIP__c = SourceIP,
                                         Status__c = Status,
                                          UserID__c = LogUser.Name,
                                          Profile__c = LogUser.Profile.Name,
                                          Address__c = String.valueOf(LogUser.Address),
                                          Email__c    = LogUser.Email,
                                          CompanyName__c = LogUser.CompanyName
                                           ));
                                         //UserID__c = UserID ));                
                
                }
                
                insert trl;                                         
            }
        }
    }
}

Thank You!
I am getting the above error when running a flow to update records In an object.  The same object has a trigger that updates whenever a record is udated.  Is there a work around for this limit issue in this particular instance? I have a couple of flows that will need to update records on this object but the trigger is getting in the way.  thank you
trigger ServiceBillingsTrigger on Service_Billings__c (after delete, after insert, after update) {
 
  Map<String,Special_Services_Sched__c> spcMap = new Map<String,Special_Services_Sched__c>();
  List<Special_Services_Sched__c> spcList = new List<Special_Services_Sched__c>();

  Map<String,Account> acctMap = new Map<String,Account>();
  List<Account> acctList = new List<Account>();
  
  final Product2 prod = [Select Id, Name From Product2 Where RecordTypeId = '012A0000000IqewIAC' And Name = 'JC' LIMIT 1][0];
  final RecordType inSpecsRt = [Select Id From RecordType WHERE SobjectType='Special_Services_Sched__c' AND Name='Specs' LIMIT 1];
  
  if (trigger.isDelete)
  {
      for (Service_Billings__c s : trigger.old) 
      {
      if(s.Cleaner__c != null)
      {
        if(!acctMap.containsKey(s.Cleaner__c))
        {
          Account clnrAcct = new Account(Id=s.Cleaner__c);
          clnrAcct.Active_Service__c = [Select count() 
                          From Service_Billings__c 
                          Where Active__c=true 
                          And Cleaner__c=:s.Cleaner__c];
          AggregateResult[] groupedResults = [Select SUM(Cleaner_Price__c) 
                          From Service_Billings__c 
                          Where Active__c=true 
                          And Cleaner__c=:s.Cleaner__c];
          clnrAcct.Services_Total__c = Double.valueOf(groupedResults[0].get('expr0'));

          acctMap.put(s.Cleaner__c,clnrAcct);
        }
      }

      if(s.Customer__c != null)
      {
        if(!acctMap.containsKey(s.Customer__c))
        {
          Account custAcct = new Account(Id=s.Customer__c);
          custAcct.Active_Service__c = [Select count() 
                          From Service_Billings__c 
                          Where Active__c=true 
                          And Customer__c=:s.Customer__c];
          AggregateResult[] groupedResults = [Select SUM(Customer_Price__c) 
                          From Service_Billings__c 
                          Where Active__c=true 
                          And Customer__c=:s.Customer__c];
          custAcct.Services_Total__c = Double.valueOf(groupedResults[0].get('expr0'));

          acctMap.put(s.Customer__c,custAcct);
        }
        if(s.Active__c)
        {
          if(s.Service__c == prod.Id)
          {
            for(Special_Services_Sched__c spc : [Select Id 
                                From Special_Services_Sched__c 
                                Where Active__c=true 
                                  And RecordTypeId =:inSpecsRt.Id
                                  And Customer__c=:s.Customer__c])
            {
              if(spcMap.containsKey(spc.Id))
                spcMap.remove(spc.Id);
              spc.Service_Billing__c = s.Id;
              spcMap.put(spc.Id,spc);
            }
          }
        }
      } 
      }    
  } else {

    if(Trigger.isUpdate)
    {
      for(integer x = 0; x < trigger.old.size(); x++)
          {
            if(trigger.old[x].LastBilled__c != trigger.new[x].LastBilled__c)
            {
              // billing Cycle Ignore Request.
            } else {
              Service_Billings__c s = trigger.new[x];
          if(s.Cleaner__c != null)
          {
            if(!acctMap.containsKey(s.Cleaner__c))
            {
              Account clnrAcct = new Account(Id=s.Cleaner__c);
              clnrAcct.Active_Service__c = [Select count() 
                              From Service_Billings__c 
                              Where Active__c=true 
                              And Cleaner__c=:s.Cleaner__c];
              AggregateResult[] groupedResults = [Select SUM(Cleaner_Price__c) 
                              From Service_Billings__c 
                              Where Active__c=true 
                              And Cleaner__c=:s.Cleaner__c];
              clnrAcct.Services_Total__c = Double.valueOf(groupedResults[0].get('expr0'));
              
              acctMap.put(s.Cleaner__c,clnrAcct);
            }
          }
    
          if(s.Customer__c != null)
          {
            if(!acctMap.containsKey(s.Customer__c))
            {
              Account custAcct = new Account(Id=s.Customer__c);
              custAcct.Active_Service__c = [Select count() 
                              From Service_Billings__c 
                              Where Active__c=true 
                              And Customer__c=:s.Customer__c];
              AggregateResult[] groupedResults = [Select SUM(Customer_Price__c) 
                              From Service_Billings__c 
                              Where Active__c=true 
                              And Customer__c=:s.Customer__c];
              custAcct.Services_Total__c = Double.valueOf(groupedResults[0].get('expr0'));
              acctMap.put(s.Customer__c,custAcct);
            }    
            if(s.Active__c)
            {
              if(s.Service__c == prod.Id)
              {
                for(Special_Services_Sched__c spc : [Select Id 
                                    From Special_Services_Sched__c 
                                    Where Active__c=true 
                                      And RecordTypeId =:inSpecsRt.Id
                                      And Customer__c=:s.Customer__c])
                {
                  if(spcMap.containsKey(spc.Id))
                    spcMap.remove(spc.Id);
                  spc.Service_Billing__c = s.Id;
                  spcMap.put(spc.Id,spc);
                }
              }
            }
          } 
        }
          }
    }

    if(Trigger.isInsert)
    {    
        for (Service_Billings__c s : trigger.new) 
        {
        if(s.Cleaner__c != null)
        {
          if(!acctMap.containsKey(s.Cleaner__c))
          {
            Account clnrAcct = new Account(Id=s.Cleaner__c);
            clnrAcct.Active_Service__c = [Select count() 
                            From Service_Billings__c 
                            Where Active__c=true 
                            And Cleaner__c=:s.Cleaner__c];
  
            AggregateResult[] groupedResults = [Select SUM(Cleaner_Price__c) 
                            From Service_Billings__c 
                            Where Active__c=true 
                            And Cleaner__c=:s.Cleaner__c];
            clnrAcct.Services_Total__c = Double.valueOf(groupedResults[0].get('expr0'));

            acctMap.put(s.Cleaner__c,clnrAcct);
          }
        }
  
        if(s.Customer__c != null)
        {
          if(!acctMap.containsKey(s.Customer__c))
          {
            Account custAcct = new Account(Id=s.Customer__c);
            custAcct.Active_Service__c = [Select count() 
                            From Service_Billings__c 
                            Where Active__c=true 
                            And Customer__c=:s.Customer__c];
            AggregateResult[] groupedResults = [Select SUM(Customer_Price__c) 
                            From Service_Billings__c 
                            Where Active__c=true 
                            And Customer__c=:s.Customer__c];
            custAcct.Services_Total__c = Double.valueOf(groupedResults[0].get('expr0'));
            acctMap.put(s.Customer__c,custAcct);
          }  
          if(s.Active__c)
          {
            if(s.Service__c == prod.Id)
            {
              for(Special_Services_Sched__c spc : [Select Id 
                                  From Special_Services_Sched__c 
                                  Where Active__c=true 
                                    And RecordTypeId =:inSpecsRt.Id
                                    And Customer__c=:s.Customer__c])
              {
                if(spcMap.containsKey(spc.Id))
                  spcMap.remove(spc.Id);
                spc.Service_Billing__c = s.Id;
                spcMap.put(spc.Id,spc);
              }
            }
          }
        } 
        }
    }
    }
   
     if(!acctMap.isEmpty())
       acctList.addAll(acctMap.values());
    if(acctList.size() > 0)
      update(acctList);
      
    if(!spcMap.isEmpty())
      spcList.addAll(spcMap.values());
  if(spcList.size() > 0)
    update(spcList);
}

 
I am able to get an access_token passing SF via HTTP POST. Now that I have the access_token, how do I leverage in the URL to query for case numbers? I want to return "status" for a lookup on the case number that is passed to the API via the IVR. I think the base URL is incorrect for my query... 

I send the folloing to SFDC:
https://login.salesforce.com/services/oauth2/token/
grant_type=password
&client_id=xxxx
&client_secret=xxxx
&username=email@.com
&password=testpwd

and I receive the access_token successfully and I store that value in a variable
I then want to send a url query to SFDC and return all cases for a specific account ... the url that I use for that is where I am lost. What would an example be of the url for this? 

i tried http://instance.salesforce.com/sid=xxxx&case=xxxx
i get the login page for SFDC. I obviously dont understand why I cannot get beyond the access_token being granted ...

Thanks in advance for any guidance,
Patrick
 
Hi All I m getting code coveage error for following lines in test class, can you please hlep

Code Coverage
User-added image





File
Edit
Debug
Test
Workspace
Help
<
>
ProspectingStatusUpdater
TrigToValidateContactRoles
Code Coverage: None
API Version:
Go To
1
trigger TrigToValidateContactRoles on Opportunity (before insert, before update) {
2

3
List<OpportunityContactRole> conRoleList = new List<OpportunityContactRole>();
4

5
Set<Id> ownerIdSet = new Set<Id>();
6

7
for(Opportunity opp : Trigger.new){
8
ownerIdSet.add(opp.ownerId);
9
}
10

11
User loggedInUser = [Select Id, Profile.Name from User where id =: UserInfo.getUserId() limit 1];
12

13
List<User> userList = [Select Id, UserRole.Name, Profile.Name from User where id in: ownerIdSet and UserRole.Name != null];
14

15
if(Trigger.isUpdate)
16
conRoleList = [Select Id, OpportunityId from OpportunityContactRole where OpportunityId in: Trigger.newMap.keySet()];
17

18
for(Opportunity opp : Trigger.new)
19
{
20

21
boolean isVerifyRolesValidation = True;
22

23
if(loggedInUser.Profile.Name.contains('System Administrator') || loggedInUser.Profile.Name.contains('Sales - Executive') || loggedInUser.Profile.Name.contains('Sales Operations - Liz Temp'))
24
{
25
isVerifyRolesValidation = false;
26
}
27
else
28
{
29
for(User u : userList)
30
{
31
if(opp.ownerId == u.Id && u.UserRole.Name.contains('Account Management'))
32
{
33
isVerifyRolesValidation = false;
34
break;
35
}
36
}
37
}
38
if(isVerifyRolesValidation){
39

40
if(opp.Probability >= 50)
41
{
42
if(Trigger.isInsert){
43
opp.addError('Contact Roles must be entered for this Opportunity before the Stage can be changed to Proposal or higher');
44
}
45
if(Trigger.isUpdate)
46
{
47
boolean isValid = false;
48
for(OpportunityContactRole cr : conRoleList){
49
if(opp.Id == cr.OpportunityId){
50
isValid = True;
51
break;
52
}
53
}
54

55
if(!isValid){
56
opp.addError('Contact Roles must be entered for this Opportunity before the Stage can be changed to Proposal or higher');
57
}
58
}
59
}
60
}
61
}
62
}
 


 
I am trying to write a test class for a controller extension and cannot seem to get it to work I keep getting a error: "System.QueryException: List has no rows for assignment to SObject on test class" and cannot figure out why.  My controller and test class are below.

public class HardwareWoSalesOrderLineEdit {
 public HardwareWoSalesOrderLineEdit(ApexPages.StandardController controller) {
     //parent record
  this.proj =[select Sales_Order__c, Id, X2nd_Sales_Order__c From Work_Order__c Where Id = :ApexPages.currentPage().getParameters().get('id')];    
     // child records
     this.line = [ SELECT SCMC__Quantity__c, Item_Name__c,SCMC__Quantity_Shipped__c, Category__c,     SCMC__Item_Description__c, PM_Ordering_Details__c, Quantity_to_Ship__c, Remaining_Quantity__c  
      FROM SCMC__Sales_Order_Line_Item__c
      WHERE (Item_Type__c = 'Hardware'   AND SCMC__Status__c != 'Completed' AND SCMC__Status__c != 'Shipped' AND Category__c != 'Physical Install' AND SCMC__Status__c != 'Cancelled' AND SCMC__Sales_Order__c = :proj.Sales_Order__c) OR
             (Item_Type__c = 'Hardware'   AND SCMC__Status__c != 'Completed' AND SCMC__Status__c != 'Shipped' AND Category__c != 'Physical Install' AND SCMC__Status__c != 'Cancelled' AND SCMC__Sales_Order__c = :proj.X2nd_Sales_Order__c)  ORDER BY Category__c ASC   ];     
     }
    //get sales order lines                 
  public SCMC__Sales_Order_Line_Item__c[] getline() { 
  return this.line; 
 } 
    
 // save method to save changes to the sales order lines
 public pagereference saveChanges() { 
  upsert this.line;
  pageRef.setRedirect(true); 
return pageRef;
 }
    
 // class variables
public PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl()); 
public Work_Order__c proj;
public SCMC__Sales_Order_Line_Item__c[] line; 

}



TEST CLASS 

@istest(seealldata=true)
public class HardwareWoSalesOrderLineEditTest{
    static testMethod void HardwareWoSalesOrderLineEditTest(){
        Test.startTest();
        SCMC__Sales_Order_Line_Item__c sol = [Select Id, SCMC__Item_Master__c, SCMC__Sales_Order__c, SCMC__Sales_Order__r.Installation__c, CreatedById,
                                              SCMC__Sales_Order__r.SCMC__Customer_Account__c
                                              from SCMC__Sales_Order_Line_Item__c where Item_Type__c = 'Hardware'   AND SCMC__Status__c != 'Completed'
                                              AND SCMC__Status__c != 'Shipped' AND Category__c != 'Physical Install' limit 1];
        system.assertnotEquals(null, sol);
        system.debug(sol.Id);
        
        
        Work_Order__c wo = new Work_Order__c(
            Account__c = sol.SCMC__Sales_Order__r.SCMC__Customer_Account__c,
            Sales_Order__c = sol.SCMC__Sales_Order__c,
            Installation__c = sol.SCMC__Sales_Order__r.Installation__c,
            Resource__c = sol.CreatedById,
            Type__c = 'Hardware Order',
            Start_Date__c = system.today(),
            Due_Date__c = system.today(),
            Confirm_address_is_correct__c = true,
            RecordTypeId = '01234000000Bmk8',
            Name = 'testwo123');{
                insert wo;}
        
        system.assertnotEquals(null, wo);
        system.debug(wo.Id);

        Work_Order__c w = [Select Id from Work_Order__c Where Name = 'testwo123' Limit 1]; 

            
        
        system.assertnotEquals(null, w);
        system.debug(w);
        Test.setCurrentPage(Page.HardwareWoSalesOrderLineEdit);
        ApexPages.Standardcontroller sc = new ApexPages.Standardcontroller(w);
        system.debug(sc);
        HardwareWoSalesOrderLineEdit myPageCon = new HardwareWoSalesOrderLineEdit(sc);
        system.debug(myPageCon);
        myPageCon.getline().add(sol);
        myPageCon.saveChanges();
        Test.stopTest();
    }      
}
I have trouble comparing old and new Account OwnerID. I see an error message saying  "Error: Compile Error: Invalid field OwnerId for SObject User at line 13 column 46". Below is my code. Please assist.
 
trigger ContactOwnerID on Account (After Insert, After Update) {

List<Account>AccList = new List<Account>();
Map<id,user>OldUserMap = new Map<id,user>();
Map<id,user>NewUserMap = new Map<id,user>();
List<Contact>ConList = new List<Contact>();
List<Contact>UpdatedConList = new List<Contact>();
List<Contact>FinalConList = new List<Contact>();



For(Account A:Trigger.new){
If(A.OwnerId != Null && OldUserMap.get(A.id).OwnerId != NewUserMap.get(A.id).OwnerId){
AccList.add(A);
}
If(!AccList.isEmpty()){
ConList =[Select id, OwnerId, AccountId from Contact where AccountId =: AccList];
}
}
If(!ConList.isEmpty()){
For(Contact c:UpdatedConList){
c.OwnerId = c.account.ownerid;
FinalConList.add(c);
}
}
If(!FinalConList.isEmpty()){
Update FinalConList;
}
}

 
Hey, I was given this code to update a date field every night and it works great in my sandbox. But the code they gave me to use for Test Class is not working and giving me errors.

I really need to get this code into production ASAP.

Scheduler Class that's working in my Sandbox;

global class SchedulerToUpdateDate implements Schedulable {
List<Grad_Employment_Detail__c> allRec = new List<Grad_Employment_Detail__c>();
List<Grad_Employment_Detail__c> toUpdate = new List<Grad_Employment_Detail__c>();
    global void  execute(SchedulableContext sc){
        allRec = [select id, current_Date__c from Grad_Employment_Detail__c];
        for(Grad_Employment_Detail__c ge: allRec){
            ge.current_Date__c = date.today();
            toUpdate.add(ge);
        }
        update toUpdate;
    }
}

This is the Test Class that was given, it's not working and giving error. (errors) is at the botom of the code listed)

@IsTest
    public class SchedulerToUpdateDate_Test{
        public static testmethod void unitTest(){            
            Test.starttest();
            Grad_Employment_Detail__c to = new Grad_Employment_Detail__c ();
            to.current_Date__c = date.today();
            insert to;
                SchedulerToUpdateDate wau = new SchedulerToUpdateDate();
                String sch = '0  00 1 3 * ?';
                system.schedule('Test', sch, wau);
            test.stoptest();
        }
    }

The error(s) I'm getting when trying to push into production. I specified this test only;
Method Name = unitTest

Error Message;
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Grad_Employment_Details__c]: [Grad_Employment_Details__c] 
Stack Trace: Class.SchedulerToUpdateDate_Test.unitTest: line 7, column 1


 
i have requirement where i show all recent items so i use this query on query editor SELECT Id,type, Name FROM RecentlyViewed  ORDER BY LastViewedDate DESC ] it is working fine on my org but on another org it is not showing recent view record. it showing only contact record why?
 
Hi,

I am having a trigger referred in a class which works fine , but fails in some cases , I would like to convert that class to a batch class and use it in my trigger

Kindly help me pls

 
MY TRIGGER CODE:

trigger ContractTrigger on Contract__c(After Update,After Insert) {    
    try{
        Trigger_Status__c ts = Trigger_Status__c.getValues('ContractTrigger');
        if(ts.Active__c){
            
            if(Trigger.isUpdate){

                TravelFundHandler.ValidateContractTermination(Trigger.New,Trigger.oldMap);
                ContractTriggerHandler.ContractfieldsupdateonAccount(Trigger.New, Trigger.oldMap);
                ContractTriggerHandler.contractcommencementdate(Trigger.New, Trigger.oldMap);
                ContractTriggerHandler.contractexpirydate(Trigger.New, Trigger.oldMap);
                 
            }  
            if(Trigger.isInsert){

                
                TravelFundHandler.travelFundMethod(Trigger.New,Trigger.oldMap);
              
            } 
            if(Trigger.isUpdate && TravelFundHandler.firstRun){
                TravelFundHandler.firstRun=false;
                TravelFundHandler.SignOnMethod(Trigger.New,Trigger.oldMap);
                
            }
          
           
            
        }
        
    }catch(Exception e){
        System.debug('Error Occured From Contract Trigger: '+e.getMessage());
    }
}
 
MY CLASS CODE :



public class triggerhandler{   
  
     
       public static void ContractfieldsupdateonAccount(List<Contract__c> newList, Map<Id, Contract__c> oldMap){
         
            Map<Id, Date> accMaptomaxcontractenddate = new Map<Id, Date>();
            Set<Id> accIds = new Set<Id>();
            List<Account> updateAcccontinfo = new List<Account>();
            Date d;
                
                        //Collecting the Account information from the Contract where the Status is 'Signed by Customer'
                        
                        for(Contract__c contr: newList){
        
                  if(contr.Status__c == 'Signed by Customer') 
                
                accIds.add(contr.Account__c);
                
                  System.debug('Account Ids: '+accIds);

                AggregateResult[] groupedResults = [SELECT Id,Account__c,MAX(Contract_End_Date__c)  
  FROM Contract__c where Account__c IN :accIds and Contracted__c = TRUE group by Account__c,Id ORDER BY MAX(Contract_End_Date__c) DESC NULLS LAST LIMIT 1]; 
                     // To get the Maximum contract end date of the Active (End Date > Today > Start date) Contract
            
                     for(AggregateResult ar :groupedResults){
  
  d = (Date)ar.get('expr0');
 System.debug('Maximum Contract End date: '+d);
  accMaptomaxcontractenddate.put((Id)ar.get('Account__c'),(Date)ar.get('expr0'));
  System.debug('Accmap for contracted Maximum Contract End date: : '+accMaptomaxcontractenddate);
  }
                   // To get the Account information associated to the Maximum contract end date of the Active (End Date > Today > Start date) Contract 
                   Map<id,Account> accMaptocontractfields = new Map<id,Account>();
            
                    
                   accMaptocontractfields = new Map<Id, Account>([SELECT Id, Contract_Start_Date__c, Contract_End_Date__c, Contract_Commencement_Date__c, 
                   Contract_Expiry_Date__c, No_of_Contracts__c,Qantas_Annual_Expenditure__c,Contract_Term_in_Months__c,Domestic_Annual_Share__c, International_Annual_Share__c,
                   Unit_Spend_per_term__c, Contracted__c,(SELECT Id, Contract_Start_Date__c, Contracted__c, Contract_End_Date__c, 
                   Domestic_Annual_Share__c, International_Annual_Share__c, Type__c,Qantas_Annual_Expenditure__c,Contract_Term_in_Months__c,
                   Unit_Spend_per_term__c  FROM Contracts__r where (Contract_End_Date__c = :d AND Contracted__c = TRUE) ORDER BY CreatedDate DESC NULLS LAST limit 1 ) FROM Account where Id IN : accIds ]);
                   
                  System.debug('Account map for contract end date:'+accMaptocontractfields);
                    
                     // To get the Contract associated to the Account from the map mentioned above
                  
                  Account acco = accMaptocontractfields.get(contr.Account__c);
                    
                             Date startDate,endDate;
                             Decimal domShare, intShare, unitspend,qantasannual,term;
                             String type;
                             Boolean contracted = false;
                    
                      for(Contract__c contr1 : acco.Contracts__r){
                          
                                  
                                   if(startDate == null && endDate == null){
                                        
                                        startDate = contr1.Contract_Start_Date__c;
                                        endDate = contr1.Contract_End_Date__c;
                                        domShare = contr1.Domestic_Annual_Share__c;
                                        intShare = contr1.International_Annual_Share__c;
                                        unitspend = contr1.Unit_Spend_per_term__c;
                                        qantasannual = contr1.Qantas_Annual_Expenditure__c;
                                        type = contr1.Type__c;
                                        term = contr1.Contract_Term_in_Months__c;
                                        contracted = contr1.Contracted__c;
                                        
                                    }else if(startDate.daysBetween(endDate) < contr1.Contract_Start_Date__c.daysBetween(contr1.Contract_End_Date__c)){
                                        
                                        startDate = contr1.Contract_Start_Date__c;
                                        endDate = contr1.Contract_End_Date__c;
                                        domShare = contr1.Domestic_Annual_Share__c;
                                        intShare = contr1.International_Annual_Share__c;
                                        unitspend = contr1.Unit_Spend_per_term__c;
                                        qantasannual = contr1.Qantas_Annual_Expenditure__c;
                                        type = contr1.Type__c;
                                        term = contr1.Contract_Term_in_Months__c;
                                        contracted = contr1.Contracted__c;
                                    }                                
                                 
                             }
                             
                    //Setting the Highest end date Active Contract information on Account 
                 
                    acco.Contract_Start_Date__c = startDate;
                    acco.Contract_End_Date__c = endDate;
                    acco.Domestic_Annual_Share__c =  domShare;
                    acco.International_Annual_Share__c = intShare;
                    acco.Type__c = type  ;
                    acco.Qantas_Annual_Expenditure__c = qantasannual;
                    acco.Contract_Term_in_Months__c =  term;
                    acco.Unit_Spend_per_term__c = unitspend;
                    acco.Contracted__c =    contracted;
                    
                    
                    System.debug('Account Contract Start Date: '+  acco.Contract_Start_Date__c );
                    System.debug('Account Contract End date: '+acco.Contract_End_Date__c);
                    System.debug('Contract Term in Months: '+acco.Contract_Term_in_Months__c);
                    System.debug('Units spend per term: '+acco.Unit_Spend_per_term__c);
                    System.debug('Account Contract Category: '+acco.Type__c);
                    System.debug('Forecast QF Spend: '  +acco.Qantas_Annual_Expenditure__c);
                    System.debug('Forecast QF Share (Dom) [System]: '+acco.Domestic_Annual_Share__c);
                    System.debug('Forecast QF Share (Int) [System]: '+acco.International_Annual_Share__c);
                    System.debug('Contracted:'+acco.Contracted__c);
                    
                      updateAcccontinfo.add(acco);
                    }

         
                    
            try{
          
            Database.SaveResult[] srlist = Database.Update(updateAcccontinfo, false);
                for (Database.SaveResult sr : srlist){
if (!sr.isSuccess()) {
    
    // Updation failed due to duplicate detected
    for(Database.Error duplicateError : sr.getErrors()){
        Datacloud.DuplicateResult duplicateResult = 
                  ((Database.DuplicateError)duplicateError).getDuplicateResult();
        System.debug('Duplicate records have been detected by ' + 
                  duplicateResult.getDuplicateRule());
        System.debug(duplicateResult.getErrorMessage());
    }

    // If the duplicate rule is an alert rule, we can try to bypass it
    Database.DMLOptions dml = new Database.DMLOptions(); 
    dml.DuplicateRuleHeader.AllowSave = true;
    Database.SaveResult[] sr2list = Database.Update(updateAcccontinfo, dml);
     for (Database.SaveResult sr2 : sr2list){
    if (sr2.isSuccess()) {
        System.debug('Duplicate account has been updated in Salesforce!');
    }
}
}
}
            }

catch(Exception e){
               System.debug(' Exception Occured: '+e.getMessage());
               }
        }
        
        /* This method is being used to populate the Account fields "Contract Commencement Date" of the 
      Minimum contract start date with the status "Signed by Customer" */
        
        public static void contractcommencementdate(List<Contract__c> newList, Map<Id, Contract__c> oldMap){
           
            Map<Id, Date> accMaptomincontractstartdate = new Map<Id, Date>();
            Set<Id> accoIds = new Set<Id>();
            List<Account> updateAcccommdate = new List<Account>();
            Date d;
            Date commencementDate;
            
            //Collecting the Account information from the Contract where the Status is 'Signed by Customer'
        
         for(Contract__c contr: newList){
           
         if(contr.Status__c == 'Signed by Customer' ) 
                
            accoIds.add(contr.Account__c);
    
             // To get the Minimum contract start date of the ""Signed by Customer" Contract    
             
            AggregateResult[] groupedResults = [SELECT Id,Account__c, MIN(Contract_Start_Date__c)  
  FROM Contract__c where Account__c IN :accoIds and Status__c = 'Signed by Customer' group by Account__c,Id ORDER BY MIN(Contract_Start_Date__c) ASC NULLS LAST LIMIT 1];
          
  for(AggregateResult ar : groupedResults){
      accMaptomincontractstartdate.put((Id)ar.get('Account__c'),(Date)ar.get('expr0'));
      
      System.debug('Accmap for Minimum Contract Start date: : '+accMaptomincontractstartdate);
      d=(Date)ar.get('expr0');
      System.debug('Least Commencement Date: '+d);
     }
                 
                 // To get the Account information associated to the Minimum contract start date of the "Signed by Customer" Contract
                 Map<id,Account> accMaptocommencementdate = new Map<id,Account>();
     
                     accMaptocommencementdate = new Map<Id, Account>([SELECT Id, Contract_Start_Date__c, Contract_End_Date__c, Contract_Commencement_Date__c, 
                   Contract_Expiry_Date__c, No_of_Contracts__c,Qantas_Annual_Expenditure__c,Contract_Term_in_Months__c,Domestic_Annual_Share__c, International_Annual_Share__c,
                   Unit_Spend_per_term__c, Contracted__c,(SELECT Id, Contract_Start_Date__c, Contracted__c, Contract_End_Date__c, 
                   Domestic_Annual_Share__c, International_Annual_Share__c, Type__c,Qantas_Annual_Expenditure__c,Contract_Term_in_Months__c,
                   Unit_Spend_per_term__c  FROM Contracts__r where (Contract_Start_Date__c = :d and Status__c = 'Signed by Customer')limit 1 ) FROM Account where Id IN : accoIds]);
  
   
               // To get the Contract associated to the Account from the map mentioned above
   Account accou = accMaptocommencementdate.get(contr.Account__c);
  
  for(Contract__c contr2 : accou.Contracts__r){
  commencementDate = contr2.Contract_Start_Date__c;
  }
  
  //Setting the Minimum Contract start date to the Account Contract commencement date
 
 accou.Contract_Commencement_Date__c =  commencementDate;
 
 System.debug('Account Contract Commenecement Date:'+accou.Contract_Commencement_Date__c);
     updateAcccommdate.add(accou);
      }
           
 
     
        
            try{
          
            Database.SaveResult[] srlist = Database.Update(updateAcccommdate, false);
                for (Database.SaveResult sr : srlist){
if (!sr.isSuccess()) {
    
    // Updation failed due to duplicate detected
    for(Database.Error duplicateError : sr.getErrors()){
        Datacloud.DuplicateResult duplicateResult = 
                  ((Database.DuplicateError)duplicateError).getDuplicateResult();
        System.debug('Duplicate records have been detected by ' + 
                  duplicateResult.getDuplicateRule());
        System.debug(duplicateResult.getErrorMessage());
    }

    // If the duplicate rule is an alert rule, we can try to bypass it
    Database.DMLOptions dml = new Database.DMLOptions(); 
    dml.DuplicateRuleHeader.AllowSave = true;
    Database.SaveResult[] sr2list = Database.Update(updateAcccommdate, dml);
     for (Database.SaveResult sr2 : sr2list){
    if (sr2.isSuccess()) {
        System.debug('Duplicate account has been updated in Salesforce!');
    }
}
}
}
            }

catch(Exception e){
               System.debug(' Exception Occured: '+e.getMessage());
               }
        }
        
        
         public static void contractexpirydate(List<Contract__c> newList, Map<Id, Contract__c> oldMap){
         
          Map<Id, Date> accMaptomaxcontractexpdate = new Map<Id, Date>();
          Set<Id> accIds = new Set<Id>();
          List<Account> updateAccexpdate = new List<Account>();
          Date d;
          Date expiryDate;
        
                //Collecting the Account information from the Contract where the Status is 'Signed by Customer'
                for(Contract__c contr: newList){
                   
                if(contr.Status__c == 'Signed by Customer' ) 
                
                accIds.add(contr.Account__c);
          
                
        
            // To get the Maximum contract end date of the ""Signed by Customer" Contract

          AggregateResult[] groupedResults =  [SELECT Id,Account__c, MAX(Contract_End_Date__c)
  FROM Contract__c where Account__c IN :accIds and Status__c = 'Signed by Customer' group by Account__c,Id Order by MAX(Contract_End_Date__c) DESC NULLS LAST LIMIT 1];         
            
                     for(AggregateResult ar : groupedResults){
      accMaptomaxcontractexpdate.put((Id)ar.get('Account__c'),(Date)ar.get('expr0'));
      
        System.debug('Accmap for Maximum Contract End date: : '+accMaptomaxcontractexpdate);
        
      d=(Date)ar.get('expr0');
      
      System.debug('Highest Expiry Date: '+d);
      
  }
  
  // To get the Account information associated to the Maximum contract end date of the ""Signed by Customer" Contract
  
   Map<id,Account> accMaptoExpirydate = new Map<id,Account>();
   
          accMaptoExpirydate = new Map<Id, Account>([SELECT Id, Contract_Start_Date__c, Contract_End_Date__c, Contract_Commencement_Date__c, 
                   Contract_Expiry_Date__c, No_of_Contracts__c,Qantas_Annual_Expenditure__c,Contract_Term_in_Months__c,Domestic_Annual_Share__c, International_Annual_Share__c,
                   Unit_Spend_per_term__c, Contracted__c, Account_Contract_No__c,(SELECT Id, Contract_Start_Date__c, Contracted__c, Contract_End_Date__c, 
                   Domestic_Annual_Share__c, International_Annual_Share__c, Type__c,Qantas_Annual_Expenditure__c,Contract_Term_in_Months__c,
                   Unit_Spend_per_term__c,Contract_Number__c FROM Contracts__r where (Contract_End_Date__c = :d and Status__c = 'Signed by Customer')ORDER BY CreatedDate DESC NULLS LAST limit 1) FROM Account where Id IN : accIds ]);
  
  
  // To get the Contract associated to the Account from the map mentioned above

  
   Account accoun = accMaptoExpirydate.get(contr.Account__c);
   
   String Accconno;
   
     for(Contract__c contr2 : accoun.Contracts__r){
         Accconno = contr2.Contract_Number__c;
  expiryDate = contr2.Contract_End_Date__c;
  }
  
    //Setting the Maximum Contract end date to the Account Contract commencement date
   
   accoun.Contract_Expiry_Date__c = expiryDate;
   accoun.Account_Contract_No__c = Accconno;
 
System.debug('Account Contract Expiry Date:'+ accoun.Contract_Expiry_Date__c);
System.debug('Account Contract No: '+  accoun.Account_Contract_No__c);
 updateAccexpdate.add(accoun);
      
        }
        

       
            try{
          
            Database.SaveResult[] srlist = Database.Update(updateAccexpdate, false);
                for (Database.SaveResult sr : srlist){
if (!sr.isSuccess()) {
    
    // Updation failed due to duplicate detected
    for(Database.Error duplicateError : sr.getErrors()){
        Datacloud.DuplicateResult duplicateResult = 
                  ((Database.DuplicateError)duplicateError).getDuplicateResult();
        System.debug('Duplicate records have been detected by ' + 
                  duplicateResult.getDuplicateRule());
        System.debug(duplicateResult.getErrorMessage());
    }

 
    Database.DMLOptions dml = new Database.DMLOptions(); 
    dml.DuplicateRuleHeader.AllowSave = true;
    Database.SaveResult[] sr2list = Database.Update(updateAccexpdate, dml);
     for (Database.SaveResult sr2 : sr2list){
    if (sr2.isSuccess()) {
        System.debug('Duplicate account has been updated in Salesforce!');
    }
}
}
}
            }

catch(Exception e){
               System.debug(' Exception Occured: '+e.getMessage());
               }
        }
        
    }

Kindly help me pls

Thanks in advance

Hi all,

We are currently using the email to case functionality within our business and have a customer at the moment who is sending us multiple cases per day that we simply need to log and report on. The problem is that they auto generate their emails from their system and as such hold all the detail in the email body. These generally are like:

Patient Name:
Address:
Town:
Post Code:

etc

I was wondering if i could use a workflow or trigger to automatically take this data out of the email body and populate some custom fields?

Any help or direction would be greatly appreciated

I know almost nothing about Apex and looking for help. I know for this use case I will need a Trigger, however. 

Here's the use case: 

My company has 8 oven slots(manufacturing), and 2 cycle AM and PM for a total of 16 total usable slots(8 each cycle). I need to measure the success rate of each slot during the AM and PM based on the # of orders gone into the specific slot. 


Here is how i've set it up thus far: 
I have a child related list (Audits__c) to a master (Order_Summary__c). Each "audit" record has a field "AM Oven Slot__c" and "PM Oven Slot__c" both are ranged 1-8 in a picklist, and finally there is a "Outcome_Result__c" picklist field with "Good" and "Fail" 

I have already used 16/25 rollup summaries to count the # of line items that go into each tray in the AM and PM, respectively. 

Now, I need a Trigger to COUNT the number of "Good" Outcome_Result__c for each respective tray # and update the respective number field. 
For example, it will SUM the # of "good" outcome results for Tray 1, and then insert that number into "Total Successful outcomes AM Tray 1" 

I think I need to do a BEFORE trigger since I don't need to utilize the record ID, and a list?? 

Help? 

Hi Salesforce gurus,

I am looking to extract the description of Custom fields of a/multiple object from the org.
basically i am trying to get a spreadsheet with the object name, field name and Description of the field.

I tried the below but have reached a dead end
>Getdescribe Apex calls - the Description is missing from the .getdescribe call
>Tried using the metadata API from this link :https://salesforce.stackexchange.com/questions/141251/query-name-help-text-description-of-custom-fields-in-a-custom-object  - but the api was not installed completely as it faced more than 30000 in apex code for 5-6 classes.
>querying the Field Definition object from workbench - again this object omits the Description field in the object
>inlineHelpText field is useless, as the field havent been used in the org like the description Text box of custom fields.

Any idea where the Description for a custom field is stored ,there has to be some metadata object or any other way to get the description.

Thanks in Advance.
 
I am new to wave analytics ,
How to bind two datasets in a single dashboards