• Veenesh Vikram
  • SMARTIE
  • 913 Points
  • Member since 2015
  • Senior Salesforce Developer


  • Chatter
    Feed
  • 25
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 1
    Questions
  • 138
    Replies
Hi,

We have written Apex class which updates the event record when custom VF refresh button is clicked but the record is not updated immediately. When we have to refresh the browser with the record id, updated data shown is.

public void Test()
   {    
       Event E = [SELECT Id, TOA_Appointment_ID__c,TOA_Appointment_Status__c FROM EVENT WHERE Id = '00Uj000000AMapq'] ;
       List<String> returnvalue = new List<String>();
       toaGetApptUpdates TU = new toaGetApptUpdates ();  // call class
       returnvalue = TU.GetAptInfo(E.TOA_Appointment_ID__c);  // invoke the class method

       String vStat = returnvalue.get(0);  // Store the response values
       String vTrvlTime = returnvalue.get(1);
       String vResId = returnvalue.get(2);
       String vResName = returnvalue.get(3);
      
           E.TOA_Appointment_Status__c = vStat;   // assign the response values
           E.TOA_Traveling_Time__c = vTrvlTime;
           
           E.TOA_Resource_Name__c = vResName;
           
          
            update E;  // update the event record.
          }

VF page for event detail record :

<apex:page tabStyle="Appointment__tab" standardController="Event" extensions="cController"  sidebar="true" >
<script  type="text/javascript">
    function Testmy()
    {
        alert("Hello");
        callt();
    
    }
    </script>

    <apex:form >
     <apex:actionFunction name="callt" action="{!Test}"  />

    <style type="text/css">
         h { font-weight: bold; position: relative; left:8px; font-size:11px }
         
         p { font-weight: bold; position: relative; left:36px; bottom:10px; font-size:13px }
         
        .pbHeader
        {
          font-size:10px  ;
        }
        
        .  ext-webkit ext-chrome
        {
            background:#ececec;
        }
        
         h3
         {
             color: #222;
          }
       
    } 
    </style>
   
    <img id="theImage" src="/resource/home28" style="position:relative; top:10px; width:26px; "></img>
    <h>Appointment</h>
    <p>{!event.Subject}</p>
     <apex:pageBlock title="Appointment Detail" >
     <apex:pageBlockButtons location="top">
            <apex:commandButton value="Edit" action="{!edit}" style="font-size:11px"/>
            <apex:commandButton value="Delete" action="{!delete}" style="font-size:11px"/>
            <apex:commandButton value="Refresh"   onclick="Testmy()" style="font-size:11px" reRender="pgsec" />
    </apex:pageBlockButtons>
        
        <apex:pageBlockSection title="Calendar Details" columns="2" id="pgsec">
           <apex:pageBlockSectionItem >
                Assigned To
                 <apex:outputLink value="{!URLFOR($Action.User.View,Event.Owner)}}">
                     <apex:outputfield value="{!event.Owner.Name}" />
                </apex:outputLink>
            </apex:pageBlockSectionItem>
            
            <apex:pageBlockSectionItem >
                Related To
                <apex:outputlink onclick="window.location='/{!event.What}';"  value="#">{!event.What.Name}</apex:outputlink>
            </apex:pageBlockSectionItem>
           <apex:outputText value="{!event.Subject}"></apex:outputText>
            
            <apex:pageBlockSectionItem >
                Name
                 <apex:outputLink onclick="window.location='/{!event.Who}';" rendered="{!NOT(ISNULL(event.Who))}" value="#">{!event.Who.Name}</apex:outputLink>
            </apex:pageBlockSectionItem>
            <apex:outputText label="Start" value="{0,date,MM/dd/yy hh:mm a}"> <apex:param value="{!event.StartDateTime}" /></apex:outputText>
            <apex:outputText value="{!event.TOA_Work_Type__c}"></apex:outputText>
            <apex:outputText value="{0,date,MM/dd/yy hh:mm a}" label="End"> <apex:param value="{!event.EndDateTime}" /></apex:outputText>
             <apex:outputText value="{!event.TOA_Time_Slot__c}"></apex:outputText>
           <apex:outputText id="TOAID" value="{!event.TOA_Appointment_ID__c}" ></apex:outputText>
           <apex:outputText value="{!event.TOA_Resource_Name__c}"></apex:outputText>
           <apex:outputText value="{!event.TOA_Appointment_Status__c}"></apex:outputText>
           <apex:outputText value="{!event.TOA_Traveling_Time__c}"></apex:outputText>
           
            
         </apex:pageBlockSection>
         
        <apex:pageBlockSection title="Appointments">
         
         <iframe src=".../VikTableEffects?id={!event.Id}" style="width: 786px; height: 200px; border:0px"/>
        
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>


