• Ray C. Kao
  • NEWBIE
  • 160 Points
  • Member since 2015

  • Chatter
    Feed
  • 6
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 1
    Questions
  • 19
    Replies
Hi Guys,

I would like to add record to object B using trigger, this trigger should only add record to B if record A fieldnumber is null/blank, how can we do that?

If(account.fieldnumber == null/blank/empty)

thanks
Hello, 

I have a controller which includes serveral UPDATE statements - however I am running into a code coverage error and I think it is because my UPDATE is not covered in my test class.  I tried to add it but I ran into an error.  What is the best way for me to beef up the test class for the controller below?  Thanks in advance!
 
CLASS:

public class R2MPipeLineController{

    public List<Opportunity> listOfLive {get; set;}
    public List<Opportunity> listOfViability {get; set;}
    public List<Opportunity> listOfLaunchPad {get; set;}
    public List<Opportunity> listOfContractSent {get; set;}
    public List<Opportunity> listOfQualified {get; set;}
    public Opportunity Live {get; set;}
    public Opportunity Viability {get; set;}
    public Opportunity LaunchPad {get; set;}
    public Opportunity ContractSent {get; set;}
    public Opportunity Qualified {get; set;}
    
    public PageReference saveCS(){
    UPDATE listOfContractSent;
    return null;
    }
    
    public PageReference saveVI(){
    UPDATE listOfViability;
    return null;
    }
    
    public PageReference saveLP(){
    UPDATE listOfLaunchPad;
    return null;
    }
    
    public PageReference saveQD(){
    UPDATE listOfQualified;
    return null;
    }
    
    public String getName(){
        return 'R2MPipeLineController';
        }
    
public R2MPipeLineController() {
    listofLive = [Select id, name, CreatedDate, Company_Name__c, Next_Step__c, Vertical__c, Weeks_Live__c, Days_Since_Last_Modified__c, Contract_SENT__c, NextStep, LeadSource, Probability, Spend_Last_Week__c, Spend_Last_30_Days__c, Owner_Name__c, Revenue_All_Time__c from Opportunity WHERE StageName = 'Live' ORDER BY Weeks_Live__c DESC];
    listOfViability = [Select id, name, Amount, Projected_Revenue__c, CreatedDate, Company_Name__c, Next_Step__c, Vertical__c, Weeks_Live__c, Days_Since_Last_Modified__c, Contract_SENT__c, NextStep, LeadSource, Probability, Spend_Last_Week__c, Spend_Last_30_Days__c, Owner_Name__c, Revenue_All_Time__c from Opportunity WHERE StageName = 'Viability' ORDER BY Days_Since_Last_Modified__c DESC];
    listOfLaunchPad = [Select id, name, Amount, Projected_Revenue__c, CreatedDate, Company_Name__c, Next_Step__c, Vertical__c, Weeks_Live__c, Days_Since_Last_Modified__c, Contract_SENT__c, NextStep, LeadSource, Probability, Spend_Last_Week__c, Spend_Last_30_Days__c, Owner_Name__c, Revenue_All_Time__c from Opportunity WHERE StageName = 'Launch Pad' ORDER BY Days_Since_Last_Modified__c DESC];
    listOfContractSent = [Select id, name, Amount, Projected_Revenue__c, CreatedDate, Company_Name__c, Next_Step__c, Vertical__c, Weeks_Live__c, Days_Since_Last_Modified__c, Contract_SENT__c, NextStep, LeadSource, Probability, Spend_Last_Week__c, Spend_Last_30_Days__c, Owner_Name__c, Revenue_All_Time__c, Contract_Age__c from Opportunity WHERE StageName = 'Contract Sent' ORDER BY Contract_Age__c ASC];
    listOfQualified = [Select id, name, Amount, Projected_Revenue__c, CreatedDate, Company_Name__c, Next_Step__c, Vertical__c, Weeks_Live__c, Days_Since_Last_Modified__c, Contract_SENT__c, NextStep, LeadSource, Probability, Spend_Last_Week__c, Spend_Last_30_Days__c, Owner_Name__c, Revenue_All_Time__c from Opportunity WHERE StageName = 'Qualified' ORDER BY Probability DESC]; 

}
}

And here is my test class: 
 
@isTest(seeAllData = false)
public class R2MPipeLineControllerTest{
    // Unit test Method
    static testmethod void UnitTest() {
        //Create your buyer record with required field
        //Opportunity o = new Opportunity(StageName = 'Qualified');
        //insert o;
        test.startTest();
           R2MPipeLineController qo = new R2MPipeLineController();
        test.stopTest();
    }   
}

 
Hi
I need the average amount and sum of amount from opportunity grouped by stageName.
I have given the code, but the page is displaying same values for average and sum of amount.

