• Ankit Gupta@ Developer
  • NEWBIE
  • 387 Points
  • Member since 2013
  • Ankit Gupta


  • Chatter
    Feed
  • 11
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 2
    Questions
  • 101
    Replies
say I have 

Contact c= findContact();
ID campID= getCampID();

how can I...

A)
find if c is a campaign member of the campaign related to campID

B)
if it is not a member make it a member?

Thanks for any help I've just started learning salesforce and have been getting pretty frustrated with SOQL 
We use the account owner and their manager to control who can view accounts.  Owners can only see there accounts.  Works great.

I created a VF page and controller to display a custom object that has a master detail relationship with account.  Everyone can all the accounts.  I don't understand why the the account security is not following through on the VF page.  

Any help would be greatly appreciated.
 
I am trying to write a trigger that will automatically mark a task called 'Lead - Intro' as complete when the Lead Status changes from Open to Contacted. I tried cobbling it together from various similiar things I've found on the forum, but there are big chunks missing and I've sort of hit a brick wall. This is how far I've come so far:

trigger updateTaskStatus on Lead (after update) {
 
try{   
        for(Lead myLead: Trigger.new){
            
            if((myLead.isconverted==false) && (myLead.Status == 'Contacted')) {
            
        List<Task> taskstatus = new List<Task>();
        
             for (Task t: taskstatus){
  if (t.Subject == 'Lead - Intro') && (t.Status == 'Open') {
    t.Status = 'Completed';
  }
            
                Update taskstatus;                             
                }
Not sure where I am going wrong but I need a javascript button to make a checkbox true...easy enough and Ive done it loads....but here I want the user to be prompted for a password which they enter and then the checkbox is marked true if they have the password correct. I have been trying the code below but I keep getting Error: The Name field is required

var ans=prompt("Please enter password","");
if(ans=="123"){

var newRecords=[];
var q=new sforce.SObject("Quote");
q.id="{!Quote.Id}";
if({!Quote.Override_Docusign__c}==false){
q.Override_Docusign__c=true;
newRecords.push(q);
result=sforce.connection.update(newRecords);
window.location.reload();
}
else
{alert
("Override already marked true");
}
else{
alert("Incorrect Password")
}
I have created an APEX REST class that queries two different objects and returns multiple rows for both queries. Both queries return completely different values.

I want to get the results of both the resultsets into one JSON object which will be automatically parsed due to the REST call.

Is this possible ?


I tried to put both resultsets into a single <sObject> list but it gave me an error saying two different types of objects were being added into a single list.

i have a trigger that will update a custom date/time field in my case but it seems like not working

This is my trigger:

c.SLA_Cont_Time__c = System.now() - c.SLA_Days_mins__c;

c.SLA_Cont_Time__c is my custom date/time field and c.SLA_Days_mins__c is a numeric field that i need to minus it to get latest value. but my c.SLA_Cont_Time__c keep getting the System.now() value instead. why it will not take the after subtraction value?

anything wrong?
Hi and thanks in advance...

Requirement: Before inserting New Opportunity check Account.Credit_Status__C (custom field).  If it doesn't meet requirements pop-up message.  If this is not the way it's done feel free to offer ideas.

Here is the code
trigger checkAccountCreditStatusisRejected on Opportunity (before insert) {
      
     for (Opportunity opp : System.trigger.new) {           
        if (opp.AccountId.Credit_Status__c == 'Rejected')
          {
             opp.addError('A new Opportunity cannot be created on account where Credit Status = Rejected');
          }// end if         
                        
       }//end for   
     
}// end trigger

Regards
How many email alerts can be created on a single workflow rule?
Hey there,

I have an email trigger and a class in which I use to send emails to all the contacts associated with an account when a service (which is also associated with the account) reaches stage 4. I have written test codes before, but I do not even know where to begin to write test code for an email trigger. please help.  


This is my trigger: 

trigger SendEmailtocontact on Service__c (after Update) {

    List<String> lcontactEmails = new List<String>();
    Set<Id> sIds = new Set<Id>();
  
    for(Service__c qItr : Trigger.new){
        if(Trigger.isUpdate){
            if(Trigger.oldmap.get(qItr.id).Service_Stage__c != qItr.Service_Stage__c && qItr.Service_Stage__c.containsIgnoreCase('Stage 4')){
                sIds.add(qItr.id);
            }
        }
        else if(Trigger.isInsert){
            if(Trigger.newMap.get(qItr.id).Service_Stage__c.containsIgnoreCase('Stage 4')){
                sIds.add(qItr.id);
            }
        }
    }
    for(Account accItr : [SELECT id,(SELECT id FROM Contacts) FROM Account WHERE id IN (SELECT Account__c FROM Service__c WHERE Id IN: sIds)]){
        for(Contact con : accItr.contacts){
            if(!String.isBlank(con.id)){
                lcontactEmails.add(con.id);
            }
        }
        if(!lcontactEmails.isEmpty()){
         EmailHandler.sendEmail(lcontactEmails); 
        }
    }
}

This is my class:

public class EmailHandler{

    public static void sendEmail (List<String> contactids){
    
        Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
        //set the email properties
        mail.setTargetObjectIds(contactids);
        mail.setSenderDisplayName('Destiny Customer Service');
        mail.setTemplateId('00XO0000000MEyP'); //Id of the Email Template
    
        //send the email
        Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail } );
      }
}


I was also hoping to maybe get some pointers on how I may clean up this code a bit, as I changed it a bit and I am sure there is a fair bit of redundant lines in there.

Thank you in advance for your help

Kind regards,

Mikie
Hi,

How can i get custom enhanced list.

I have created a vf page. which look like the enhaced list view. but in the vf page i should not use <apex:enhancedlist>. How can this be achieved.

Regards
Suresh S

Hi,

 

How i rename Home tab in salesforce?

 

 

 

 

regards,

Sagar

Hi All,

I'm facing issue while connecting Odata with JSON getting following error

External Object Error
We encountered an unexpected error. Try again later, or contact your administrator, who can verify the external data source settings and the external system's availability. Error received from the external system: 


if I changed the format from JSON to AtomPub. it is working fine. 



 

Hi,

 

 

I have created a blank visualforce page  and check the javascript error console i'm getting below error

 

 

Timestamp: 10/19/2013 8:35:43 PM
Error: ReferenceError: initViewstateTab is not defined
Source File: https://c.ap1.visual.force.com/jslibrary/1381427012000/sfdc/VFDevMode.js
Line: 23

 

 

Hi, I'm new to apex and trigger and have an issue. I need to update a field on a record when 2 other fields are updated. This field is supposed to calculate the time between 2 dates based on the business hours. My trigger work with old records but not with record that are newly updated.
Here is my trigger:
trigger RequirementTrigger on Requirement__c (before insert, before update) {
    RequirementTriggerHandler.calculerDelai(Trigger.new);
}
Here is my handler:
public with sharing class RequirementTriggerHandler {

private static String businessHoursTMA;

//Récupère BusinessHours TMA
static{
    BusinessHours businessHours = [SELECT Id FROM BusinessHours WHERE isDefault = true];
    businessHoursTMA = businessHours.Id;

}

//Calcul délais entre changement de statuts en heure
public static void calculerDelai(List<Requirement__c> newRequirement){
    for(Requirement__c rq : newRequirement){
        if(rq.Date_d_but_statut_DMR__c  != NULL){
            // Délai moyen de prise en charge DMC (Date début "statut DMR"– Date début prise en charge) en heures  
            if(rq.Date_debut_prise_en_charge__c != NULL){
                rq.Delai_DMC__c = BusinessHours.diff(businessHoursTMA,
                                                 rq.Date_debut_prise_en_charge__c,
                                                 rq.Date_d_but_statut_DMR__c)/ 3600000;
            }
            // Délai moyen de qualification/assignation DMA (Date début "statut DMR"– Date début "statut DMA") en heures
            if(rq.Date_d_but_statut_DMA__c != NULL){
                rq.Delai_DMA__c = BusinessHours.diff(businessHoursTMA, 
                                                 rq.Date_d_but_statut_DMA__c, 
                                                 rq.Date_d_but_statut_DMR__c)/ 3600000;
            }
            // Délai moyen de réalisation DMR (Date de résolution du ticket – Date début "statut DMR") en heures
            if(rq.Date_de_resolution_ticket__c != NULL){
                 rq.Delai_de_realisation__c = BusinessHours.diff(businessHoursTMA, 
                                                            rq.Date_d_but_statut_DMR__c,
                                                            rq.Date_de_resolution_ticket__c)/ 3600000;
            }


        }
    }

}
Hope you can help me, thank you ! 
  • March 14, 2019
  • Like
  • 0
All,

I'm trying to call an apex function from a javascript button. I've read the developer guide and several relevant posts on this forum, but still can find out the issue. I have not created any namespace prefix for my dev org. The conroller is different from the Helper class with the web service method.
VF page:
<apex:page showHeader="false" >
  
 <script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script>
 <script src="/soap/ajax/15.0/apex.js" type="text/javascript"></script>
 
 <script type="text/javascript">
    
    function testRemote(){
        var id = sforce.apex.execute("HelperClass","getContactId",{});
        alert('id is: '+id);
        }
 
 </script>
  
 <div>  
    <button onclick="testRemote();">
      Remote
    </button>
  </div>
 </apex:page>

Apex class for webservice:
global class HelperClass {
    
    webService static String getContactId(){
       
        String id = '003j0000002CQ3B';
        return id;
    	}
}
Much appreciated,

Sarju
 
say I have 

Contact c= findContact();
ID campID= getCampID();

how can I...

A)
find if c is a campaign member of the campaign related to campID

B)
if it is not a member make it a member?

Thanks for any help I've just started learning salesforce and have been getting pretty frustrated with SOQL 
Hello
I want create Accounts from php sdk ...
In create contacts, need fill "Account Name" fields .
if Account exists, i has account ids and correct fill AccountId field,
But sometime, need create new Account for contacts , how i do it ? 
thanks !
I am facing this error wile i am saving the class which implements webservicemock any help much appriciated
Hello, I am working on this trigger where I want to update a custom date field only when certain fields on the table are changed. I am assuming that Contact and Person Account has shared fields, so how would I create this trigger? (may be 1 for Account and another for Contact?)

Thank you, a simple example would be great! :)
We use the account owner and their manager to control who can view accounts.  Owners can only see there accounts.  Works great.

I created a VF page and controller to display a custom object that has a master detail relationship with account.  Everyone can all the accounts.  I don't understand why the the account security is not following through on the VF page.  

Any help would be greatly appreciated.
 
Hi,
I need a test code for this pagereference method ..its with for loops and if conditions..so help me to findout this.
Thanks in advance.
public PageReference Del (){
        Integer dmlrows = Limits.getLimitDMLRows();
        Integer curdmlrows = Limits.getDMLRows(); 
        Integer remainingdmlrows = dmlrows - curdmlrows;
        
        Integer indexVal = Integer.valueof(system.currentpagereference().getparameters().get('index'));  
        
        if (newRFPProdList.get(indexVal - 1).id!=null)
            delRFPProdList.add(newRFPProdList.get(indexVal - 1));
        
        Id prodid = newRFPProdList.get(indexVal - 1).Product__c;  
        system.debug('selectedprodid'+prodid);
        try{
        delete [select ID from rfp_question__c where rfp__c = :rfpID and product__c =: prodid];
        remainingdmlrows = dmlrows - curdmlrows;
        
        newprd.remove(indexVal - 1);
        newRFPProdList.remove(indexVal - 1);
        
        if(delRFPProdList.size()>0)
            delete delRFPProdList;
        delRFPProdList.clear();
        }
        catch (Exception e) {
          String  message  = '[ PACRES ] Exception: ' + e.getMessage() + '; line: ' + e.getLineNumber() ;
            //ApexPages.addMessage(message);
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, '[ PACRES ] Exception: ' + e.getMessage() ));
            exceptionMessages += message + '\n\n';
        }
        return null;
    }