Thanks,
Pallavi
  • August 07, 2016
  • Like
  • 0

Is there an easy way of making Buttons visible to certain users/profiles? 

I have had a look but can't see an obvious way of doing this

Thanks in Advance,
Kim

Hello All,

I'm new to salesforce and wondering how to update a field value in a related list if there more than one record in that list and you want to update only a specific record.

For example: In the below image, I would like to update the Payment received field with a value.
How would you update only one of the payment fields if there are more than one null value in the Payment received?

Would this have to be done with an trigger?

User-added image

Any help or suggestions would be apprieciated.

King regards,
Vinh
Hi all,
I need help in trigger, There are two objects Intake_details and claim. The issue is,some claim records are being created that do not have a corresponding Intake Detail record
A claim record should only be created if its name(claim number) field matches the Intake_details name field. 

Please suggest me how to do this.
Hi Guys, 

I have a Page layout where child related lists exists, I would like to overide one of the child related list with a Visualforce page. I have created the visualforce page but how can I override the standard related lists with the custom visualforce page?

Thanks, 
Prasanna
 
Hello,
User-added image
I'm looking for a apex trigger or workflow that will update a checkbox, if certain condition are met. In my example (screenshot) if High Cedit Sub is greater than two. I want the two subjects with the minimum score and high credit to be checked. Or if that can't work the two subjects with the minimum score to add 20 on them. You are help will very must appreciated, Many Thanks 
I don't have any developer or coding knowledge. I try to learn as I go, but for the past two days, I have not figured out how to resolve my issue. I hope that the forum will help guide me in the right direction so that I can move forward.

What I've done is created a trigger to assign leads to a particular zipcode based off this suggestion (https://developer.salesforce.com/forums/?id=906F0000000Af9nIAC). It litterally is the same trigger. All I did was substitute the database and sales field name with my custom object fields. It worked great in the sandbox production. So I created two more triggers for the Account and Contact records. Both of those worked as well.

The issue I'm running into now is deployment into production. Validation failed. My org has 0% coverage. I've read as much documentation and examples as I could, and tested what I could understand. Nothing is making much sense at this point.

Appreciate it.
Hi everyone,

I can't pass this challenge and.

Look this picture
User-added image
Hi,
i need to get the data from the selected picklist..

the picklist is to have 5 records, if i selected 1 record from the piclist in the visual force page the cases object data is to mbe shown which is assigned to that contact.

can anyone help me with the code?
public class s1{
public List<Student_Particluars__c> std = [select Name,Amount_Paid__c,DOB__c,Email__c from Student_Particluars__c];
public List<Student_Particluars__c> getpro(){
return std;
}
}
..........................................-------------------------------------------------............................................................

<apex:page controller="s1">
<apex:form>
 <apex:pageBlock>
 <apex:pageBlockTable value="{!pro}" var="p">
 <apex:column value="{!p.Name}"/>
 <apex:column value="{!p. Amount_Paid__c}"/>
 <apex:column value="{!p.DOB__c}"/>
 <apex:column value="{!p.Email__c }"/>
   </apex:pageBlockTable>
   </apex:pageBlock>
</apex:form> 
</apex:page>


 

I want to create a related list to drop onto a page, based on an indirect relationship.

Example: I have an object subscription and a second object subscriptiondetail, which has a lookup (not a master/detail) to subscription.  The subscriptiondetail also contains a lookup to the standard SF object Product.  I want to define a related list and put it on the product page, containing subscriptions that have subscriptiondetail records that relate to the product.  I don't want a related list of subscriptiondetails, the related list will need to contain fields from the subscription object, so it needs to be a related list of subscriptions, but the actual relationship is a level lower in subscriptiondetail.

