• olegforce
  • NEWBIE
  • 70 Points
  • Member since 2008
  • CEO
  • olegforce

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 24
    Replies
HI Users,

I have a trigger code which works as expected, I want to move this code into an apex class and call that in the trigger 
set < id > Checkids = new set < id > ();
        set < id > Uncheckids = new set < id > ();
        if (trigger.isinsert || trigger.isupdate) {
            for (Proposal__Proposal__c p: trigger.new) {
                if (p.Proposal__Primary__c == true && p.Proposal__Approval_Stage__c == 'Accepted') {
                    Checkids.add(p.Proposal__Opportunity__c);
                }
                if (p.Proposal__Primary__c == true && p.Proposal__Approval_Stage__c != 'Accepted') {
                    Uncheckids.add(p.Proposal__Opportunity__c);
                }
                if (p.Proposal__Primary__c == false && p.Proposal__Approval_Stage__c == 'Accepted') {
                    Uncheckids.add(p.Proposal__Opportunity__c);
                }
            }
        }
        list < opportunity > opptoupdate = new list < opportunity > ();
        for (opportunity o: [select id, Has_Primary_Accepted_Quote_Proposal__c from opportunity where id in : Checkids and Has_Primary_Accepted_Quote_Proposal__c = false]) {
            o.Has_Primary_Accepted_Quote_Proposal__c = true;
            opptoupdate.add(o);
        }
        for (opportunity o: [select id, Has_Primary_Accepted_Quote_Proposal__c from opportunity where id in : Uncheckids and Has_Primary_Accepted_Quote_Proposal__c = true]) {
            o.Has_Primary_Accepted_Quote_Proposal__c = false;
            opptoupdate.add(o);
        }
        if (opptoupdate.size() > 0) {
            update opptoupdate;
        }

 

Hi Devs',

 

How can I change the parameters in this line below so that it will run every 15 min. It seems to me that at the minimum we can run the job every 1 hours. Please let me know if I am correct ....

 

System.schedule('Stock Price Update', '0 0 1-23 * * ?', new getStockPrice());

 

Thanks,

 

 

Can someone explain to me why HTML for Lookup from SLDS page is not rendering correctly in Lightnig component? 

https://www.lightningdesignsystem.com/components/lookups/

When I copy and paste the html in the sample (replace svg with lightning:icon) it does not render as shown in the example... All messed up. 

I have a community using the Napili template.  It's a public community with no requirement to login.  I have the "Contact Support & Ask Buttons" component on the page, but we do not want to support Discussions.  I need to either:

A)  modify the component to remove the "Ask A Question" button, or
B) create a custom component with a button that navigates to the Contact Support page.

If I cannot modify the standard component, is there at least a place I can look at the underlying code so I can make my own?

Can someone explain to me why HTML for Lookup from SLDS page is not rendering correctly in Lightnig component? 

https://www.lightningdesignsystem.com/components/lookups/

When I copy and paste the html in the sample (replace svg with lightning:icon) it does not render as shown in the example... All messed up. 
Hi,

I have a custom object called "Project__c" with two fields called "Revenue__c" and "Pipeline__c".
I have a lookup reference/field to the standard Opportunity object.

I used an example code to roll up the amount value of all associated Opportunities, and that works fine. However I would like to split the roll up where all opportunities with status = "Closed Won" is summarized to "Revenue__c" and all opportunities with status = "Open" is summarized to "Pipeline__c". How do I modify the trigger to acheive this?

Trigger:
trigger PipelineRollUp on Opportunity (after delete, after insert, after update, after undelete) {
if(trigger.isInsert || trigger.isUpdate || trigger.isUnDelete){
list<RollUpSummaryUtility.fieldDefinition> fieldDefinitions =
 new list<RollUpSummaryUtility.fieldDefinition> {
 new RollUpSummaryUtility.fieldDefinition('SUM', 'Amount',
 'Pipeline__c')
 };
RollUpSummaryUtility.rollUpTrigger(fieldDefinitions, trigger.new,
 'Opportunity', 'ProjectLookup__c', 'Project__c', '');
}
if(trigger.isDelete){
list<RollUpSummaryUtility.fieldDefinition> fieldDefinitions =
 new list<RollUpSummaryUtility.fieldDefinition> {
 new RollUpSummaryUtility.fieldDefinition('SUM', 'Amount',
 'Pipeline__c')
 };
RollUpSummaryUtility.rollUpTrigger(fieldDefinitions, trigger.old,
 'Opportunity', 'ProjectLookup__c', 'Project__c', '');
}
}

