• Swati G
  • SMARTIE
  • 1133 Points
  • Member since 2010

  • Chatter
    Feed
  • 33
    Best Answers
  • 0
    Likes Received
  • 3
    Likes Given
  • 0
    Questions
  • 176
    Replies
Hi all,

I have 2 field in SOSL . How we check substract from to_date and from_date <=1 days
I have design a Apex Trigger Code:


trigger BusinessHrs on Customer__c (before insert, before update)
{
Long Diff1;
Long Diff2;
for(Customer__c c1: trigger.new)
{
BusinessHours stdBusinessHours = [select id from businesshours where id = '01mi0000000aAVI'];

DateTime d1 = DateTime.newInstance(1997, 1, 31, 7, 8, 16);
DateTime d2 = DateTime.newInstance(1997, 1, 31, 7, 8, 16);

d1=c1.Startdate__c;
d2=c1.EndDate__c;

Diff1=BusinessHours.diff('01mi0000000aAVI',d1, d2) ;
c1.Business_Hour1__c=(Diff1/(1*60*60*1000));

DateTime d3=DateTime.newInstanceGmt((d1.dateGmt()), (d1.timeGmt()) );
DateTime d4=DateTime.newInstanceGmt((d2.dateGmt() ), (d2.timeGmt() ) );

Diff2=BusinessHours.diff('01mi0000000aAVI',d1, d2) ;
c1.Business_Hour2__c=(Diff2/(1*60*60*1000)); } } }

In Both Business_Hour1__c,Business_Hour2__c the number field(decimal 2 places) have no decimal value... Is something wrong in : Diff2=BusinessHours.diff('01mi0000000aAVI',d1, d2) ;
c1.Business_Hour2__c=(Diff2/(1*60*60*1000));
Hi, please help on my Batch Apex Job, it kept on prompt me error 'First error: Too many query rows: 50001'  and i cant reduce the result return from my statement, i need to process all data, can any1 suggest me a way?
 
public class ContactCampaignCount implements Database.Batchable<sObject>{
    Integer subtotalUpdCst_actual = 0;
    private string ctc_types;
    private string cpgn_types;
 
    public ContactCampaignCount(String ctc_type, string cpgn_type){
        
        this.ctc_types = ctc_type;
        this.cpgn_types = cpgn_type;
    }
    
    public Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'SELECT Id,Name,Test1__c, Test2__c, Test3__c, Test4__c, Test5__c FROM Contact WHERE RecordTypeId = \'' + ctc_types +'\'';
        