Is this possible by creating a controller or class for just the related list, rather than replacing the entire parent page with a custom version?

Do standard fields have 15 digit reference id's? I want to reference the Case "account name" field in a URL button but the field address is 

https://cs45.salesforce.com/_ui/common/config/field/StandardFieldAttributes/d?id=Account&type=Case&retURL=%2Fp%2Fsetup%2Flayout%2FLayoutFieldList%3Ftype%3DCase%26retURL%3D%252Fui%252Fsetup%252FSetup%253Fsetupid%253DCase%26setupid%3DCaseFields&setupid=CaseFields

Thanks!
I have a question about what causes referencing a formula field inside a formula to add so many characters to the compiled character count.

I have a formula(text) field (call it Formula__c) that is just
TEXT(Parent__r.Picklist_Field__c)

When I reference this in a new formula field
IF(Formula__c == "Text Value", TRUE_STUFF, FALSE_STUFF)
It seems to add around 250 more characters to the compiled character count than if I were to just do
IF(ISPICKVAL(Parent__r.Picklist_Field__c, "Text Value"), TRUE_STUFF, FALSE_STUFF)
Where do all of the extra characters come from?
 
I have embeded custom vf page into one of the object lay out. Let's say I am trying to perform Edit action, Then edit page is being open as sub page with in the actual page. Instead, How can we open that page as a new page(Unlike subpage with in the actual page).

Thanks In Advance.
Hello,

I want to implement the fucntionality of attaching document to a email.
As of now i am able to send email.

like below 
      Messaging.reserveSingleEmailCapacity(2);
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {'test@google.com'};
            String[] ccAddresses = new String[] {'test@google.com'};
                mail.setToAddresses(toAddresses);
        mail.setCcAddresses(ccAddresses);
        mail.setReplyTo('test@google.com');
        mail.setSenderDisplayName('Support Team');
        mail.setSubject('test Subject');
        mail.setBccSender(false);
        mail.setUseSignature(false);
        mail.setHtmlBody('<html><body><p>Hello Text</p></body></html>');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
I want to improve it to let user choose file in "Computer" or "Salesforce document", attach the file and send it with email.

Thank you for sugetions !
 
  • May 31, 2016
  • Like
  • 0
Hi,

  We have created new custom object called SPR__c which is related to opportunity in SPR we have created a button which will call the below class from visual force page.  below is the class

Class
public class  check_spr_coterm
{
 
 Integer Olicheck;
 Integer Athcheck;
 String PageID; 
 String P_SPR_Approver_Director;
 String P_SPR_Approver_RVP;
 String P_SPR_Approver_GVP;
 String P_SPR_Approver_EVP;  
 
 public check_spr_coterm()
 {
   SPR__c SP;
   //OpportunityLineItem OLI;
    
   SP = [select id,Opportunity__c from SPR__c 
          where Id = : ApexPages.currentPage().getParameters().get('id') limit 1];
   
   PageID = ApexPages.currentPage().getParameters().get('id');
   
  List<SPR__c> SPRO = new List<SPR__c>();

   SPRO = [select id,SPR_Approver_Director__c,SPR_Approver_RVP__c,SPR_Approver_GVP__c,SPR_Approver_EVP__c from SPR__c 
           where 
           id = :ApexPages.currentPage().getParameters().get('id') and
           ( SPR_Approver_Director__c = null or SPR_Approver_RVP__c = null or 
             SPR_Approver_GVP__c = null or SPR_Approver_EVP__c = null ) limit 1 ];
             
      if(!SPRO.isEmpty()) // check if list is not empty
        {       
       P_SPR_Approver_Director = SPRO[0].SPR_Approver_Director__c;
       P_SPR_Approver_RVP = SPRO[0].SPR_Approver_RVP__c;  
       P_SPR_Approver_GVP = SPRO[0].SPR_Approver_GVP__c;
       P_SPR_Approver_EVP = SPRO[0].SPR_Approver_EVP__c;
        }
      else
      {
        P_SPR_Approver_Director = 's';
        P_SPR_Approver_RVP =  's';  
        P_SPR_Approver_GVP =  's';
        P_SPR_Approver_EVP =  's';
       }     
     
   List<AggregateResult> OLI = [select count(id) olicnt from OpportunityLineItem 
                                where opportunityid = :SP.Opportunity__c and name like '%COTERM%' ];
    
   List<AggregateResult>  ATH = [select count(id) athcnt from  Attachment 
                                 where parentid = :ApexPages.currentPage().getParameters().get('id')];  
 
   Olicheck = (Integer)OLI[0].get('olicnt');
   Athcheck = (Integer)ATH[0].get('athcnt');  
     
 }
 public void pageAction(){
 
     if ( P_SPR_Approver_Director == NULL || P_SPR_Approver_RVP == NULL || P_SPR_Approver_GVP == NULL || P_SPR_Approver_EVP == NULL  )
     {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info,'Your SPR approvers have not been set up, please contact the SFDC Administrator @ SFDC@fortinet.com'));  
     }
 
     else if( Olicheck > 0 && Athcheck ==0) // COTERM product exist and attached is missing this will fire
     {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info,'An RTS Quote is required for the COTERM product.Please attach quote(s) and then resubmit your SPR for approval'));     
     }
     
     else if ( P_SPR_Approver_Director <> NULL && P_SPR_Approver_RVP <> NULL && P_SPR_Approver_GVP <> NULL && P_SPR_Approver_EVP <> NULL  )
     {
       Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
       req.setObjectId(PageID);
       Approval.ProcessResult result = Approval.process(req);
       ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info,'Sucessfully submitted for approval'));
       redirectpage();
      }
     
 }
 
 
 public PageReference redirectpage()
 {
   PageReference pageRef = new PageReference('/' + PageID);
   pageRef.setRedirect(true);
   return pageRef;
 }
 
 
}