Hi,

I am Creating custom button in salesforce when i click on the button it will execute java script here i need to check the current logged user .and need to add users to one list and compare the user with users in the list if the logged in user is present in the list then redirect to page1 .else give an error message.
Can someone tell me how to write javascript code to achieve this?

thanks
lokesh 
Hey there,

I am trying to render a PDF in a Visualforce page and I tried every possibility I found. This is my webservice (from the controller ShowInfoFactura) which gives a SOAP envelope response after calling it:
webservice static Blob getPDFMethod() {
        String theResult, theFinalResult;
        Blob blobby;
        try {
            // Web Service Calls
            // (...)
            wsResponse = wsPort.getWSResponse(ApexPages.currentPage().getParameters().get('id')); // SOAP envelope
            theResult = String.valueOf(wsResponse); // String
	        List <String> splitTheResult = new List<String>(theResult.split('result'));
            String theResultString = splitTheResult.get(2);
            String theResultStringRight = theResultString.right(theResultString.length() - 1);
            theFinalResult = theResultStringRight.left(theResultStringRight.length() - 3);
            blobby = EncodingUtil.base64Decode(theFinalResult);
        }
        catch (System.Exception ex) {
            ApexPages.addMessages(ex);
  			return null;
        }
        return blobby;
    }
These are the results (USER_DEBUG):
  • theResult (SOAP envelope): 17:00:00:517 USER_DEBUG [5]|DEBUG|The custom response is: wsResponse:[apex_schema_type_info=(http://jws.client.factory/, false, false), field_order_type_info=(message, result, status), message=null, message_type_info=(message, http://jws.client.factory/, null, 0, 1, false), result=JVBERi0xLjQKJeLjz9MKNSAwIG9iago8AxDL2rgKdlVtWsyxMqy3f1atrQvgtneJKOADeQU/Ds5njLlfLohtg3ee73unERvYmoKMTkgMCBvYmoKPDwvY2EgMT4+Pi9QYWdlcyAxNSAwIFI+XS9JbmZvIDM4IDAgUi9TaXplIDM5Pj4Kc3RhcnR4cmVmCjIzNjI5OAolJUVPRgo=, result_type_info=(result, http://jws.client.factory/, null, 0, 1, false), status=1, status_type_info=(status, http://jws.client.factory/, null, 1, 1, false)]
  • theFinalResult (Encoded PDF String): JVBERi0xLjQKJeLjz9MKNSAwIG9iago8AxDL2rgKdlVtWsyxMqy3f1atrQvgtneJKOADeQU/Ds5njLlfLohtg3ee73unERvYmoKMTkgMCBvYmoKPDwvY2EgMT4+Pi9QYWdlcyAxNSAwIFI+XS9JbmZvIDM4IDAgUi9TaXplIDM5Pj4Kc3RhcnR4cmVmCjIzNjI5OAolJUVPRgo
My visualforce page:
<apex:page controller="ShowInfoFacturas" renderAs="pdf" applyBodyTag="false">
    <head>
        <style> 
            html, body, p { font-family: 'Arial Unicode MS'; }
        </style>
    </head>
    <body>
        <center>
        <h1>Factura</h1>
        <apex:panelGrid columns="1" width="100%">
            <apex:outputText value="{!PDFMethod}" escape="false"/>
            <apex:outputText value="{!NOW()}"></apex:outputText>
        </apex:panelGrid>
        </center>
    </body>
</apex:page>

It does not show me the PDF, does anybody know how to do it properly? 

Thank you.
It is Possible for Custom Setting records updation for various profiles using custom VF Page or Permission set.
Actuallay I have creaeted custom VF Page and Apex Class to udpate Custom setting records.
How to use batch apex and schedule?
plz help me with this.
1) I am having an User (let’s say Stephan). Who has a custom Field called : Immediate Manager. (Hierarchy Field)
2) We have an Account (let’s Say : Google). Whose owner is Stephan.
3) Whenever I will deactivate that user, then that User’s Immediate manager will become owner of all Account, which Stephan owned. Code with all best practices. (Bulkifying).
Also write Test method for this , which should cover at least 85%. functionality should be checked if working or not in test Class also.

