• Ritesh Aswaney
  • PRO
  • 3633 Points
  • Member since 2011
  • Technical Solution Architect
  • salesforce.com


  • Chatter
    Feed
  • 137
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 795
    Replies

hi group,

 

                 In E-Mail to Case what are the mandatory values to be passed . And can any one explain to me in detail about E-mail to Case, In the sense where to be used and why ...

       

     Thanks for giving reply in (advance)

                    Thanks and Regards

                            Varma

 

                                     

I'm trying to write some tests for a Visualforce controller extension, however the tests are failing because a query in the controller is not retrieving related sObjects in a query. Outside of testing (in the sandbox), the related sObjects are retrieved without issue, but in testing the related sObjects are null.

 

Here is the query code in the controller:

private void queryRel ()
{
	for (Relationship__c r : [SELECT Id,Name,Primary_Client__r.Name,Owner.Id,Owner.Name,Owner.IsActive FROM Relationship__c WHERE Id = : relId FOR UPDATE])
		rel = r;
}

 In the test environment, Owner is null.

 

Here is the setup code for the test:

List<Relationship__c> rList = [SELECT Id,OwnerId,(SELECT Id FROM Accounts__r) FROM Relationship__c];
rList[2].OwnerId = [SELECT Id FROM User WHERE IsActive = TRUE AND Id != : UserInfo.getUserId() LIMIT 1].Id;
Database.update(rList[2]);

ApexPages.StandardController sc = new ApexPages.StandardController([SELECT Id FROM Relationship__c WHERE Id = : rList[0].Id]);
RelationshipAddController rac = new RelationshipAddController(sc);
System.AssertNotEquals('fatal',rac.pageMsgSeverity,rac.pageMsgBody + rac.rel);

 Currently that first assertion fails because an internal check to verify the Owner is active fails since Owner.IsActive is null.

 

Any suggestions would be greatly appreciated.

My controller has a method that returns a list.

Based on certain criteria I would like to hide the results from the DataBlockTable. For example if Revenue__c < 300.

 

I know this could be done by changing the SOQL query to filter the results so the list just does not contain the unwanted values. However I would prefer to keep the list as is and filter on the VisualForce side. Is there a syntax to use render  within a DataBlockTable so it will conditionally show the rows?

I have a trigger that does some work when the opportunity is closed with stage=close won. But my code also checks to make sure that if I am editing an opportunity that is saved with stage=close won (that is trigger.old has stage = close won) then it should not carry out the task.

 

Trigger createRenewalOpp on opportunity(after update){

    List<Opportunity> oppList = new List<Opportunity>();
    
    //making sure that the opportunity is not already closewon
    for(Opportunity p : trigger.old) {
          if(p.stageName !='Closed Won' ){

//execute code
}
}
}

 

The problem with above code is that if I create a new opportunity and close it starught away with stage = close won (meaning trigger.old has no value) then the code following the "if" statement does not execute.

 

How can I check to create an exception for such a scenario?

 

Thank you!

 

I've to write a Simple validation in my Custom VF/Apex code where a formula field (Grand Total which depends on 3 other fields) should not exceed a set number. If it does I would write a condition in my Apex code & add a error message to page. 

My Issue is that I think formula fields are only evaluated once the record is saved & when the page loads again & that's the reason I can't check for the modified Grand Total field in my apex code when User saves a record. 

 

Any workaround this , can this be achieved through After Trigger ?

hi i want to get distinct values from the list of values

 

i have a filed called brandcategory in this i have some data from this i want get distinct values in my visualforce page

example: in my filed i have this data

1

1

2

2

3

4

5

and i have to show result in my vf like this

1;2;3;4;5



 

how can we achive this

 

can any one help me

thanks for advance to all

 

 

Hi there,

 

I have a very unique sitatuon and possible a hard one to solve. I have this Validation Rule on the Contacts

 

 

AND(

OR(ISBLANK( LeadConverted2_ctc__c ),

AND(NOT(ISNEW()),

LeadConverted2_ctc__c =1

)

),

OR(

ISBLANK( Title ),

ISBLANK( Phone ),

ISBLANK( Email )

),

NOT(ISPICKVAL( LeadSource , "XYZ")))

 

 

We have data coming from the outside source which comes as a LEAD and in that external app we do not capture Title of the Lead. So this RULE should not kick in when the data is being fed from the external app as a LEAD.

I tried to solve the above by capturing the Lead Source. But here is another challenge that I am facing:-

 

If the LEAD that is being converted has a LEAD Source = XYZ and the Contact that is being attached to also has the same LEAD Source, then the Val Rule does not get ignored and gives the error message that Title, Phone and Email is required.

 