Visual force Page.
<apex:page controller="check_spr_coterm" action="{!pageAction}">
<apex:pageMessages />
<apex:form >
        <apex:commandButton value="Ok" action="{!redirectpage}" oncomplete="abc();"/>
    </apex:form>
<script>
function abc() {
    window.location = 'https://www.google.com';
}
</script>
</apex:page>

<!--
<apex:page controller="check_spr_coterm">
<script>
window.alert('{!$CurrentPage.Parameters.Id}');
window.parent.opener.location.reload(true);
window.parent.close();
</script>
</apex:page>
-->

Wrote below Test Class which is still showing 0% code coverage Please suggest me how to add code coverage test class for above class 
@isTest(seealldata=true)
public class  test_check_spr_coterm
{
   static testMethod void test_check_spr_coterm(){
   
  Account Act = new Account( Name = 'Test Sudhir Ac',Website='www.sudhir.com',Industry='Legal',BillingStreet='894', BillingCity='sunnyvalley', BillingState='CA', 
                             BillingPostalCode='997',BillingCountry='USA');  

  insert Act; 
   
  Opportunity Opp = new Opportunity(Name = 'Test Class Sudhir',AccountId=Act.id,Closedate=system.today(),StageName='Omit from Forecast',Deal_Type__c='Refresh' );  

  insert Opp;  
   
   
   SPR__c SPR = new  SPR__c(Opportunity__c=opp.id,Partner_Account__c='0018000000pwEyq',Distributor__c='a0N8000000Aiif0',Reason_Needed__c='Budget Constraints',
                            SPR_Approver_Director__c = null,SPR_Approver_RVP__c=null,
                            SPR_Approver_GVP__c=null,SPR_Approver_EVP__c=null  ); 
   
   insert SPR;
     
   //String SPR1 = SPR[0].id;
  
  
 // if([select count() from ProcessInstance where targetobjectid=:SPR1.id] < 1)
     //   {       
            Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
            req.setComments('Approve.');
            req.setNextApproverIds(new Id[] {UserInfo.getUserId()});
            req.setObjectId(SPR.Id);

            //Submit the approval request
            Approval.ProcessResult result = Approval.process(req);

     //   } 
        
   }     

}


Please suggest me how to modify the test class to get code coverage.

Thanks
Sudhir
I am trying to create a validation rule for closing ticket.
The Closure Category (Picklist) and Incident Resolution field must be completed before a ticket can be closed.
I am currently using this formula but its not working for me.
AND(ISPICKVAL(BMCServiceDesk__ClosureCategory__c, ''), $User.BMCServiceDesk__IsStaffUser__c=TRUE && BMCServiceDesk__Status_ID__c ="Resolved" && (ISBLANK(BMCServiceDesk__incidentResolution__c)))
 
