• varun_vatsa
  • NEWBIE
  • 34 Points
  • Member since 2014
  • Sr Solution Architect
  • Appirio


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 27
    Replies
Hi folks, hope you can help.

I'm trying to edit a trigger on the case object that forms part of the Round Robin Record Assignment app from the Appexchange however I'm having issues with it and could do with some help.

In the comments listed here: https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000178fsEAA&revId=a0S30000000fPTLEA2&tab=r (https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000178fsEAA&revId=a0S30000000fPTLEA2&tab=r) it provides instructions on how to edit the trigger to prevent having to change the record owner twice when having to manually reassign a record to another user.

When editing the trigger in Sandbox I get the following error and I don't know why:
Error: Compile Error: line 87:44 no viable alternative at character '”' at line 87 column 44
Please can you help me understand what I'm doing wrong.

The only thing I'm changing in the trigger is:
Trigger.new[i].TempOwnerId__c = ag.User__c;
and changing it to:
Trigger.new[i].TempOwnerId__c = ”;

Really hope you can help folks, thanks for your help in advance.

Many thanks,
Dave
I am trying to pass values to a master detail field in my Test Class. I tried to pass values as I do for normal fields, but it is throwing Error.

Can any one suggest me how can i do this
So I uninstalled a package we no longer used earlier today which I assume has brought down our average test coverage.

I'm now trying to deploy an updated version of an existing class and its failing obviously due to low code coverage.  So sort this I have written a test class in our sandbox which runs fine and works with one of the existing classes in my production org.  However if I try to deploy the change set from my sandbox to production it is failing again due to code coverage.

How on earth am I meant to boost the test coverage if I cannot deploy new test classes????
  • June 22, 2015
  • Like
  • 0
This is my Class and you can see the test class I have written for this but covering only 50%.

public class OverrideNewButtonComponentController {
    Public string sObjectType {get; set;}
    Public string keyPrefix {get; set;}
    Public string infoProLabel {get; set;}
    Public string infoProLawonLabel {get; set;}
    
    List<Line_of_Business__c > listInfoProLawson = new List<Line_of_Business__c >();
    public OverrideNewButtonComponentController(String sobjectName, String objPrefix) {
        sObjectType=sobjectName;
        keyPrefix=objPrefix;
    }
    public OverrideNewButtonComponentController(){}