        return Database.getQueryLocator(query);
    }
   
    public void execute(Database.BatchableContext BC, List<Contact> scope)
    {
                
        List <Campaign> ytd_total_cmpgn = new List <Campaign>();
        List <Campaign> ytd_email_cmpgn = new List <Campaign>();
        List <Campaign> mth_total_cmpgn = new List <Campaign>();
        List <Campaign> mth_email_cmpgn = new List <Campaign>();
        List <CampaignMember> ytd_total_cpgn_mb = new List<CampaignMember>();
        List <CampaignMember> ytd_email_cpgn_mb = new List<CampaignMember>();
        List <CampaignMember> mth_total_cpgn_mb = new List<CampaignMember>();
        List <CampaignMember> mth_email_cpgn_mb = new List<CampaignMember>();
        List<Contact> updateCtcs = new List<Contact>();
        
        ytd_total_cmpgn = [SELECT ID, Campaign_Effective_Start_Date__c, Year__c, Channel__c FROM Campaign WHERE Year__c =: String.valueOf(System.today().year()) and RecordTypeId =: cpgn_types];
        ytd_email_cmpgn = [SELECT ID, Campaign_Effective_Start_Date__c, Year__c, Channel__c FROM Campaign WHERE Year__c =: String.valueOf(System.today().year()) and Channel__c = 'Email' and RecordTypeId =: cpgn_types];
        mth_total_cmpgn = [SELECT ID, Campaign_Effective_Start_Date__c, Year__c, Channel__c FROM Campaign WHERE Campaign_Effective_Start_Date__c >=: System.today().addMonths(-12) and Campaign_Effective_Start_Date__c <=: System.today() and RecordTypeId =: cpgn_types];
		mth_email_cmpgn = [SELECT ID, Campaign_Effective_Start_Date__c, Year__c, Channel__c FROM Campaign WHERE Campaign_Effective_Start_Date__c >=: System.today().addMonths(-12) and Campaign_Effective_Start_Date__c <=: System.today() and Channel__c = 'Email' and RecordTypeId =: cpgn_types];
        
        ytd_total_cpgn_mb = [SELECT Id, ContactId, CampaignId From CampaignMember where CampaignId in :ytd_total_cmpgn];
        ytd_email_cpgn_mb = [SELECT Id, ContactId, CampaignId From CampaignMember where CampaignId in :ytd_email_cmpgn];
        mth_total_cpgn_mb = [SELECT Id, ContactId, CampaignId From CampaignMember where CampaignId in :mth_total_cmpgn];
        mth_email_cpgn_mb = [SELECT Id, ContactId, CampaignId From CampaignMember where CampaignId in :mth_email_cmpgn];
        
        for(Contact ctc : scope){
            
            Integer ytd_total_Campaign = 0;
            Integer ytd_total_emailCampaign = 0;
            Integer mth_total_Campaign = 0;
            Integer mth_emailCampaign = 0;
            Date last_campaign_date;
            
            for(CampaignMember ytd_total_cmb : ytd_total_cpgn_mb){
                if(ytd_total_cmb.ContactId == ctc.Id){
                   ytd_total_Campaign += 1;
                }
            }
            
            for(CampaignMember ytd_total_eml_cmb : ytd_email_cpgn_mb){
                if(ytd_total_eml_cmb.ContactId == ctc.Id){
                   ytd_total_emailCampaign += 1;
                }
            }
            
            for(CampaignMember mth_total_cmb : mth_total_cpgn_mb){
                if(mth_total_cmb.ContactId == ctc.Id){
                   mth_total_Campaign += 1;
                    
                    for(Campaign cm: mth_total_cmpgn){
                        if(cm.Id == mth_total_cmb.CampaignId){
                            
                            if(last_campaign_date == null || last_campaign_date < cm.Campaign_Effective_Start_Date__c){
                                last_campaign_date = cm.Campaign_Effective_Start_Date__c;
                            }
                        }
                    }
                }                
            }
            
            for(CampaignMember mth_total_eml_cmb : mth_email_cpgn_mb){
                if(mth_total_eml_cmb.ContactId == ctc.Id){
                   mth_emailCampaign += 1;
                }
            }
            
            if(ctc.Test5__c == null || ctc.Test5__c < last_campaign_date){               
               ctc.Test5__c = last_campaign_date;
            }
            
            ctc.Test1__c = ytd_total_Campaign;
            ctc.Test2__c = ytd_total_emailCampaign;
            ctc.Test3__c = mth_total_Campaign;
            ctc.Test4__c = mth_emailCampaign;
       
            updateCtcs.add(ctc);
        }
        statics.enableContactTrigger = false;

        List<Database.SaveResult> r1 = Database.update(updateCtcs, false);
        for( Database.Saveresult r : r1 ){
            if ( r.isSuccess()){
                subtotalUpdCst_actual = subtotalUpdCst_actual + 1;
                System.debug('Database.Saveresult >> ' + r);
            }else{
                for ( Database.Error e : r.getErrors() ){
                    System.debug ( updateCtcs + '\n' + e.getStatusCode() + ': ' + e.getMessage());
                } 
            }
        }
    }   
    public void finish(Database.BatchableContext BC)
    { 
    }
}



thanks
Hi,

Can I add a VF component as Related List in a standard Page Layout?

Thanks in Advance,
Pramitha
I got the error in the subtitle . Can any one help me to fix that . I below code i can not create the disclosure obligation when the name has & symbol. It is created ok with normal name

Here is my below code :

/**
    @description    Class for the Redirect With Variables page.     
    Function: Handles the controller logic for the RedirectWithVariables page.       
 */