If the Contact's LEAD Source = SFDC then the Validation Rule is easily by passed.  I want this to happen at all lead conversion.

 

I want the Validation Rule not to kick in on the Lead Conversion.

 

Can I do this with Val Rule or is APEX the answer?

 

please help

 

 

 

 

 

Hello:

 

After creating a new product, I tried uploading it into a new opportunity and an apex trigger error appeared and wouldn't allow me to go any further.  No one has ever seen this error come up before.  It only happens when trying to upload a brand new product.  The error message is:

 

 

Apex trigger OpportunityDiscountCalculation caused an unexpected exception, contact your administrator: OpportunityDiscountCalculation: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.OpportunityDiscountCalculation: line 11, column 1

 

 

I tracked down this apex trigger that was developed by our previous system admin about 2 years ago.  There is no information about whether it was created from an app we got from the AppExchange. I don't know how to deactivate it.

 

Any suggestions?

 

I appreciate your consideration!

 

 

 

I feel like I'm very close to getting this to work.  What I'm trying to do it take the user to enter a Opportunity Contact Role page once they save the Opportunity.  To do so, I'm overriding the Opportunity View button.

 

I'm good with the redirct to the Opportunity Contact Role page but the standard Opportunity page is not coming up.  I get the following error:   

 

java.lang.IllegalArgumentException: Illegal view ID OpportunityRedirect?id=006M0000004ahc8. The ID must begin with /

 

Here's my code:

public with sharing class OpportunityRedirect {
	String oppId;

	public OpportunityRedirect(ApexPages.StandardController stdController) {
		//c = stdController;
		oppId = stdController.getId();
	}
        
	public PageReference redirect() {
		PageReference pageDetail = new PageReference ('/p/opp/ContactRoleEditUi/e?oppid=' + oppId + '&retURL=' + oppId);
		pageDetail.setRedirect(true);
		
		OpportunityContactRole[] ocr = [select ContactId, Role, isPrimary from OpportunityContactRole where OpportunityId = :oppId];
		system.debug('--------------------- ocr: ' + ocr);
		if (ocr.size() == 0) return pageDetail;
		
		//PageReference pageOpportunity = new PageReference('OpportunityRedirect/?id=' + oppId);
		PageReference pageOpportunity = new PageReference('OpportunityRedirect');
		pageOpportunity.getParameters().put('id',oppId);
		pageOpportunity.setRedirect(true);
		return pageOpportunity;
	}
}

 

<apex:page standardController="Opportunity" 
		extensions="OpportunityRedirect" action="{!redirect}">
	<apex:detail />
</apex:page>

 

 

 

When you are working with object X and before you can save a related object through lookup can not have a status of Y how do you write the test code across objects?

 

Thank you,

Steve

 

Hi Everyone

 

I have two custom objects Employee (Master) , submission (Detail).My rollup in Employee gives no of submissions made by each .I need to filter these submissions based on current month and for each employee... for this  i'm planning to write a trigger . here i created a count field on employee everytime if a record enter into submission object the count should be incremented.but i need employee wise submissions count on monthly basis could you please help me out.Every time the count should be reset to zero on next month. is it better to write a trigger or a class.

 

Thanks in advance

 

I created one object, which have fields like Start date, weeks etc.,. and also i created one custom button named as "Add". 

 

Coming to my requirement, if i give start date as 6/11/2012 and weeks as 3 then click on add button i want to show the pageblock table with below columns

 

startdate , weeks, 6/11/2012, 13/11/2012, 20/11/2012. and also these 3 week values will be in input form.

 

here my main intention is, how to create these type of columns dynamically? and also how to take the week values

 because if i take week value as 5 then i want to populate the coloumns 5 times dynamically. so here main thing is weeks  and startdate. based on weeks i want to populte the columns. if i give 5 weeks then i want first column as start date and remaining 4 columns will populate with further week values. And also another thing is, after giving these values where i want to store the values. For this waht i want to create???

 

So please give the solution to me ASAP. 

 

 

thanks

gani

Hi Guys,

 

I have created a simple vf page and placed and small jQuery script in the vf page (below code). I have added this vf page as an inline VF page in the Case detail page. In the jQuery I am trying to pick up the case number by passing the id of the div in which the case number is present and alerting the result. But I am getting a blank pop-up.

But when I try the same, by placing the jQuery in the sidebar, its working just fine.

 

<apex:page standardController="Case">
<script src="/resource/jQueryLatest" type="text/javascript"></script> <script type="text/javascript"> j$(document).ready(function(){ var caseNumber = j$("#cas2_ileinner").text(); alert(caseNumber); }); </script>
</apex:Page>

 Problem: not able to access the DOM elements of the standard detail page from a jQuery script which is placed in the inline vf page on the same page.

 