Am I missing anything?
global class AggregateExample
{
    //3. 
    public List<AggregateResult> aggrList=new List<AggregateResult>();
    
    //4.
    public AggregateExample()
    {
       aggrList=[select StageName,AVG(Amount),SUM(Amount) from opportunity Group By StageName limit 50000];
    }
       
    //5. create list object of wrapper class
    List<oppor_wrapper> opr=new List<oppor_wrapper>();
    
    //6.
    global List<oppor_wrapper> getResultList()
    {
       for(AggregateResult ar:aggrList)
       {
         oppor_wrapper o=new oppor_wrapper(ar);
         
         opr.add(o);
       }
        return opr;
    }

    global class oppor_wrapper
    {
       //1.
       public String StageName{get;set;}
       
       public Decimal Amount{get;set;}
       
       //2.
       public oppor_wrapper(AggregateResult aggr)
       {
         this.StageName=(String)aggr.get('StageName');
         this.Amount=(Double)aggr.get('expr0');
         this.Amount=(Decimal)aggr.get('expr1');
        
       }
    }
}
<apex:page controller="AggregateExample"
                    contentType="vnd.ms-excel#reporting.xls>
           
 <apex:pageBlock title="Result">
        <apex:pageBlockTable value="{!resultList}" 
                             var="o">
                
            <apex:column value="{!o.stageName}" 
                         headerValue="StageName" />
                         
            <apex:column value="{!o.Amount}" 
                         headerValue="AverageAmount"/>
                         
            <apex:column value="{!o.Amount}" 
                         headerValue="SumAmount"/>
                                   
                         
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

Thanks
pooja
 
I have a user who imports data in our production instance, and I wrote a scheduled apex to process that data. The most sure way to query the records to process is to use the user's LastModifiedById. However, I have to write and test the code in our sandbox, and test 75%+ to deploy to production. The user's production Id isn't recognized in sandbox, so no records are found and not enough of the code gets tested. How would you work around this?
I need to get First day from the date given.

For example consider 30/04/2015 date and it is Thrusday all I need to get next month's first Thrusday i.e, 07/05/2015 in batch class.

Please help me out of this.

Many thanks in advance
Hi,

I need to query date field from a Date/Time field in a SOQL query.

EG: [SELECT Id,StartDate FROM XYZ WHERE StartDate >=: StartTime];

StartDate = Date type
StartTime = Date/Time type


 I need to query the date in YYYY-MM-DD format, but in Date field the value being stored is YYYY-MM-DD HH:MM:SS format. So i cannot able to fetch the values.
 
There is a toast message box after close publisher. But the message box has no message! Does anyone know how to set the message in the toast message box?

Here is the code and screen...

Visualforce mobile code
<apex:page >
    <meta charset="UTF-8" />
    <apex:includeScript value="/canvas/sdk/js/publisher.js" />
    <script> 
        function closeAction() {
            Sfdc.canvas.publisher.publish({ name : "publisher.close", payload : { refresh:"false" }});
        }
    </script>

    <h1>Sample Page</h1>
    <button onclick="closeAction()">Close Action</button>
</apex:page>
Screen 1 - click "Close Action"
User-added image

Screen 2 - the next screen has a toast message but there is no message in it. How to set it?
User-added image
Hi Guys,

I would like to add record to object B using trigger, this trigger should only add record to B if record A fieldnumber is null/blank, how can we do that?

If(account.fieldnumber == null/blank/empty)

thanks
Hello,

Is it possible to send automated email notifications using workflow or process builder on a specific time zone base on the customer's location?

 
Hello, 

I have a controller which includes serveral UPDATE statements - however I am running into a code coverage error and I think it is because my UPDATE is not covered in my test class.  I tried to add it but I ran into an error.  What is the best way for me to beef up the test class for the controller below?  Thanks in advance!
 
CLASS:

public class R2MPipeLineController{

    public List<Opportunity> listOfLive {get; set;}
    public List<Opportunity> listOfViability {get; set;}
    public List<Opportunity> listOfLaunchPad {get; set;}
    public List<Opportunity> listOfContractSent {get; set;}
    public List<Opportunity> listOfQualified {get; set;}
    public Opportunity Live {get; set;}
    public Opportunity Viability {get; set;}
    public Opportunity LaunchPad {get; set;}
    public Opportunity ContractSent {get; set;}
    public Opportunity Qualified {get; set;}
    