Apex Class:
 
public class RollUpSummaryUtility {
//the following class will be used to house the field names
 //and desired operations
 public class fieldDefinition {
 public String operation {get;set;}
 public String childField {get;set;}
 public String parentField {get;set;}
public fieldDefinition (String o, String c, String p) {
 operation = o;
 childField = c;
 parentField = p;
 }
 }
public static void rollUpTrigger(list<fieldDefinition> fieldDefinitions,
 list<sObject> records, String childObject, String childParentLookupField,
 String parentObject, String queryFilter) {
//Limit the size of list by using Sets which do not contain duplicate
 //elements prevents hitting governor limits
 set<Id> parentIds = new set<Id>();
for(sObject s : records) {
 parentIds.add((Id)s.get(childParentLookupField));
 }
//populate query text strings to be used in child aggregrator and
 //parent value assignment
 String fieldsToAggregate = '';
 String parentFields = '';
for(fieldDefinition d : fieldDefinitions) {
 fieldsToAggregate += d.operation + '(' + d.childField + ') ' +
 ', ';
 parentFields += d.parentField + ', ';
 }
//Using dynamic SOQL with aggergate results to populate parentValueMap
 String aggregateQuery = 'Select ' + fieldsToAggregate +
 childParentLookupField + ' from ' + childObject + ' where ' +
 childParentLookupField + ' IN :parentIds ' + queryFilter + ' ' +
 ' group by ' + childParentLookupField;
//Map will contain one parent record Id per one aggregate object
 map<Id, AggregateResult> parentValueMap =
 new map <Id, AggregateResult>();
for(AggregateResult q : Database.query(aggregateQuery)){
 parentValueMap.put((Id)q.get(childParentLookupField), q);
 }
//list of parent object records to update
 list<sObject> parentsToUpdate = new list<sObject>();
String parentQuery = 'select ' + parentFields + ' Id ' +
 ' from ' + parentObject + ' where Id IN :parentIds';
//for each affected parent object, retrieve aggregate results and
 //for each field definition add aggregate value to parent field
 for(sObject s : Database.query(parentQuery)) {
Integer row = 0; //row counter reset for every parent record
 for(fieldDefinition d : fieldDefinitions) {
 String field = 'expr' + row.format();
 AggregateResult r = parentValueMap.get(s.Id);
 //r will be null if no records exist
 //(e.g. last record deleted)
 if(r != null) {
 Decimal value = ((Decimal)r.get(field) == null ) ? 0 :
 (Decimal)r.get(field);
 s.put(d.parentField, value);
 } else {
 s.put(d.parentField, 0);
 }
 row += 1; //plus 1 for every field definition after first
 }
 parentsToUpdate.add(s);
 }
//if parent records exist, perform update of all parent records
 //with a single DML statement
 if(parentsToUpdate.Size() > 0) {
 update parentsToUpdate;
 }
}
}


As you might have guessed allready, dev. is a new thing for me....
  • December 07, 2016
  • Like
  • 0
HI Users,

I have a trigger code which works as expected, I want to move this code into an apex class and call that in the trigger 
set < id > Checkids = new set < id > ();
        set < id > Uncheckids = new set < id > ();
        if (trigger.isinsert || trigger.isupdate) {
            for (Proposal__Proposal__c p: trigger.new) {
                if (p.Proposal__Primary__c == true && p.Proposal__Approval_Stage__c == 'Accepted') {
                    Checkids.add(p.Proposal__Opportunity__c);
                }
                if (p.Proposal__Primary__c == true && p.Proposal__Approval_Stage__c != 'Accepted') {
                    Uncheckids.add(p.Proposal__Opportunity__c);
                }
                if (p.Proposal__Primary__c == false && p.Proposal__Approval_Stage__c == 'Accepted') {
                    Uncheckids.add(p.Proposal__Opportunity__c);
                }
            }
        }
        list < opportunity > opptoupdate = new list < opportunity > ();
        for (opportunity o: [select id, Has_Primary_Accepted_Quote_Proposal__c from opportunity where id in : Checkids and Has_Primary_Accepted_Quote_Proposal__c = false]) {
            o.Has_Primary_Accepted_Quote_Proposal__c = true;
            opptoupdate.add(o);
        }
        for (opportunity o: [select id, Has_Primary_Accepted_Quote_Proposal__c from opportunity where id in : Uncheckids and Has_Primary_Accepted_Quote_Proposal__c = true]) {
            o.Has_Primary_Accepted_Quote_Proposal__c = false;
            opptoupdate.add(o);
        }
        if (opptoupdate.size() > 0) {
            update opptoupdate;
        }

 