public with sharing class RedirectWithVariablesController {
    /*
     *  Method name:    redirectUser
     *  @description    Redirects the user to the given object + parameters
     *  @return         PageReference The page the user needs to be redirect to.
     */    
    public pagereference prePopulateFields(){
        //Get object name
        String strObject = System.currentPageReference().getParameters().get('object');  
        string params = '';
        Integer a = 0;
        map<String,String> fields = getFieldsIdsMap(strObject);
        
        string regName = System.currentPageReference().getParameters().get('Registration__c');
        string regId = System.currentPageReference().getParameters().get('ID_Registration__v');
        string retURL = System.currentPageReference().getParameters().get('retURL');
        string stakeholerName = System.currentPageReference().getParameters().get('Stakeholder__c');
        string stakeholerId = System.currentPageReference().getParameters().get('ID_Stakeholder__v');
        for(string k: fields.keySet()){
            //ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, k+''));
            //System.debug('label: ' + a + ': ' + k);
            //a++;
            if(k == 'Registration'){
                params += fields.get(k) + '=' + regName + '&' + fields.get(k) + '_lkid=' + regId + '&';
            }
            if(k == 'Stakeholder'){
                params += fields.get(k) + '=' + stakeholerName + '&' + fields.get(k) + '_lkid=' + stakeholerId+ '&';                
            }
        }
        //for(string p:fields.values()){            
        //    params += p+'=Test Value '+a+'&';
        //    a++;
        //}
        PageReference p = new PageReference('/' +  
        Schema.getGlobalDescribe().get(strObject).getDescribe().getKeyPrefix() + '/e?'+
            params+'nooverride=1&retURL=' + retURL);        
        p.setRedirect(true);
        return p;
    }

    public map<String, String> getFieldsIdsMap(String sObjectName) {
        map<String, String> label_IdMap = new map<String, String>();
        if(null!= sObjectName && sObjectName.trim() != '') {
            //if(!isObjectValid(sObjectName)){
            //    return null;
            //}
            PageReference p = new PageReference('/' +  
            Schema.getGlobalDescribe().get(sObjectName).getDescribe().getKeyPrefix()
            + '/e?nooverride=1'); // this one return null in the url
            String html = '';
            if(!Test.isRunningTest()) {
                html = p.getContent().toString();
            } else {
                //html = '';
                html = '<label for="CF00NK0000000Yt1b"><span class="requiredMark">*</span>Name</label>';
            }
            Matcher m = Pattern.compile('<label for="(.*?)">(<span class="requiredMark">\\*</span>)?(.*?)</label>').
            matcher(html);
            while(m.find()) {
                String label = m.group(3);
                String id = m.group(1);
                label_IdMap.put(label, id);
            }
        }
        return label_IdMap;
    }    
}

controller:
public class DisclosureNewOverrideController{
    public String retURL {get;set;}
    public DisclosureNewOverrideController(ApexPages.standardController sc){
        retURL = ApexPages.CurrentPage().GetParameters().Get('retURL');
        system.debug('nghiatran retURL ' + retURL + ' ' + retURL.substring(1));
        //ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'This: ' + retURL));
        //string objectName = getObjectName(retURL);
        string objectName = CommonUtils.getObjectName(retURL.substring(1));
        if(objectName == 'Disclosure_Claim_for_Payment__c'){
            ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'This button has been disabled to help ensure the correct Disclosure/Claim for Payment is created.'));
            ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'To create a New Disclosure, please navigate to the Stakeholder record -> Disclosure Obligation record.'));
            ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'To create a New Claim for Payment, please navigate to the Stakeholder record -> Eligible Claim for Payment record.'));
        }else if(objectName == 'Disclosure_Obligation__c'){
            ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'This button has been disabled to help ensure the correct Disclosure Obligation is created.'));
            ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'To create a new Disclosure Obligation, please navigate to the Stakeholder record.'));
        }else if(objectName == 'HP_Trim_Container__c'){
            ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'This button has been disabled to help ensure the correct Donor TRIM Containers are created.'));
            ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'To create the Donor TRIM Containers, please navigate to the \'All\' list view and click on \'Generate Donor TRIM Containers.\''));
        }
    }
   

this is 2 url when create new disclosure :

not ok https://c.cs6.visual.force.com/apex/DisclosureObligationNewOverride?save_new=1&sfdc.override=1
 the account name :Mr Madhvi Lata & Visapaa
ok :https://c.cs6.visual.force.com/apex/DisclosureObligationNewOverride?CF00NN0000000MBK7=Aegis+Consulting+Group+Pty+Ltd&CF00NN0000000MBK7_lkid=001N000000M1lpg&scontrolCaching=1&retURL=%2F001N000000M1lpg&sfdc.override=1
the account name :Aegis Consulting Group Pty Ltd



 
This is quite a simple question. This is not working in my code:
<apex:column headerValue="{!$Label.ContractManagementColumnCustName}" value="{!waitlistItem.Contract__r.Contact__r.Name}"/>
Error: Invalid field Contact__r for SObject Contract
I'm sure that my setup of objects is correct, so the relationship on object Contract__c exists. What am I doing wrong?
 
In how many ways can we schedule a batch apex??

Thanks in advance
I have one object named "Order_batch__c" .In that i have records in such a way
I want to separate the data into two records one is parent object "order" and child object "order item"

order consists of fields : customer po,account name, customer id
order item consists of fields : nicomatic pin,quantity ordered

Trigger:
 