    public PageReference saveCS(){
    UPDATE listOfContractSent;
    return null;
    }
    
    public PageReference saveVI(){
    UPDATE listOfViability;
    return null;
    }
    
    public PageReference saveLP(){
    UPDATE listOfLaunchPad;
    return null;
    }
    
    public PageReference saveQD(){
    UPDATE listOfQualified;
    return null;
    }
    
    public String getName(){
        return 'R2MPipeLineController';
        }
    
public R2MPipeLineController() {
    listofLive = [Select id, name, CreatedDate, Company_Name__c, Next_Step__c, Vertical__c, Weeks_Live__c, Days_Since_Last_Modified__c, Contract_SENT__c, NextStep, LeadSource, Probability, Spend_Last_Week__c, Spend_Last_30_Days__c, Owner_Name__c, Revenue_All_Time__c from Opportunity WHERE StageName = 'Live' ORDER BY Weeks_Live__c DESC];
    listOfViability = [Select id, name, Amount, Projected_Revenue__c, CreatedDate, Company_Name__c, Next_Step__c, Vertical__c, Weeks_Live__c, Days_Since_Last_Modified__c, Contract_SENT__c, NextStep, LeadSource, Probability, Spend_Last_Week__c, Spend_Last_30_Days__c, Owner_Name__c, Revenue_All_Time__c from Opportunity WHERE StageName = 'Viability' ORDER BY Days_Since_Last_Modified__c DESC];
    listOfLaunchPad = [Select id, name, Amount, Projected_Revenue__c, CreatedDate, Company_Name__c, Next_Step__c, Vertical__c, Weeks_Live__c, Days_Since_Last_Modified__c, Contract_SENT__c, NextStep, LeadSource, Probability, Spend_Last_Week__c, Spend_Last_30_Days__c, Owner_Name__c, Revenue_All_Time__c from Opportunity WHERE StageName = 'Launch Pad' ORDER BY Days_Since_Last_Modified__c DESC];
    listOfContractSent = [Select id, name, Amount, Projected_Revenue__c, CreatedDate, Company_Name__c, Next_Step__c, Vertical__c, Weeks_Live__c, Days_Since_Last_Modified__c, Contract_SENT__c, NextStep, LeadSource, Probability, Spend_Last_Week__c, Spend_Last_30_Days__c, Owner_Name__c, Revenue_All_Time__c, Contract_Age__c from Opportunity WHERE StageName = 'Contract Sent' ORDER BY Contract_Age__c ASC];
    listOfQualified = [Select id, name, Amount, Projected_Revenue__c, CreatedDate, Company_Name__c, Next_Step__c, Vertical__c, Weeks_Live__c, Days_Since_Last_Modified__c, Contract_SENT__c, NextStep, LeadSource, Probability, Spend_Last_Week__c, Spend_Last_30_Days__c, Owner_Name__c, Revenue_All_Time__c from Opportunity WHERE StageName = 'Qualified' ORDER BY Probability DESC]; 

}
}

And here is my test class: 
 
@isTest(seeAllData = false)
public class R2MPipeLineControllerTest{
    // Unit test Method
    static testmethod void UnitTest() {
        //Create your buyer record with required field
        //Opportunity o = new Opportunity(StageName = 'Qualified');
        //insert o;
        test.startTest();
           R2MPipeLineController qo = new R2MPipeLineController();
        test.stopTest();
    }   
}

 
Hi
I need the average amount and sum of amount from opportunity grouped by stageName.
I have given the code, but the page is displaying same values for average and sum of amount.

Am I missing anything?
global class AggregateExample
{
    //3. 
    public List<AggregateResult> aggrList=new List<AggregateResult>();
    
    //4.
    public AggregateExample()
    {
       aggrList=[select StageName,AVG(Amount),SUM(Amount) from opportunity Group By StageName limit 50000];
    }
       
    //5. create list object of wrapper class
    List<oppor_wrapper> opr=new List<oppor_wrapper>();
    
    //6.
    global List<oppor_wrapper> getResultList()
    {
       for(AggregateResult ar:aggrList)
       {
         oppor_wrapper o=new oppor_wrapper(ar);
         
         opr.add(o);
       }
        return opr;
    }

    global class oppor_wrapper
    {
       //1.
       public String StageName{get;set;}
       
       public Decimal Amount{get;set;}
       
       //2.
       public oppor_wrapper(AggregateResult aggr)
       {
         this.StageName=(String)aggr.get('StageName');
         this.Amount=(Double)aggr.get('expr0');
         this.Amount=(Decimal)aggr.get('expr1');
        
       }
    }
}
<apex:page controller="AggregateExample"
                    contentType="vnd.ms-excel#reporting.xls>
           
 <apex:pageBlock title="Result">
        <apex:pageBlockTable value="{!resultList}" 
                             var="o">
                
            <apex:column value="{!o.stageName}" 
                         headerValue="StageName" />
                         
            <apex:column value="{!o.Amount}" 
                         headerValue="AverageAmount"/>
                         
            <apex:column value="{!o.Amount}" 
                         headerValue="SumAmount"/>
                                   
                         
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