below is the trigger. Bold lines not covered in test class. (code coverage is 77%) 

trigger updateAccOwner on Account (after update) {
    List<Id> ownerChangedAccountlist = new List<Id>();
    Map<Id,Id> accountownerMap = new Map<Id,Id>();
    List<custObj1__c> lstCust1 =  new List<custObj1__c>();
    List<custObj2__c> lstCust2 = new List<custObj2__c>();
  
    for(Account acc:Trigger.new)
    {
       if(acc.ownerId!=Trigger.oldmap.get(acc.Id).ownerid)
       {          
          ownerChangedAccountlist.add(acc.Id);
          accountownerMap.put(acc.Id,acc.ownerId);
       } 
    }
   list<custObj1__c> custList = [select id,ownerid,Account__c  from custObj1__c where Account__c in:ownerChangedAccountlist];
  for(custObj1__c acct:custList)
   {        
      acct.ownerid = accountownerMap.get(acct.Account__c);
      lstCust1.add(acct); 

   }    
     update lstCust1;   
           List<custObj2__c> accList = [select id,ownerid,Account__c from custObj2__c where Account__c in:ownerChangedAccountlist];
              for(custObj2__c acc : accList)
            {
               acc.OwnerId = accountownerMap.get(acc.Account__c);
               lstCust2.add(acc);

              }
        update lstCust2;
           }


Test class :

     Static testmethod void testupdateAccOwner()
     {   
                       
         Account a = new Account();
        a.Name = 'Test Account';             
        insert a;                
           
       custObj1__c acct = new custObj1__c(Account_Plan_Name__c = 'Test Account Plan'); 
        acct.Account__c = a.Id; 
        acct.OwnerId = a.OwnerId;
        insert acct; 
         
        custObj2__c acc = new custObj2__c();
        acc.Account_acc_Name__c = 'Test account acc';
        acc.custObj1__c = acct.Id;            
        acc.Account__c = a.Id;      
        insert acc;
        
        a.OwnerId = [select id from user limit 1].id;
        update a;
        
        Test.startTest();
            
            acct.OwnerId = a.OwnerId;
             update acct;
            acc.ownerId = acct.OwnerId;
            update acc;
         
        Test.stopTest();  
     }
 

When sending email message using the sendEmailMessage() method, I am getting the INVALID_OPERATION error Reason is: 'Parent Case required'.

Is it possible to send EmailMessages with empty (or not set) Parent Case field?

Thanks

Is there any way that I can access Java or .Net code from a static resource?
  • April 18, 2016
  • Like
  • 0
For some reason, when I go to the developer console in my sandbox, I don't see the new classes I created listed in the Overall Code Coverage section on the bottom right. Do I need to refresh anything in the sandbox?

User-added image
  • April 18, 2016
  • Like
  • 0
Hi everyone !
I'm looking for some good design practice for the below scenario.
I've an object which has lot of fields and a record is being created/updated in one of the class (say mainClass). Query in the mainClass is going to exceed
20000 characters which is the max limit of SOQL query. We're going to add few more fields in the near future and definetely the query size exceeds the
max limit. I can create a query2 for the same object, but the issue is to leverage the doSOmething() in the Helper class, which has lot of business logic in it.
How can I leverage my doSomething() method in this situation.

Any pointers on this is much appreciated.

public class mainClass {

    public void sampleMethod1(){
      Object1 query1 = [SELECT field1__c,field2__c,field3__c,field4__c,......
                      .......
                      .......
                      FROM Object1 LIMIT1]; // This query is GOING TO exceed 20,000 characters which is the max limit for a SOQL query in Salesforce  

       query1.field1__c='test1';
       query1.field2__c='test2';
       Helper hlp = new Helper();
       hlp.doSometing(query1);
       update obj1;
      
    }
}


public class Helper{

    Object1 o1;
    public Helper(){
       o1 = new Object1();
    }
    
   public void doSomething(Object1 obj1){   
       o1=obj1;
       o1.field3__c = 'test3';
       o1.field4__c='test4';
       o1.field5__c='test5';
       .
       .
       .
       .
       .//lot of business logic exist here to map the Object1 fields
       .    
       .
       .       
   }
}

 
Hey everybody.

Ive created a 3 dimension integer array, it's go like this:
List<List<List<integer>>> ArrayList = new  List<List<List<integer>>>();