Here two objects are used.Account and Schedule__c.
The main block's code is called by before trigger on account.
Trigger is on Account object.
It is not allowing me to update the Schedule__c object .

Please let me know why this error is encountered.


Error : 
Error:Apex trigger Account caused an unexpected exception, contact your administrator: Account: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0JM0000007bp55MAA; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Schedule: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a05M000000ACmimIAD; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 001M000000uSEuz) is currently in trigger Account, therefore it cannot recursively update itself: [] Class.ScheduleTrigger.updateCallsForSchedule: line 63, column 1 Trigger.Schedule: line 11, column 1: []: Class.AccountTrigger.NextCallCycleCheck: line 248, column 1

Main Block :
system.debug('Inside 6week block ');
                 a.REX_Call__c=false;
                 boolean acctNextCycle = a.Next_Cycle_Call__c;
                 List<Schedule__c> wk6Schedules = new list<Schedule__c>();

                 if(a.Priority_Cycle_Frequency__c == 'K: 6 Week Cycles: Weeks 1-2' || a.Priority_Cycle_Frequency__c == 'L: 6 Week Cycles: Weeks 3-4' || a.Priority_Cycle_Frequency__c == 'M: 6 Week Cycles: Weeks 5-6'){
                        system.debug('Inside 6week if block ');
                     for(Schedule__c schedule : [SELECT Id,Store__c,Week__c FROM Schedule__c WHERE Active__c = 'Y' AND Status__c = 'Active' AND Route__r.Status__c = 'Active' AND Store__r.Active__c = 'Y'  AND Store__c =: a.Id]){
                           system.debug('Inside schedule for loop ');
                        if (schedule.Week__c == 1 || schedule.Week__c == 2){
                               system.debug('Inside if block of week 1 and 2 ');
                            if (!acctNextCycle){
                                   system.debug('Inside nextcall true ');
                                reverseAcctNextCycleCall(a);
                            }else{
                                system.debug('Inside nextcall false ');
                                wk6Schedules.add(update6wkSchedule(schedule));
                            }
                        }else if (schedule.Week__c == 3 || schedule.Week__c == 4){
                            system.debug('Inside if block of week 3 and 4 ');
                            reverseAcctNextCycleCall(a);
                            wk6Schedules.add(update6wkSchedule(schedule));
                        }    
                     }
                     System.debug('all schedules to update are ...'+ wk6schedules);   
                     if (wk6Schedules.size() > 0) {
                         database.update(wk6Schedules);
                     }

Functions used in main block :
public static Account reverseAcctNextCycleCall(Account account){
         system.debug('Inside reverseAcctNextCycleCall ');
      Account schedAcct = new Account();
      schedAcct = account;
      if (schedAcct.Next_Cycle_Call__c){
        schedAcct.Next_Cycle_Call__c = false;
      }else{
        schedAcct.Next_Cycle_Call__c = true;
      }
        system.debug('New next cycle call :'+schedAcct.Next_Cycle_Call__c);
        system.debug('Exiting reverseAcctNextCycleCall');
      
      return schedAcct;
    }
    
    public static Schedule__c update6wkSchedule(Schedule__c sched){
    // if wk=1or2, +2 , if wk=3or4, -2
    system.debug('inside update6wkSchedule');
    Schedule__c schedule = sched;
    Decimal existingWk = schedule.Week__c;
    system.debug('Existing week : '+existingWk);
    Decimal newWk = 0;
    if (existingWk == 1 || existingWk == 2){
         newWk = existingWk + 2;
    }else if (existingWk == 3 || existingWk == 4){
         newWk = existingWk - 2;
    }else{
         return schedule;
    }
    schedule.Week__c = newWk;
        system.debug('New week : '+newWk+'schedule.Week__c : '+schedule.Week__c);
    return schedule;
  }


 
When a certain costum object is created and saved I would like a popup message to show only if certain critiria are relevant. 
please advice me how to do this
I am trying to call one rest API using Httprequest (from salesforce using Apex code), but not able to figure how I can pass the body.  I would appreciate if anyone share the way to pass the below mentioned body in the HttpRequest.

here are the details:
End-point URL : https://api.boomi.com/api/rest/v1/AccountID/EnvironmentExtensions/XXXXXXXXXX

Body:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<bns:EnvironmentExtensions xmlns:bns="http://api.platform.boomi.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="XXXXXXXXXXXXXXXX" extensionGroupId="" environmentId="XXXXXXXXXXXXXXX">
    <bns:connections>
        <bns:connection name="SFDC connection" id="XXXX">
            <bns:field componentOverride="false" usesEncryption="false" encryptedValueSet="false" value="email@gmail.com" id="user"/>
            <bns:field componentOverride="false" usesEncryption="true" encryptedValueSet="true" id="password" value="password"/>
        </bns:connection>
    </bns:connections>
</bns:EnvironmentExtensions>


Apex code to call Rest API:


      String endPointURL = 'https://api.boomi.com/api/rest/v1/AccountID/EnvironmentExtensions/XXXXXXXXXX';
      
      String userName = 'XXXXXX';
      String password = 'XXXXXXX';

      String body= '';
      String query;
      query = '';
      Blob headerValue = Blob.valueOf(userName + ':' + password);
      String authorizationHeader = 'BASIC ' +
      EncodingUtil.base64Encode(headerValue);
      accs1 = new List<cAccount>();
      Httprequest request = new HttpRequest();
      Http http = new Http();
      request.setMethod('POST');
      request.setEndpoint(endPointURL);
      request.setHeader('Content-Type', 'application/json');
      // Header info with remote server user name and password
      request.setHeader('Authorization', authorizationHeader);
      request.setBody(query); 
            
      request.setTimeout(120000); 
      request.setBody(query);          
      //Making call to external REST API
      HttpResponse response = http.send(request);  
      System.debug('responseBody: '+response.getBody());
How can we "Force Download" a static PDF File stored as a Static Resource/Document in a VF Page? By Force Download, I mean that the File shoulld be downloaded straight away to the user's local machine and not open in a new Tab as a PDF. 
Please help me why its giving my test class is giving me 0% coverage.

Here is my Trigger Code.
 
trigger DirectOpp on Direct_Opportunities__c (before insert) {
   
    Set<Id> contactId = new Set<Id>();
	id accountId;
    date myDate = date.valueOf(system.today());
    
    for (Direct_Opportunities__c d : Trigger.new){
        
	      System.debug(d.Contact__c);
          contactId.add(d.Contact__c);
      
       // Getting the Account Id from Direct Opportunity Contact__c
       // and assigned it to variable aId
       
        accountId = [select AccountId from Contact where id in :contactId].get(0).accountId;
		
        
	// Inserting of New Opportunity
        Opportunity o = new Opportunity();
        o.Name =  ' Direct Opportunity ' + d.Type__c;
        o.CloseDate = myDate + 7;
        o.StageName = 'New';
        o.OwnerId = d.Assigned_BC__c;
        o.AccountId = accountId;
        o.Contact__c = d.Contact__c;
        o.CampaignId = d.Campaign__c;

        insert o;
        
        // Inserting of Tasks
        
        Task t = new Task();
        
        t.Subject = d.Type__c;
        t.ActivityDate = myDate + 1;
	    t.Status = 'Not Started';
        t.Priority = 'High';
        t.OwnerId = d.Assigned_BC__c;
        t.WhatId = o.Id;
        t.WhoId = o.Contact__c;
        
        insert t;
        
        
    }
}

And here is my Test Class.
 
@istest

public class Unit_Test_DirectOpp {

    static testMethod void TestonDirectOpp() {
   		
     test.startTest();

        Account acct = new Account(Name = 'Test Account ');

        insert acct;
     
        Contact cont = new Contact(LastName = 'Last', AccountId = acct.Id );

        insert cont;
    
    	Direct_Opportunities__c d = new Direct_Opportunities__c(Assigned_BC__c = cont.OwnerId, Contact__c = cont.Id, Type__c = 'Type', Campaign__c = 'MyCampaign');


        Opportunity Opp = new Opportunity(AccountId = acct.Id,  Contact__c = cont.Id, Name = 'Test Opportunity', StageName ='New' , CloseDate = date.today());

        insert Opp;

      
        Task t = new Task(Subject='Subject', ActivityDate = date.today(), Status = 'Not Started', Priority = 'High', OwnerId = Opp.OwnerId, WhatId = Opp.Id, WhoId = cont.id);
        insert t;

    
        
        test.stopTest();
       
 }
}

 
  • September 01, 2016
  • Like
  • 0
How can we "Force Download" a static PDF File stored as a Static Resource/Document in a VF Page? By Force Download, I mean that the File shoulld be downloaded straight away to the user's local machine and not open in a new Tab as a PDF. 
I would like to be able to send an email notification to a management if a task is overdue. How can I do this?
  • August 07, 2016
  • Like
  • 0
Hi,

We have written Apex class which updates the event record when custom VF refresh button is clicked but the record is not updated immediately. When we have to refresh the browser with the record id, updated data shown is.

public void Test()
   {    
       Event E = [SELECT Id, TOA_Appointment_ID__c,TOA_Appointment_Status__c FROM EVENT WHERE Id = '00Uj000000AMapq'] ;
       List<String> returnvalue = new List<String>();
       toaGetApptUpdates TU = new toaGetApptUpdates ();  // call class
       returnvalue = TU.GetAptInfo(E.TOA_Appointment_ID__c);  // invoke the class method

       String vStat = returnvalue.get(0);  // Store the response values
       String vTrvlTime = returnvalue.get(1);
       String vResId = returnvalue.get(2);
       String vResName = returnvalue.get(3);
      
           E.TOA_Appointment_Status__c = vStat;   // assign the response values
           E.TOA_Traveling_Time__c = vTrvlTime;
           
           E.TOA_Resource_Name__c = vResName;
           
          
            update E;  // update the event record.
          }

VF page for event detail record :

<apex:page tabStyle="Appointment__tab" standardController="Event" extensions="cController"  sidebar="true" >
<script  type="text/javascript">
    function Testmy()
    {
        alert("Hello");
        callt();
    
    }
    </script>

    <apex:form >
     <apex:actionFunction name="callt" action="{!Test}"  />

    <style type="text/css">
         h { font-weight: bold; position: relative; left:8px; font-size:11px }
         
         p { font-weight: bold; position: relative; left:36px; bottom:10px; font-size:13px }
         
        .pbHeader
        {
          font-size:10px  ;
        }
        
        .  ext-webkit ext-chrome
        {
            background:#ececec;
        }
        
         h3
         {
             color: #222;
          }
       
    } 
    </style>
   
    <img id="theImage" src="/resource/home28" style="position:relative; top:10px; width:26px; "></img>
    <h>Appointment</h>
    <p>{!event.Subject}</p>
     <apex:pageBlock title="Appointment Detail" >
     <apex:pageBlockButtons location="top">
            <apex:commandButton value="Edit" action="{!edit}" style="font-size:11px"/>
            <apex:commandButton value="Delete" action="{!delete}" style="font-size:11px"/>
            <apex:commandButton value="Refresh"   onclick="Testmy()" style="font-size:11px" reRender="pgsec" />
    </apex:pageBlockButtons>
        
        <apex:pageBlockSection title="Calendar Details" columns="2" id="pgsec">
           <apex:pageBlockSectionItem >
                Assigned To
                 <apex:outputLink value="{!URLFOR($Action.User.View,Event.Owner)}}">
                     <apex:outputfield value="{!event.Owner.Name}" />
                </apex:outputLink>
            </apex:pageBlockSectionItem>
            
            <apex:pageBlockSectionItem >
                Related To
                <apex:outputlink onclick="window.location='/{!event.What}';"  value="#">{!event.What.Name}</apex:outputlink>
            </apex:pageBlockSectionItem>
           <apex:outputText value="{!event.Subject}"></apex:outputText>
            
            <apex:pageBlockSectionItem >
                Name
                 <apex:outputLink onclick="window.location='/{!event.Who}';" rendered="{!NOT(ISNULL(event.Who))}" value="#">{!event.Who.Name}</apex:outputLink>
            </apex:pageBlockSectionItem>
            <apex:outputText label="Start" value="{0,date,MM/dd/yy hh:mm a}"> <apex:param value="{!event.StartDateTime}" /></apex:outputText>
            <apex:outputText value="{!event.TOA_Work_Type__c}"></apex:outputText>
            <apex:outputText value="{0,date,MM/dd/yy hh:mm a}" label="End"> <apex:param value="{!event.EndDateTime}" /></apex:outputText>
             <apex:outputText value="{!event.TOA_Time_Slot__c}"></apex:outputText>
           <apex:outputText id="TOAID" value="{!event.TOA_Appointment_ID__c}" ></apex:outputText>
           <apex:outputText value="{!event.TOA_Resource_Name__c}"></apex:outputText>
           <apex:outputText value="{!event.TOA_Appointment_Status__c}"></apex:outputText>
           <apex:outputText value="{!event.TOA_Traveling_Time__c}"></apex:outputText>
           
            
         </apex:pageBlockSection>
         
        <apex:pageBlockSection title="Appointments">
         
         <iframe src=".../VikTableEffects?id={!event.Id}" style="width: 786px; height: 200px; border:0px"/>
        
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>