trigger orderitem on order_batch__c (after insert , after update) {
 Set<Id> Ids= new Set<Id>();
    for (order_batch__c member : Trigger.new){
        Ids.add(member.Id); 
        
        
        }
 List<order_batch__c> memberList = new List<order_batch__c>([Select Id,Or_customer_PO_Number__c,Or_Nicomatic_p_n__c, Or_clientpn__c,Quantity_Ordered__c,Requested_Date__c,Discount__c,Unit_price__c  From order_batch__c  where Id in :Ids]);
    for(order_batch__c temp : memberList )
    {
        order__c o= new order__c();
        o.Customer_Po__c=o=temp.Or_customer_PO_Number__c;
        insert o;
        Order_Item__c member2 = new Order_Item__c();
       // mermber2.Order__c=temp.Or_customer_PO_Number__c;
        member2.Name = temp.Or_Nicomatic_p_n__c;
        member2.Client_PN__c = temp.Or_clientpn__c;
         member2.Quantity__c = temp.Quantity_Ordered__c;
        member2.Request_Date__c = temp.Requested_Date__c;
         member2.Discount__c = temp.Discount__c;
        member2.Price__c = temp.Unit_price__c;
        insert member2;
        
        
    }
 }
My requirement is to separate records in parent and child records .when ever there is an update in order batch records it has to update accordingly parent or child.

I am getting error in the above trigger .can any body help me regarding this




User-added image
Hi 
I'm getting Error in Test Class like below :
System.DmlException: Upsert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Auto_generated: execution of AfterInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Test Class:

@isTest 
private class Emailtocase_TestClass
{
     static TestMethod void Emailtocase_TestClass()
    {
        
        Test.StartTest();  
        
        Case c= new Case();
        c.Subject = 'Testing';
        //insert c;
       
        
       Contact con = new Contact();
       con.LastName = 'Testing Contact';
       con.Email = 'test1@gmail.com'; 
       insert con;  
       Contact c1 = [Select id,LastName,Email from Contact where Email = 'test1@gmail.com'];
        
        Case ca = new Case();
        ca.Id = c.Id;
        ca.Subject='Welcome';
        ca.Status = 'email';
        ca.Origin='New';
        ca.ContactId = c1.Id;
        ca.SuppliedEmail= 'test1@gmail.com';
        ca.Task_Taken__c=false;
        ca.OwnerId = '00G90000002Gb76';
        upsert ca;
        
        Account a = new Account();
        a.Domain_Name__c = 'gmail.com';        
        a.Name='Testing Account';
        insert a;
        Account a1 = [Select id,Domain_Name__c,Name,Phone from Account where Domain_Name__c = 'gmail.com'];
        Case cas1= new Case();
        cas1.Subject = 'Testing';
        cas1.SuppliedEmail= 'test@gmail.com';
        
        List<contact> lstcon =new List<contact>();
        contact con1=new contact(lastname='sas',Email = cas1.SuppliedEmail,AccountId=a1.Id);
        lstcon.add(con1);
        insert lstcon;
        
       
        
       Case ca1 = new Case();
        ca1.Id = cas1.Id;        
        ca1.Subject='Welcome';
        ca1.Status = 'email';
        ca1.Origin='New';       
        ca1.AccountId=a1.Id;
        ca1.Task_Taken__c=false;
        ca1.OwnerId = '00G90000002Gb76';       
        ca.ContactId = lstcon[0].Id;
        Upsert ca1;// Here I'm getting error line is -Class.Emailtocase_TestClass.Emailtocase_TestClass: line 57, column 1
      
        Test.StopTest();
        
        
        
    }
}
The above covers 54% so how to solve this error.

Thanks
hi all,
i need to write test class for this trigger. Please give some idea


trigger accountTestTrggr  on Account (before insert,before update) {
 List<Account> accountsWithContacts = [select id, name,(select id,firstname, lastname,Description from Contacts) from Account where Id IN :Trigger.newMap.keySet()];         
 List<Contact> contactsToUpdate = new List<Contact>{};
    for(Account a: accountsWithContacts){
    for(Contact c: a.Contacts){
    c.Description=c.firstname+c.lastname;
    contactsToUpdate.add(c);
       }
}
update contactsToUpdate;
}
How can case owner and case team get a notification when an attachment is added to a case??
Hi All,
How to get photoURL from FeedItem object?
i have tried Createdby.smallphotourl but it's not working for FeedItem object...

I am trying to use REST API for SalesForce for that I need to Enable REST API.

for that I went through Setup -> Manage Users -> Permission Sets -> Create New, but I am seeing Insufficient Privileges page.

I am using 30 days trial version.

How can I enable REST API ?

Thanks