the thing is that i'm trying to approach cell directly, like that:
ArrayList[2][3][4] = 7;

and im getting:
FATAL_ERROR|System.ListException: List index out of bounds: 2

which i was guessing is because i havnt initialized the cell and tried to approach it directly.

ive run a 3 nested for loops in order to initialize the array using:
ArrayList.add(0);
but i kept getting the same message (this time: List index out of bounds: 0, of course)

so im a bit stuck and dont know how to deal with this array but im surely have to use it

suggestions will be welcomed!

Thanks in advanced,
Noam
I have a before insert, before update trigger on the contact that is causing issues when a lead is converted.  I don't need the triggers to run on lead conversion though so how can I write this into my trigger or class?
I'm getting the error "Invalid type: CloneClassAttendance" in test code bolded below.
We're supposed to go live tomorrow morning and I'm stuck... don't mean to sound too desperate... but I am :(
Thanks, Michele

Here's the test code:
@isTest
private class CloneClassAttendanceTest {
//CloneClassAttendance myTest = new CloneClassAttendance();
//Public CloneClassAttendance(){}
// above line gives error  Invalid constructor name:
    static testMethod void myUnitTest() {   
        // Add test contact
        Contact c = new Contact(LastName='Test');
        insert c;
        // Add test campaign
        Campaign cp = new Campaign(Name='TestCampaign');
        insert cp;
        // Add campaign member status
        CampaignMemberStatus cms = new CampaignMemberStatus( CampaignId = cp.Id, Label = 'Attended', SortOrder = 3);
        insert cms;
        // Add campaign member
        CampaignMember cm = new CampaignMember( CampaignId = cp.Id, Status = 'Attended', ContactId = c.Id);
        insert cm;
     
         //Page reference change VF_PageName with the name of your visualforce page
         PageReference cloneAttendance = Page.CloneClassAttendance;
         //Set the current page
        Test.setCurrentPage(cloneAttendance);
         //Set the id param on the page to the campaign id
         ApexPages.currentPage().getParameters().put('id', cp.Id);
         //Instantiate standard controller with the campaign record
         ApexPages.StandardController s = new ApexPages.StandardController(cp);
         //Instantiate extension class passing the standard controller
         //Line below gives error: Invalid type: CloneClassAttendance       
         CloneClassAttendance cca = new CloneClassAttendance(s);

         //Call your extensions methods here...
         cca.InsertRecord();
    }
}

Here's the Apex code I'm trying to test:
public class CloneClassAttendance
{
    private final Campaign theCampaign;

    public CloneClassAttendance( ApexPages.StandardController stdController )
    {
        theCampaign = (Campaign)stdController.getRecord();
    }

    //  returns the day-of-week for the given date in 2001 - 2099
    //  this works because 2001 started on a Monday
    //  0 = Sunday, ... 6 = Saturday
    private static Integer dayOfWeek( Date theDate )
    {
        Integer theYear = theDate.year() - 2001;
        return Math.mod( theYear + theYear/4 + theDate.dayOfYear(), 7 );
    }