Thanks
pooja
 
when we want disable all the validationrules for a specific user on all the sobjects how we can achieve this give me some examples
and how to deactivate the triggers for a specific user
Hi,

I'm trying to create a new Master Detail Relationship between two objects, however I'm recieving this error message:

You must first create a Lookup relationship, populate the lookup field with data in all records, and then change the relationship type to Master-Detail. 

Which seems pretty straight forward, except I'm not sure how to populate the lookup field with the data. Can someone point me in thr right direction?
I see one of our contacts from an account has been deleted. I tried restoring it from Recycle bin. But I don't see the contact in there. Is there any other way of undeleting the contact? I've the all the necessary information about the contact - First name, Last name, Contact ID, Account name.

Please provide step by step instuctions to do the same. Thanks in advance!
Hi,

Can U please modify this trigger to call Future class. May be this solution work.
Trigger TaskTrigger on Task(after insert, after delete, after undelete) {
    Set<Id> accountIds = new Set<Id>();
    for(Task tsk : trigger.isDelete ? trigger.old : trigger.new) {
        accountIds.add(tsk.AccountId);
    }
    AggregateResult[] groupedResults = [SELECT Count(Id), AccountId FROM Task group by AccountId having AccountId in: accountIds];
    Map<Id,Integer> taksCountMap = new Map<Id,Integer>();
    for (AggregateResult ar : groupedResults)  {
        taksCountMap.put((Id)ar.get('AccountId'),Integer.valueOf(ar.get('expr0')));
    }
    
    List<Account> accUpdLst = new List<Account>();
    //Updating the count field
    for(Task tsk: trigger.new) {   
        if(taksCountMap.containsKey(tsk.AccountId))
            accUpdLst.add(new Account(Id = tsk.AccountId,count__c = taksCountMap.get(tsk.AccountId)));
    }
    
    if(accUpdLst.size() > 0) {
        update accUpdLst;
    }
}

 
HI, I have a problem with this trigger, I am not able to update the fields contact_lago__c :(
Here's the code:
//this trigger assign an owner for each Candidatura Discover based on score.
trigger AssignOwnerDiscover on Candidatura_Tenant__c (before insert,before update) {
    //Set<ID> ids = Trigger.newMap.keySet();
    List<Candidatura_Tenant__c> c = [SELECT Id,punteggio__c,contact_lago__c,Lead__r.Country FROM Candidatura_Tenant__c WHERE Id in :Trigger.newMap.keySet()];
    if (c.size()==0)
        return;
    for(Candidatura_Tenant__c i: c){
        if(i.punteggio__c >=21){
            if(i.Lead__r.Country=='IT')
                i.contact_lago__c ='003c000000hafFz';
            else 
                i.contact_lago__c ='003a000001v34dh';
        }
        else{
                if(i.punteggio__c >14)
                    i.contact_lago__c ='00313000028crUg';
                else
                    i.contact_lago__c =i.Lead__r.Agente__c;
        }
   }
}
Thanks in advance!
I have a user who imports data in our production instance, and I wrote a scheduled apex to process that data. The most sure way to query the records to process is to use the user's LastModifiedById. However, I have to write and test the code in our sandbox, and test 75%+ to deploy to production. The user's production Id isn't recognized in sandbox, so no records are found and not enough of the code gets tested. How would you work around this?
Hi,

How to avoid Too many queries rows 500001 in the apex class.

I have one query 
list<Account> acc = [select id,Fax from Account];

As per requirement i dont need to use where condition in the above query .............

Any suggestions,
Regards,
VSK
  • May 03, 2016
  • Like
  • 0
Hi, 
I saved the trigger sucessully, however, when I am saving  the BLC_Lead__c record from UI, then I am getting the error in the bold font written line and the error is  Salesforce - Unlimited EditionSystem.NullPointerException: Attempt to de-reference a null object: Trigger.EnableCurfewedOnLeads: line 23, column 1 :


trigger EnableCurfewedOnLeads on BLC_Lead__c (before update) {

//Iterate over all the Leads to retrieve the Curfew ID
   Set<Id> setCurfewIds = new Set<Id>();
     for(BLC_Lead__c blcLead : Trigger.new){
     
       setCurfewIds.add(blcLead.Call_Curfew_Details__r.id);      
       
        }
        

//  Retrieve all Curfews and create a map of Curfews

  Map<Id,Call_Curfew_Details__c>  mapCurfews = new Map<Id,Call_Curfew_Details__c>([SELECT Id, IsCurfew__c FROM Call_Curfew_Details__c where Id IN:setCurfewIds]);
  
    
    
//Iterate all over the Leads and Populate the flag isCurfew = TRUE
    for(BLC_Lead__c leds: Trigger.new){
    
if(leds != null && leds != null){        
         Call_Curfew_Details__c relatedCurfews =  mapCurfews.get(leds.Call_Curfew_Details__r.id);          leds.IsCurfew__c =  relatedCurfews.IsCurfew__c;        
          }        
       }    

    }
I have created a VF page and controller to add new user records, I am setting all relevant fields (I think), but I keep getting this error message:

Insert failed. First exception on row 0; first error: LICENSE_LIMIT_EXCEEDED, content feature license limit exceeded: []

I am setting profile, and have seen several posts that talk about setting the UserType but SF tells me that this field is not writeable.

I have plenty of licenses left in my dev org so not sure where the problem is. Am I missing a key field somewhere?

Here is the code excerpt:
// FIRST build default details based on current user		

// Establish current user and fetch details to copy
currentUser = [select CompanyName,					
				Country,											
				EmailEncodingKey,			
				LanguageLocaleKey,		
				LocaleSidKey,				
				TimeZoneSidKey,
				UserType				
			from User
				where id = :UserInfo.getUserId()];
						            	
// Copy to new user object
newUser = currentUser.clone(false, true);		

// Create all other details (NB: Fname, Lname, email in VF page)

// Set user licence and profile
 if (sysAdmin) {
 	newUser.ProfileId = sysAdminProfileID;	
 } else {
 	newUser.ProfileId = userProfileID;	 			
 }
 		
 // Set other fields
newUser.isActive = true;												
newUser.UserRole = null;												
newUser.UserName = newUser.Email;										
newUser.Alias = createUserAlias(newUser.FirstName, newUser.LastName);	
newUser.CommunityNickname = newUser.FirstName;							
newUser.ReceivesInfoEmails = false;										
newUser.ReceivesAdminInfoEmails = false;								
newUser.UserPreferencesApexPagesDeveloperMode = false;					
    
 // DML to ensure password generated 
Database.DMLOptions dmlo = new Database.DMLOptions();
dmlo.EmailHeader.triggerUserEmail = true;
dmlo.EmailHeader.triggerAutoResponseEmail= true;
newUser.setOptions(dmlo);

 try {
 	insert newUser;
 } catch (exception e) {
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, e.getMessage()));
         return false; 			
 }

 