please help!

 

Regards

Sam

 

 

I encountered some unexpected behavior with the save() method on the standard controller and just curious as to the reasoning behind it.

 

I have an instance of a StandardController for a new custom object.  Calling the save() method successfully inserts a new record for the custom object.  If you call save() again, it inserts another new record instead of updating the existing one in the controller's context.

 

Here's the basic code:

 

MyObject__c o = new MyObject__c();
ApexPages.StandardController sc = new ApexPages.StandardController(o);

// this successfully inserts a new record...

sc.save();

// this successfully returns the Id of the new record
// doesn't this mean that the record is in the controller's current context?

Id myId = sc.getId();

// shouldn't this update the record that is in the current context?
// it does not; it inserts a new record

sc.save();

 

Why doesn't the second call to save() update the record that was inserted in the first call to save()?   It seems to be holding on to the reference of the object that was passed into the constructor.  This would kind of make sense to me if the call to getId() returned null.  At least it would appear that the context of the controller is consistent.

Hi all,

 

Does anyone know how to achieve the funtion like web-to-lead?

I have a html that contains a form where I upload a file of chatter. After I posted the form, is there any method to receive the post? 

 

Best Regards

How can I improve code coverage for my below class?

Lines which are in red are not covered,

 

Please, help me

 

 

global class My_InsertActual_Batch implements Database.Batchable<sObject> {
    
    Public String Query;
    List<User_Budget__c> ublst = new List<User_Budget__c>();
    List<User_Budget__c> ublst1 = new List<User_Budget__c>();
    List<Commission__c> comlst = new List<Commission__c>();
    List<Commission__c> comlst1 = new List<Commission__c>();
    Set<Id> ubid = new Set<Id>();
    Set<Id> comid = new Set<Id>();
    global Database.queryLocator start(Database.BatchableContext bc) {
        Query = 'SELECT Actual_Dirty__c,Actual__c,Channel__c,Month_Year__c,OwnerId FROM User_Budget__c WHERE Actual_Dirty__c = True LIMIT 20';
        return Database.getQueryLocator(Query);
    }
    
    global void execute(Database.BatchableContext bc, LIST<SObject> lst) {
        for(sObject s : lst) {
           User_Budget__c ub = (User_Budget__c)s; 
           ubid.add(ub.OwnerId);
           ublst.add(ub);
        }
        System.Debug('$$$$$$'+ubid);
        comlst = [select id,Sales_Team_Member__c,
        Total_My_SO_Sales_January__c, Total_My_SO_Sales_February__c,Total_My_SO_Sales_March__c,
        Total_My_SO_Sales_April__c,Total_My_SO_Sales_May__c,Total_My_SO_Sales_June__c,
        Total_My_SO_Sales_July__c,Total_My_SO_Sales_August__c,Total_My_SO_Sales_September__c,
        Total_My_SO_Sales_October__c,Total_My_SO_Sales_November__c,Total_My_SO_Sales_December__c,
        Total_Cash_Carry_Sales_January__c, Total_Cash_Carry_Sales_February__c,Total_Cash_Carry_Sales_March__c,
        Total_Cash_Carry_Sales_April__c,Total_Cash_Carry_Sales_May__c,Total_Cash_Carry_Sales_June__c,
        Total_Cash_Carry_Sales_July__c,Total_Cash_Carry_Sales_August__c,Total_Cash_Carry_Sales_September__c,
        Total_Cash_Carry_Sales_October__c,Total_Cash_Carry_Sales_November__c,Total_Cash_Carry_Sales_December__c 
        from Commission__c where Sales_Team_Member__c in :ubid];
        System.debug('@@@@@'+comlst);
        for(Commission__c com : comlst) {
            comid.add(com.id);
        }
        //ublst = [SELECT Actual_Dirty__c,Actual__c,Channel__c,Month_Year__c,OwnerId FROM User_Budget__c];
        System.debug('******'+ublst);
        for(User_Budget__c u: ublst) {               
           u.Actual__c = 0;
           for(Commission__c com : comlst) {               
               //SO Sales January
               if((u.OwnerId == com.Sales_Team_Member__c) &&
               (u.Actual_Dirty__c == True)) { 
                //u.Actual__c = 0;                   
                   if(u.Channel__c == 'Special Order') {
                       If(u.Month_Year__c.month() == 1) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_My_SO_Sales_January__c;   
                       }                  
                       //SO Sales February
                       if(u.Month_Year__c.month() == 2) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_My_SO_Sales_February__c;                                
                       }     
                       //SO Sales March
                       if(u.Month_Year__c.month() == 3) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_My_SO_Sales_March__c;                                
                       }     
                       //SO Sales April
                       if(u.Month_Year__c.month() == 4) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_My_SO_Sales_April__c;                                
                       }     
                       //SO Sales May
                       if(u.Month_Year__c.month() == 5) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_My_SO_Sales_May__c;                                
                       }     
                       //SO Sales June
                       if(u.Month_Year__c.month() == 6) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_My_SO_Sales_June__c;                                
                       }     
                       //SO Sales July
                       if(u.Month_Year__c.month() == 7) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_My_SO_Sales_July__c;                                
                       }     
                       //SO Sales August
                       if(u.Month_Year__c.month() == 8) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_My_SO_Sales_August__c;                                
                       }     
                       //SO Sales September
                       if(u.Month_Year__c.month() == 9) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_My_SO_Sales_September__c;                                
                       }      
                       //SO Sales October
                       if(u.Month_Year__c.month() == 10) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_My_SO_Sales_October__c;    
                            System.debug(com.Total_My_SO_Sales_October__c+'######'+u.Actual__c+u.Month_Year__c.month()); 
                            System.debug(u.Actual_Dirty__c+'!!!!!');             
                       }  
                       //SO Sales November
                       if(u.Month_Year__c.month() == 11) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_My_SO_Sales_November__c;                                
                       }   
                       //SO Sales December
                       if(u.Month_Year__c.month() == 12) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_My_SO_Sales_December__c;                                
                       } 
                   }                
                   //CC Sales January
                   if(u.Channel__c == 'Cash & Carry') {
                       if(u.Month_Year__c.month() == 1) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_Cash_Carry_Sales_January__c; 
                           }                  
                       //CC Sales February
                       if(u.Month_Year__c.month() == 2) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_Cash_Carry_Sales_February__c;                                
                       }     
                       //CC Sales March
                       if(u.Month_Year__c.month() == 3) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_Cash_Carry_Sales_March__c;                                
                       }     
                       //CC Sales April
                       if(u.Month_Year__c.month() == 4) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_Cash_Carry_Sales_April__c;                                
                       }     
                       //CC Sales May
                       if(u.Month_Year__c.month() == 5) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_Cash_Carry_Sales_May__c;                                
                       }     
                       //CC Sales June
                       if(u.Month_Year__c.month() == 6) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_Cash_Carry_Sales_June__c;                                
                       }     
                       //CC Sales July
                       if(u.Month_Year__c.month() == 7) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_Cash_Carry_Sales_July__c;                                
                       }     
                       //CC Sales August
                       if(u.Month_Year__c.month() == 8) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_Cash_Carry_Sales_August__c;                                
                       }     
                       //CC Sales September
                       if(u.Month_Year__c.month() == 9) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_Cash_Carry_Sales_September__c;                                
                       }      
                       //CC Sales October
                       if(u.Month_Year__c.month() == 10) {
                            //u.Actual__c = 0;
                            u.Actual__c += com.Total_Cash_Carry_Sales_October__c;    
                            System.debug(com.Total_Cash_Carry_Sales_October__c+'######'+u.Actual__c+u.Month_Year__c.month()); 
                            System.debug(u.Actual_Dirty__c+'!!!!!');             
                       }  
                       //CC Sales November
                       if(u.Month_Year__c.month() == 11) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_Cash_Carry_Sales_November__c;                                
                       }   
                       //CC Sales December
                       if(u.Month_Year__c.month() == 12) {
                           //u.Actual__c = 0;
                           u.Actual__c += com.Total_Cash_Carry_Sales_December
__c;                                
                       } 
                   }
               }                  
           } 
           u.Actual_Dirty__c = False; 
           ublst1.add(u);
        }
        update ublst1;        
    }
    
    global void finish(Database.BatchableContext bc) {
         AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
         TotalJobItems, CreatedBy.Email
         FROM AsyncApexJob WHERE Id =:BC.getJobId()];
         If(a.Status == 'Completed') {
             My_scheduledActual_Batch bs = new My_scheduledActual_Batch();
             Datetime sysTime = System.now();
             sysTime = sysTime.addminutes(1);
             //String tStr = '0 05 * * * ? '; 
             String chron_exp = '' + sysTime.second() + ' ' + sysTime.minute() + ' ' +
             sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();            
             System.schedule('Update Actual'+sysTime.getTime(),chron_exp, bs);
             
         }         
         If(a.Status != 'Completed') {
              // Send an email to the Apex job's submitter notifying of job completion. 
    
               Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
               String[] toAddresses = new String[] {a.CreatedBy.Email,’mail@mail.com'};
               mail.setToAddresses(toAddresses);
               mail.setSubject('Apex Sharing Recalculation ' + a.Status);
               mail.setPlainTextBody
               ('The batch Apex job processed ' + a.TotalJobItems +
               ' batches with '+ a.NumberOfErrors + ' failures.');
               Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
               
               My_scheduledActual_Batch bs = new My_scheduledActual_Batch();
               Datetime sysTime = System.now();
               sysTime = sysTime.addminutes(6);
               //String tStr = '0 05 * * * ? '; 
               String chron_exp = '' + sysTime.second() + ' ' + sysTime.minute() + ' ' +
               sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();            
               System.schedule('Update Actual'+sysTime.getTime(),chron_exp, bs);

         }
    }
}

 

 

 