    public void insertRecord()
    {
        Map<Date,Campaign> map_newCampaigns = new Map<Date,Campaign>();

        Date newDate = theCampaign.CloneStart__c;
        while ( newDate <= theCampaign.CloneEnd__c )
        {
            map_newCampaigns.put
            (   newDate,
                new Campaign
                (   Type                = 'Class Attendance',
                    IsActive            = true,
                    StartDate           = newDate,
                    EndDate             = newDate,
                    ParentId            = theCampaign.Id,
                    Name                = theCampaign.Name + '-' + newDate.format(),
                    Description         = theCampaign.Description,
                    Teacher__c          = theCampaign.Teacher__c,
                    Day_of_Week__c      = theCampaign.Day_of_Week__c,
                    Hours_Per_Class__c  = theCampaign.Hours_Per_Class__c,
                    Location__c         = theCampaign.Location__c,
                    Start_Time__c       = theCampaign.Start_Time__c,
                    End_Time__c         = theCampaign.End_Time__c,
                    Waitlist__c         = theCampaign.Waitlist__c,
                    Max_Capacity__c     = theCampaign.Max_Capacity__c,
                    Status              = 'Completed'
                )
            );
            newDate = newDate.addDays( 7 );
        }
        insert map_newCampaigns.values();

        List<CampaignMemberStatus>  list_newCampaignMemberStatus    = new List<CampaignMemberStatus>();
        List<CampaignMember>        list_newCampaignMembers         = new List<CampaignMember>();

        newDate = theCampaign.CloneStart__c;  
        while ( newDate <= theCampaign.CloneEnd__c )
        {
            Campaign newCampaign = map_newCampaigns.get( newDate );

            for ( CampaignMemberStatus status :
                [   SELECT  Id, HasResponded, IsDefault, Label, SortOrder
                    FROM    CampaignMemberStatus
                    WHERE   (   CampaignId = :theCampaign.Id
                            AND IsDeleted = false
                            )
                ]
                )
            {

                list_newCampaignMemberStatus.add
                (   new CampaignMemberStatus
                    (   CampaignId      = newCampaign.Id,
                        HasResponded    = status.HasResponded,
                        IsDefault       = status.IsDefault,
                        Label           = status.Label,
// the following line is a workaround due to the fact that when the campaign is cloned it automatically
// add CampaignMemberStatus of Sent and Received with sortorder 1 and 2. This was creating a duplicate bug.
                        SortOrder       = status.SortOrder +2
                    )
                );
System.debug( 'CampaignMemberStatus: CampaignId= ' + newCampaign.Id +' Label = ' + status.Label + ', SortOrder = ' + status.SortOrder );
            }

            for ( CampaignMember member :
                [   SELECT  Id, ContactId, Status
                    FROM    CampaignMember
                    WHERE   CampaignId = :theCampaign.Id
                ]
                )
            {
                list_newCampaignMembers.add
                (   new CampaignMember
                    (   CampaignId      = newCampaign.Id,
                        ContactId       = member.ContactId,
                        Status          = member.Status
                    )
                );
            }

            newDate = newDate.addDays( 7 );
        }

        insert list_newCampaignMemberStatus;
        insert list_newCampaignMembers;
    }
}

Here's the Visual Force page:
<apex:page standardController="Campaign" extensions="CloneClassAttendance" action="{!insertRecord}">
  <h1>Cloning Attendance</h1>
  <p> Class name is {! campaign.name} </p>
  <p> Class id is:   {! campaign.id} </p>
  <p> Class start date is:   {! campaign.startdate} </p>
  <p> Class end date is:   {! campaign.enddate} </p>
  <p> Next week is: {! campaign.startdate+7} </p>
  <p> Class Status is {! campaign.status} </p>
  <p> Class teacher is {! campaign.teacher__c} </p>
  <p> Class DOW is {! campaign.Day_of_Week__c} </p>
  <p> Class Hours_Per_Class__c is {! campaign.Hours_Per_Class__c} </p>
  <p> Class Location is {! campaign.Location__c} </p>
  <p> Class Start time is {! campaign.Start_Time__c} </p>
  <p> Class End time is {! campaign.End_Time__c} </p>
  <p> Class Description is {! campaign.Description} </p>
  <p> Class Waitlist is {! campaign.Waitlist__c} </p>
  <p> Class Max_Capacity is {! campaign.Max_Capacity__c} </p>
  <p> Clone start date is:   {! campaign.clonestart__c} </p>
  <p> Class end date is:   {! campaign.cloneend__c} </p>
</apex:page>
I am having issue referencing a simple stylesheet in my visualforce page.

I created a CSS with simple code:
.center{
     width:976px;
  margin-left: auto;
  margin-right: auto;
  background-color: red;
}

then i uploaded this in my static resource and now im trying to refrence this particular CSS in my div tag but it is not working.

here is what i have in my VF page:

<apex:page showHeader="false" sidebar="false" >
 
  <apex:stylesheet value="{!$Resource.center}"/>
 
 
  <apex:form >
      <div class="center" >
          CENTER THIS
          {!$Resource.center}
      </div>
  </apex:form>
</apex:page>

I am not sure what else to do. I can hard code the CSS in the VF Page but I have  a lot of div tags with different CSS. Can anyone help me on this?
I have a custom object that has a field that is a lookup to a User. When I put that on a VF page, I get a picklist for the UserRole (Public, Partner User) and the lookup for the name. I'd like to force it to always be for the User and not the partner user. I've tried various things that have no effect. Here's the page:

<apex:page Controller="testController" sidebar="false">
<apex:form >
            <apex:inputField value="{!userName.User__c}" />
</apex:form>
</apex:page>

And the controller:
 
public class testController {

    public test__c userName{get;set;
    public testController() {
        userName=new test__c();
    }
}

If anyone knows how to limit this so onlty the User role is searched and the Role picklist is not displayed, I'd appreciate it.

Thanks, Dave