Thanks,
Pallavi
  • August 07, 2016
  • Like
  • 0

Is there an easy way of making Buttons visible to certain users/profiles? 

I have had a look but can't see an obvious way of doing this

Thanks in Advance,
Kim

Hi,

I am developing an application in salesforce lightning. I have a dashboard page and after clicking any menu it will navigate to particular component. I have created the header as a separate component and included in other components. I have action buttons for the body in header component. Let's say, I have a component A which has a user form and to save the form after filling these details i have "save" button in header component. To trigger the events i used a registered event in header components like below,

    <aura:registerEvent name="renewalPriceSaveEvent" type="ESRV:RenewalPriceSaveEvent"/>

And on button click i fired the event in header controller,

        var appEvent = $A.get("e.ESRV:RenewalPriceSaveEvent"); 
        appEvent.fire();

In body component i handled that event like this,

    <aura:handler event="ESRV:RenewalPriceSaveEvent" action="{!c.onSave}"/>

And called save method which works fine for the first time. The problem is when i again go to dashboard and again come to same page and click save button means the event is triggered twice. Is there any way to remove event if exists before firing? 

 
Hello All,

I'm new to salesforce and wondering how to update a field value in a related list if there more than one record in that list and you want to update only a specific record.

For example: In the below image, I would like to update the Payment received field with a value.
How would you update only one of the payment fields if there are more than one null value in the Payment received?