trigger RecordOwnerChangeEx on User (after update) {   
 list<user> u=[select id, isActive, ManagerId from user where id in:trigger.new];
  // list<account> acc=[select id, ownerId from Account where ownerId in: ids ];
    list<account> ac=new list<account>();
    for(User uu:u){
        if(uu.IsActive == false && uu.ManagerId != null){
        for(account a:[select id, ownerId from Account where ownerId =:uu.id ]){
            a.ownerId = uu.ManagerId;
            ac.add(a);
        }
    }
    }
    update ac;

Tried with this but not working. 
I would like to know if it’s possible to implement an in-app live chat into our app (Platform: Ember.JS and Ruby on Rails).

If this is possible- can you provide documentation on how to implement this into any app?

Thanks
Tim 
I am having difficulty in image upload, as my image is not getting uploaded to external system when I use httprequest. Please help.

I am using simple html form to post content to external site. Image is not getting posted as image is not bounded with an apex variable in controller.
Hello Team,

I want to display  few questions  and answers realted to that questions in Visual force page. But on click of next question, i have to get second and so on 

Would you please guide me how to achieve this, I tried using pagination but facing difficulties to retrieve answer options.

These question and answers are stored in same table.

Thanks,
Kumar
Hi,

I just ran into an issue using ui:textInput within aura:iteration
 
<aura:attribute name="test" type="String[]" default="test1, test2"></aura:attribute>

<aura:iteration items="{!v.test}" var="t">
      {!t}
      <ui:inputText value="{!t}"></ui:inputText>
</aura:iteration>

so when I type something in the input box and leave it, the output should change too, shouldnt it?
Any help?
Thanks!
 
Let me first say "thank you" in advance for any and all help given for my project here.  I'm a novice when it comes to apex code but I know what I want to do is possible.  

What I want to do
On the account object, I have a field called "Current_Status__c" where my reps can update information about their account for the week.  The problem with this is that I want to be able to have the history of each of these statuses, so I was thinking the best might be to "log a call" or use "new task" with the subject line of "Status Update".   The rep would fill out the "Comments" sections which Salesforce calls "Description" and then their information would automatically move to the "Current_Status__c" field on the account.  Each week the rep would "log a call" or use "new task" again and the "Current_Status__c" field would be overwritten with the latest information.  I already have a "status history" field that checks whenever "Current_Status__c" is changed and adds the latest info to the history field.  

What I need (ie. Everything)
  1. Should I use "log a call" and just make the subject "Status Update" or use "new task"?  Is there a benefit to either one?  
  2. The actual apex code on how to do this
  3. Test code
  4. Any other information on how to deploy this to production.  I can use the Sandbox.

I've found a couple other discussions that I could repurpose for my situation but I don't know how to write the test code and what I should use to actually deploy my code.  I'm willing to learn and piece things together if folks can point me in the right direction.  

Thanks again to all those willing and able to help.  I really appreciate it.  

Conor
plz help me with this.
1) I am having an User (let’s say Stephan). Who has a custom Field called : Immediate Manager. (Hierarchy Field)
2) We have an Account (let’s Say : Google). Whose owner is Stephan.
3) Whenever I will deactivate that user, then that User’s Immediate manager will become owner of all Account, which Stephan owned. Code with all best practices. (Bulkifying).
Also write Test method for this , which should cover at least 85%. functionality should be checked if working or not in test Class also.

trigger RecordOwnerChangeEx on User (after update) {   
 list<user> u=[select id, isActive, ManagerId from user where id in:trigger.new];
  // list<account> acc=[select id, ownerId from Account where ownerId in: ids ];
    list<account> ac=new list<account>();
    for(User uu:u){
        if(uu.IsActive == false && uu.ManagerId != null){
        for(account a:[select id, ownerId from Account where ownerId =:uu.id ]){
            a.ownerId = uu.ManagerId;
            ac.add(a);
        }
    }
    }
    update ac;

Tried with this but not working.