Below is my test calss:

 

@isTest
private class Test_My_InsertActual_Batch {
    static testMethod void My_InsertActual_Batch(){
        
        User u1 = [SELECT Id,Name FROM User WHERE 
        Email = 'mail@mail.com' limit 1];  
        List <User_Budget__c> ublst = new List<User_Budget__c>();
        
        for(integer i = 0; i<200; i++) {
            Date sysDate = Date.parse('1/31/2012');
            sysDate = sysDate.adddays(i);
            User_Budget__c ub = new User_Budget__c(
            Channel__c = 'Cash & Carry',
            Actual__c = 0,
            Actual_Dirty__c = True,
            Budget_Currency__c = 500,
            Month_Year__c = sysDate,
            OwnerId = u1.id);
            ublst.add(ub);
        }
        insert ublst;
        
        Test.startTest();
            My_InsertActual_Batch insact = new My_InsertActual_Batch();
            ID batchprocessid = Database.executeBatch(insact);
            My_scheduledActual_Batch bs = new My_scheduledActual_Batch();
            Datetime sysTime = System.now();
            sysTime = sysTime.addminutes(1);              
            String chron_exp = '' + sysTime.second() + ' ' + sysTime.minute() + ' ' +
            sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();            
            System.schedule('Update Actual'+sysTime.getTime(),chron_exp, bs);
        Test.stopTest();
    }
}

 

 