I need to get First day from the date given.

For example consider 30/04/2015 date and it is Thrusday all I need to get next month's first Thrusday i.e, 07/05/2015 in batch class.

Please help me out of this.

Many thanks in advance
Hi All,

I m very new to salesforce and I m wondering if there is a way to hide custom fileds on custom Objects  if there is no value entered in them?

Thanks,
Hi,

I need to query date field from a Date/Time field in a SOQL query.

EG: [SELECT Id,StartDate FROM XYZ WHERE StartDate >=: StartTime];

StartDate = Date type
StartTime = Date/Time type


 I need to query the date in YYYY-MM-DD format, but in Date field the value being stored is YYYY-MM-DD HH:MM:SS format. So i cannot able to fetch the values.
 
Hi, i have an entitlement process which its 'Case enters the process' = Based on a custom date/time field on the case: SLA Cont Time

and under this entitlement process i have a milestone it's Start time = 'Entitlement Process'

but whenever my case being assigned to to this entitlement, the milestone start time always show case created date. shouldn't it be my custom date/time field: SLA Cont Time?

ps: my SLA cont time is different from case created date
thanks.
Can anybody tell how to read the barcode from the image and display the product information details regarding the barcode image.

Using EAN 128 image format. It should accept only EAN 128 image format. 

Thanks in advance.