    public PageReference init() {
           
          if (ApexPages.currentPage().getParameters().get('RecordType') == null) {
          Schema.DescribeSObjectResult describeLead = Schema.SObjectType.Lead;
          List<Schema.RecordTypeInfo> rtInfos = describeLead.getRecordTypeInfos();
          for(Schema.RecordTypeInfo rtInfo : rtInfos) {
            if(rtInfo.getName() != 'Master' && rtInfo.isAvailable()) {
            ApexPages.currentPage().getParameters().put('RecordType', rtInfo.getRecordTypeId());
           }
          }
          
         }

        String userLawson = String.Valueof([Select id, Lawson_Division__c from User where id = : Userinfo.getUSerId()].Lawson_Division__c);




        if (userLawson != null) {
            listInfoProLawson = [SELECT Id, Name, Lawson_Division__c, Infopro_Division__r.Name from Line_of_Business__c where Lawson_Division__r.Name = :userLawson];
            system.debug('sObjectType==' + sObjectType);
            if (listInfoProLawson.size() >= 1 && listInfoProLawson.get(0).Name != null && listInfoProLawson.get(0).Infopro_Division__r.Name != null) {
                String labelVal ;
                if(sObjectType=='Opportunity')
                    labelVal = System.Label.OpportunityNewButtonOverRideLabel;
                else if(sObjectType=='Lead')
                    labelVal= System.Label.LeadNewButtonOverRideLabel;
                labelVal = labelVal.trim();
                List<String> labels = labelVal.split(',');
                System.debug('labels==' + labels);
                infoProLawonLabel = labels.get(0).trim();
                infoProLabel = labels.get(1).trim();
                System.debug(sObjectType+'sObjectTypes---');

                //return new PageReference('/setup/ui/recordtypeselect.jsp?ent=' + sObjectType + '&nooverride=1&retURL=%2F'+keyPrefix+'%2Fo&save_new_url=%2F'+keyPrefix+'%2Fe%3FretURL%3D%252F'+keyPrefix+'%252Fo&' + infoProLawonLabel + '=' + listInfoProLawson.get(0).Name + '&' + infoProLawonLabel + '_lkid=' + listInfoProLawson.get(0).Id + '&' + infoProLabel + '=' + listInfoProLawson.get(0).Infopro_Division__r.Name);
                if(sObjectType=='Lead' && (ApexPages.currentPage().getParameters().get('RecordType') == Schema.SObjectType.Lead.getRecordTypeInfosByName().get('Field Sales Lead').getRecordTypeId() || ApexPages.currentPage().getParameters().get('RecordType') == Schema.SObjectType.Lead.getRecordTypeInfosByName().get('Refer Republic Lead').getRecordTypeId())){
                    Pagereference page = new PageReference('/'+keyPrefix+'/e?nooverride=1&retURL=%2F'+keyPrefix+'%2Fo&save_new_url=%2F'+keyPrefix+'%2Fe%3FretURL%3D%252F'+keyPrefix+'%252Fo&' + infoProLawonLabel + '=' + listInfoProLawson.get(0).Name + '&' + infoProLawonLabel + '_lkid=' + listInfoProLawson.get(0).Id + '&' + infoProLabel + '=' + listInfoProLawson.get(0).Infopro_Division__r.Name + '&lea16country=USA');
                    //page.setRedirect(true);
                    return page;
                }
                else if(sObjectType=='Opportunity' && (ApexPages.currentPage().getParameters().get('RecordType') == Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Field Sales Opportunity').getRecordTypeId())){
                System.debug(sObjectType+'inside sObjectTypes---');
                    Pagereference page = new PageReference('/'+keyPrefix+'/e?nooverride=1&retURL=%2F'+keyPrefix+'%2Fo&save_new_url=%2F'+keyPrefix+'%2Fe%3FretURL%3D%252F'+keyPrefix+'%252Fo&' + infoProLawonLabel + '=' + listInfoProLawson.get(0).Name + '&' + infoProLawonLabel + '_lkid=' + listInfoProLawson.get(0).Id + '&' + infoProLabel + '=' + listInfoProLawson.get(0).Infopro_Division__r.Name);
                    //page.setRedirect(true);
                    return page;
                }
                return new PageReference('/'+keyPrefix+'/e?nooverride=1&retURL=%2F'+keyPrefix+'%2Fo&save_new_url=%2F'+keyPrefix+'%2Fe%3FretURL%3D%252F'+keyPrefix+'%252Fo&' + infoProLawonLabel + '=' + listInfoProLawson.get(0).Name + '&' + infoProLawonLabel + '_lkid=' + listInfoProLawson.get(0).Id + '&' + infoProLabel + '=' + listInfoProLawson.get(0).Infopro_Division__r.Name + '&RecordType='+ApexPages.currentPage().getParameters().get('RecordType'));
            }
        }

            //return new PageReference('/setup/ui/recordtypeselect.jsp?ent=' + sObjectType + '&nooverride=1&retURL=%2F'+keyPrefix+'%2Fo&save_new_url=%2F'+keyPrefix+'%2Fe%3FretURL%3D%252F'+keyPrefix+'%252Fo');
        if(sObjectType=='Lead' && (ApexPages.currentPage().getParameters().get('RecordType') == Schema.SObjectType.Lead.getRecordTypeInfosByName().get('Field Sales Lead').getRecordTypeId() || ApexPages.currentPage().getParameters().get('RecordType') == Schema.SObjectType.Lead.getRecordTypeInfosByName().get('Refer Republic Lead').getRecordTypeId())){
            return new PageReference('/'+keyPrefix+'/e?nooverride=1&retURL=%2F'+keyPrefix+'%2Fo&save_new_url=%2F'+keyPrefix+'%2Fe%3FretURL%3D%252F'+keyPrefix+'%252Fo&lea16country=USA&RecordType='+ApexPages.currentPage().getParameters().get('RecordType'));
        }
        else if(sObjectType=='Opportunity' && (ApexPages.currentPage().getParameters().get('RecordType') == Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Field Sales Opportunity').getRecordTypeId())){
            return new PageReference('/'+keyPrefix+'/e?nooverride=1&retURL=%2F'+keyPrefix+'%2Fo&save_new_url=%2F'+keyPrefix+'%2Fe%3FretURL%3D%252F'+keyPrefix+'%252Fo');
        }
        else if(sObjectType=='Lead' && (ApexPages.currentPage().getParameters().get('RecordType') == Schema.SObjectType.Lead.getRecordTypeInfosByName().get('Special Waste Leads').getRecordTypeId())){
           return new PageReference('/apex/SPWLead?ent=Lead&RecordType='+ApexPages.currentPage().getParameters().get('RecordType')+'&retURL=SPWLead&save_new_url=00Q/e');
        }    
        return new PageReference('/'+keyPrefix+'/e?nooverride=1&retURL=%2F'+keyPrefix+'%2Fo&save_new_url=%2F'+keyPrefix+'%2Fe%3FretURL%3D%252F'+keyPrefix+'%252Fo&RecordType='+ApexPages.currentPage().getParameters().get('RecordType'));
    }


}




Here is the test class I have written.


@istest private class TestOverrideNewButtonComponentController { Static testmethod void OverrideNewButtonComponentController() { OverrideNewButtonComponentController ride = new OverrideNewButtonComponentController();  ride.init(); OverrideNewButtonComponentController controller = new OverrideNewButtonComponentController();      String sbjname='Lead';       String  sbjprefix='00Q';              List<Line_of_Business__c > lst = new List<Line_of_Business__c >(); Line_of_Business__c  lb1=new Line_of_Business__c(); Lawson_Division__c   ld1 = new Lawson_Division__c(); Infopro_Division__c  id1 = new Infopro_Division__c(); Profile p = [SELECT Id FROM Profile WHERE Name='field sales']; User u = new User(Alias = 'standt1', Email='standarduser1@testorg.com', EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = p.Id, TimeZoneSidKey='America/Los_Angeles', UserName='myorg1@testorg.com'); System.runAs(u) { ld1.name = 'test'; insert ld1; id1.name = 'testinfo'; insert id1; lb1.name = 'testLawson'; //lb1.Infopro_Division__c = 'testinfo1'; //lb1.Lawson_Division__c = 'test1'; //insert lb1; } } //user U = new user (  }


Please help me in covering the full class.
Hi,

I'm just wondering which order I should learn these in, and if it matters.

Thanks,
Wyatt
trigger CaseTrigger on Case (before insert,before update,after insert,after update) {
    
    if((trigger.isBefore && trigger.isInsert) ||  (trigger.isBefore && trigger.IsUpdate)){
       set<Id> accIdSet = new Set<Id>();
        for(Case cs :  trigger.new){
            if(cs.AccountId !=null){
                accIdSet.add(cs.AccountId);

            }
         }
        system.debug('accIdSet==>'+accIdSet);
        if(accIdSet !=null && accIdSet.size()>0){
            Map<Id,Account> accMap = new Map<Id,Account>([Select id,Name,Device_Replacement__c from account where id in :accIdSet]);
            system.debug('accMap==>'+accMap);
            for(Case cs: trigger.new){
                if(cs.Roku_Offer__c !=null && accMap.get(cs.AccountId).Device_Replacement__c !='Eligible'){
                    cs.addError('Roku offer is not available on this Case Account.');
                }
            }
                
        }
    }
    
    if(trigger.isAfter  &&  (trigger.isUpdate || trigger.isInsert)){
        system.debug('trigger.isAfter==>');
        Map<Id,Account> accUpdateMap = new Map<Id,Account>();
        for(Case cs:trigger.new){
            if(cs.AccountId !=null && cs.Roku_Offer__c !=null){
                accUpdateMap.put(cs.AccountId,new Account(id=cs.AccountId,Device_Replacement__c='Completed'));
                
            }
        }
        system.debug('accUpdateMap==>'+accUpdateMap);
        if(accUpdateMap !=null && accUpdateMap.size()>0){
            update accUpdateMap.values();
        }
    }
    
  
}
Hi,

I have a simple SOQL query which is executed many times.

for(1000 times){
List<custom_Object_c > pList = [SELECT x__c FROM custom_Object_c ];
}

It gives me error that i execute more than required queries and gives a exception on page.

I want to find a solution where it will not give exception on page and execute the maximum times it could and retrived the maxium number of data in pList  and continue with that list, it may ignore the rest.

What can be solution.
Dear All,

I would like to retrive the data from Lookup Relationship Object A1 and Child Object Data of B2 fields 
Example:  Account --Object Name
                   Main Contact: Lookup Name
                   Contact Object is Havng child Relationship with Country Object
Now my Question is I would liket o Fetch Account fields Data, Contacts Field Data and Country Object Field Data

Here is my planned query:

Select Name, MainContact__r.Country__r.Name FROM Account__c

as per my above query its not allowing me to write lookup to child object relationship

Can some one help me?


Thanks & Regards,




 
I've got a Batchable Apex test I've created that is throwing the following error:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, setTrainingAccountId: execution of BeforeInsert

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.setTrainingAccountId: line 55, column 1: []

I'm not sure why the Trigger is affecting my Test Class Execution. I haven't been able to pinpoint the exact issue. Any ideas?

Trigger
trigger setTrainingAccountId on Training__c (before insert, before update, after insert, after update, after delete, after undelete) {
    set<Id> setAttendees = new set<Id>();
    set<Id> setCourses = new set<Id>();

  set<Id> setUnknownAccounts = new set<Id>();
  
  for(Account a : [
    SELECT
      Id
    FROM
      Account
    WHERE
      Name LIKE '%End%User%'
      OR Name LIKe '%User%End'
  ]){
    setUnknownAccounts.add(a.Id);
  }
    
    if(trigger.isDelete){
        for(Training__c t : trigger.old){
            setAttendees.add(t.Attendee__c);
            setCourses.add(t.Course_or_Module__c);
        }
    }else{
        for(Training__c t : trigger.new){
            setAttendees.add(t.Attendee__c);
            setCourses.add(t.Course_or_Module__c);
        }
    }
    
    map<Id,Contact> mapContactAccount = new map<Id,Contact>([
    SELECT
            Id,
            AccountId
        FROM
            Contact
        WHERE
            Id IN : setAttendees
    ]);
    
    //map<Id, Course__c> mapCourses = new map<Id, Course__c>([SELECT Name, Duration_Hours__c FROM Course__c WHERE Id IN : setCourses]);
    map<Id,Course__c> mapCourses = new map<Id,Course__c>([
        SELECT
            Id,
            Name
        FROM
            Course__c
        WHERE
            Id IN : setCourses
    ]);
    
    //Jade Update : Account field update with current contact's account
    if(trigger.isBefore){
        for(Training__c t : trigger.new){
          if(setUnknownAccounts.contains(mapContactAccount.get(t.Attendee__c).AccountId)){
          t.addError('Assigning Training to a Contact associated with an Unknown End User Account is not allowed. Pleae assign the Contact to an existing Account or create a new one first.');
        }
            t.Account__c = mapContactAccount.get(t.Attendee__c).AccountId;
        }
    }
    /* if(trigger.isBefore){
        for(Training__c t : trigger.new){
            t.Account__c = mapContactAccount.get(t.Attendee__c).AccountId;
            if(t.Duration_Hours__c == null && trigger.isInsert){
                t.Duration_Hours__c = mapCourses.get(t.Course_or_Module__c).Duration_Hours__c;
            }
        }
    } */
    
    if(trigger.isAfter){
        set<Id> setAccounts = new set<Id>();
        
        if(trigger.isDelete){
            for(Training__c t : trigger.old){
                if(t.Course_or_Module__c != null){
                    if(
                        mapCourses.get(t.Course_or_Module__c).Name.startsWithIgnoreCase('pivCLASS Advanced Training')
                        || mapCourses.get(t.Course_or_Module__c).Name.startsWithIgnoreCase('pivCLASS PKI @ the Door Training')
                        || mapCourses.get(t.Course_or_Module__c).Name.startsWithIgnoreCase('pivCLASS Software Training')
                    ){
                        setAccounts.add(mapContactAccount.get(t.Attendee__c).AccountId);
                    }
                }
            }
        }else{
            for(Training__c t : trigger.new){
                if(t.Course_or_Module__c != null){
                    if(
                        mapCourses.get(t.Course_or_Module__c).Name.startsWithIgnoreCase('pivCLASS Advanced Training')
                        || mapCourses.get(t.Course_or_Module__c).Name.startsWithIgnoreCase('pivCLASS PKI @ the Door Training')
                        || mapCourses.get(t.Course_or_Module__c).Name.startsWithIgnoreCase('pivCLASS Software Training')
                    ){
                        setAccounts.add(mapContactAccount.get(t.Attendee__c).AccountId);
                    }
                }
            }
        }
        
        if(!setAccounts.isEmpty()){
            accountCertifications accountCertifications = new accountCertifications();
            accountCertifications.setAccountCertifications(setAccounts);
        }
    }
}

Test Class
@isTest
public class TestBatchUpdateTraining {

    Static testmethod void test(){
String Query = 'SELECT id,Training_Status__c,Expiry_Date__c FROM Training__c WHERE Expiry_Date__c < Today';
     

    
Training__c[] ml = new List<Training__c>();
        date mydate = date.parse('5/11/2014');
       for (Integer i=0;i<10;i++) {
           Training__c m = new Training__c(
               Course_or_Module__c= 'a0vn0000000EZsJ',
               Account__c = '001n0000005m8G0',
               Attendee__c ='003n0000006QMkP', //Learner
               Training_Status__c='Completed',
           		Expiry_Date__c = mydate);
           ml.add(m);
           System.debug(ml);
       }
    insert ml;
    
    Test.startTest();
    BatchUpdateTraining bit = new BatchUpdateTraining();
    Database.executeBatch(bit);
    Test.stopTest();
    
    Integer i = [SELECT COUNT() FROM Training__c WHERE Training_Status__c = 'Expired'];
    System.assertEquals(i, 0);
    }
}

Batch Update
global class BatchUpdateTraining implements Database.Batchable<sobject> {

     public String Query;

     public Database.QueryLocator start(Database.BatchableContext BC)  {  

        Query = 'SELECT id,Training_Status__c,Expiry_Date__c FROM Training__c WHERE Expiry_Date__c < Today';
		
        return Database.getQueryLocator(Query); 

    }

     public void execute(Database.BatchableContext BC, List<Training__c> scope) { 
        List<Training__c> tr = new List<Training__c>(); 
		System.debug(scope);
        for (Training__c ac : scope)  {
		ac.Training_Status__c = 'Expired';
        tr.add(ac);
        System.debug(tr.size());

       }

           update tr;
     }

 
    public void finish(Database.BatchableContext BC) {   
    AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
      TotalJobItems, CreatedDate, CreatedBy.Email
      FROM AsyncApexJob WHERE Id =
      :BC.getJobId()];
	Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    List<String> toAddresses = new List<String> {a.CreatedBy.Email};
        mail.setToAddresses(toAddresses);
        mail.setSubject('Training Expiration Job Processed ' + a.Status);
        mail.setPlainTextBody('The batch Apex job processed ' + a.TotalJobItems + ' batches with ' + a.NumberOfErrors + ' failures' + a.CreatedDate + 'Date Ran');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
   }

}

 
I am a new for the regex, so can any good people can help me answer these question? thanks....

this is my email:

Order Number: 2000157
Date Ordered: Wednesday, May 21, 2014
http://www.ggfoee.com/orderdetails.aspx?orderid=2000157
Link to Back End Order Details   


CUSTOMER ROLE: Parent 
PAYMENT METHOD: PayPal Standard 
PAYMENT STATUS: Pending 
PO URL:  No Purchase Order File Uploaded 
PO  #: 
COUPON CODE:  No coupon used 
No Comment or Instructions Given
Billing Address
Name: lacy mason
Company: Mason Tool & Engineering Ltd
Address: Unit 8/ 66 Hobill Ave,
Wiri
City: Auckland, 2241
State/Province: North Island, Ireland
Phone: 021735562


My question is:
How to use regex get those info?: Date ordered, Payment Method, Payment Status, Name, company name, Address and Phone number.
you don't need answer all, just answer what you know it. thank you again...:)
  • April 19, 2015
  • Like
  • 0
I need to display the search results of a SOQL query in a Visualforce page. The results should be displayed in a list (e.g. 7 Contacts are returned in the search results - the list would have 7 rows). Can I do this without a controller class? I already have the search results. I do not need to run another query. I simply need a Visualforce page to display the results. If I have to use a controller class is there a way to pass the search results (i.e. list of objects) into the controller via the ApexPages.currentPage().getParameters() method or by some other means? Or is there another way to display the results without even using the Visualforce page?

Thanks!
Hi,
 

I am new to salesforce environment. AS per of my client requirement I need to integrate spring mvc3( hibernate + mysql) which is already developed in salesforce environment.

Here my problem listed down below. Could some one please guide me. Thanks
1, Is it possible ?
2. If yes,rFrom wahere to start  ?
3. What needs to learn? .
4. does this suppost spring mvc+ hibernate+mysql

Thanks,
Babu G

Summary:

My trigger is supposed to update a custom field on the related Account called Owner_s_Last_Activity_Date__c with the CreatedDate of the Task any time a new task created on the Account is assigned to the Account owner.  The trigger works great in the positive case (i.e. the Related Account lookup is populated), but I'm getting a null pointer exception any time the related Account lookup is null.  I know I need to filter tasks with no related Account out of my trigger logic, but I just can't seem to figure out how to do it.  Any help would be greatly appreciated.  Thanks!

trigger UpdateAccountFromActivity on Task (after insert) {

  Map<ID, Account> parentAccts = new Map<ID, Account>();
  List<Id> listIds = new List<Id>();

  for (Task task : Trigger.new){
    if(task.AccountId!=null)
      listIds.add(task.AccountId);
  }
   
  parentAccts = new Map<Id, Account>([SELECT ID, Owner_s_Last_Activity__c, OwnerID, (SELECT ID, CreatedDate, OwnerId, AccountID FROM Tasks WHERE AccountID!=null ) FROM Account WHERE ID IN :listIds]);

  for (Task task: Trigger.new){
      Account myParentAcc = parentAccts.get(task.AccountId);
      if(myParentAcc.OwnerId == task.OwnerId && task.AccountID != null){
       myParentAcc.Owner_s_Last_Activity__c = task.CreatedDate;
        }     
      }  
   update parentAccts.values();
}

when i created Apex class and Triggers along with meta data also creted, why it is created, how it can be usefull ?

Thnaks
Siva
  • May 19, 2014
  • Like
  • 1