Would this have to be done with an trigger?

User-added image

Any help or suggestions would be apprieciated.

King regards,
Vinh
Hi friends
I have 2 custom objects, book1 and book2 with no relationship between them.
when I update a record in book1, the same record should be updated in book2.

Is this scenario possible if yes pls provide some inputs.

Thanks
pooja biswas
Hi 

I have a requirement to update some fields of an account based ont he Account Owner Ids. The process should be

1. Write Trigger in the Account Update
2. Check if the Owner is updated 
3. Check if a specific Id is common for both Old/New Owners (Select PGroupId, Id from user where id in (OldOwnerId,NewOwnerId)
4. If group id is same for both owners update specific fields in the account.

I have started coding in the Trigger. Since these changes are happening from the ETL process, I  am not sure how to bulkify my code. Should I get all the Account Ids before starting the Trigger & Compare in the below trigger ? Any suggestions
for (Account acc: Trigger.new) {
}

Thanks
Biju
I have a lookup field on the Opportunity record called Primary Fund (name of the fund to which a donation is posted), and I would like that data to be available in a field on the Contact object called Fund Name. I can't use a cross object formula. Is there a way to do it Process Builder? 
Hi all,
I need help in trigger, There are two objects Intake_details and claim. The issue is,some claim records are being created that do not have a corresponding Intake Detail record
A claim record should only be created if its name(claim number) field matches the Intake_details name field. 

Please suggest me how to do this.

Hi,

I have a requirement to edit an objects date field from my lightning component. With the relationship between the objects I have to create a wrapper to display the records and necessary date fields.

When I use aura:iteration with the wrapper ui:inputdate does not work properly. The date the user selects from the calendar does not get updated on the UI, however the values is updated in the back end.

When I use aura:iteration with a list of any concrete object ui:inputdate works properly. The date the user selects from the calendar gets updated on the UI, and the values is also updated in the back end.

Has anyone faced a similar issue and know of any work around for the same?

Thanks
Vivian