Hi,

 

I have a controller class and a VF page that display a list of records from which a user can select any number of records. Once a user check marks the records, they are displayed in second section of VF page.

 

Now again on second VF page (PDF page), I want to display the list again with extra information. But that list is not getting carried forward from one page to another.

 

Please suggest me as to what shall be done.

 

Thanks

Hi ,

 

I'm trying to create a custom OnClick JavaScript button that will update multiple records sterngth , weakness , opps .

 

can any one help me here

 

 {!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")}
var recordTypeName = '{!Account.RecordType}';
var idArr = {!GetRecordIds($ObjectType.Business_Plan__c)}
var BPRecordId = '';
var queryPart = "'" + idArr.join("','") + "'"

if(recordTypeName == 'Channel'){
var result = sforce.connection.query("Select Id Strengths__c, Opportunities__c, Threats__c, Weakness__c From Business_Plan__C  where Id IN ("+queryPart+")") ;
BPRecordId = result.getArray("records")[0].Id;
}
else if(recordTypeName == 'Grower' || recordTypeName == 'Lawn and Garden'){
var result = sforce.connection.query("Select Id Strengths__c, Opportunities__c, Threats__c, Weakness__c From Business_Plan__C  where Id IN ("+queryPart+")") ;
BPRecordId = result.getArray("records")[0].Id;
}
else if(recordTypeName == 'Influencer'){
var result = sforce.connection.query("Select Id Strengths__c, Opportunities__c, Threats__c, Weakness__c From   Business_Plan__C  where Id IN ("+queryPart+")") ;
BPRecordId = result.getArray("records")[0].Id;
}
else{
alert('Invalid Operation. Please contact System Admin for details!!');
}

var BPDescription = sforce.connection.describeSObject("Business_Plan__c");
var BPUrlForNew = BPDescription.urlNew.split('com')[1];
var Strenght = '{!Business_Plan__c.Strengths__c}';
var CFID = 'CF'+'00NO0000000X9xI'; // this ID is differnect with the production,please chage it after deployment
var AccountName = '{!Account.Name}';
var aid='{!Account.Id}';
var Year = '{!Business_Plan__c.Name}';
 window.top.location=BPUrlForNew+'?'+CFID+'='+AccountName+'&'+CFID+'_lkid='+aid+'&RecordType='+BPRecordId+'&'+CFID+'='+Year;

just i want to retrive month from dateofbirth field ...please help me