+ Start a Discussion
Rami HawlyRami Hawly 

Hello,

Did anyone else notice that the view state limit in Visualforce pages has been increased from 135 to 170 KB in the new release of Spring 2019

Best Answer chosen by Rami Hawly
DevADSDevADS
That's correct. With Spring'19 release the limit is increased from 135 KB to 170 KB.

Reference - https://releasenotes.docs.salesforce.com/en-us/spring19/release-notes/rn_vf_view_state_limit.htm
asadimasadim 

Hi,

 

Is there a way to select everything in SOQL like "SELECT *" in SQL? I have looked at the SOQL manual about SELECT statements but it didn't tell if I can do this or not.

 

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
ArtabusArtabus

No, you can't do this in SOQL, but you can generate dynamically your SOQL query with the list of all fields (Id, Name, etc...).

To identify all fields, you can use the API call describeSObjects()

Manu KM 9Manu KM 9 

Hi,

Lets say we have an object and on the lightning component we are displaying its details. when ever i click on the button i need to pass record id to the controller.

This how my code look like:-
<aura:iteration items="{! v.vegs}" var="veg">
            <div class='tile' aura:id="test1" press="{! c.tester}" >              
                <img src='{! veg.Image__c}'  onClick="{! c.tester}" aura:id="imgId" value="{! veg.Name }"> </img>
                Name: {! veg.Name } <br></br>             
                price: {! veg.Price__c }   <br></br>
                <ui:button label="Add to cart" press="{! c.addToCart}"  aura:id="btn1" >      </ui:button>               
           </div>
</aura:iteration>

I want something similer to :-
 
<aura:iteration items="{!v.newCases}" var="case">
<button type="button" onclick="{!c.showCaseDeleteModal(case.Id)}">Delete</button>
</aura:iteration>


How can I pass the id to a component controller when the  button gets clicked?


Thank you!
Best Answer chosen by Manu KM 9
Veenesh VikramVeenesh Vikram
You can get ID in the JS controller directly, no need to assign to another attribute,

Do like this:
In your component, assign the record Id to the button's Id
<aura:iteration items="{!v.newCases}" var="case">  
<button type="button" onclick="{!c.showCaseDeleteModal}" id={!case.Id}>Delete</button> 
</aura:iteration>
In your JS controller, capture the ID as as source of event:
 
showCaseDeleteModal: function(component, event, helper) {
var idx = event.target.id;
alert(idx);                       //here is your ID
});

Kindly mark as solved if it helps.

Regards
Veenesh
Stéphanie ParkStéphanie Park 
We have a VisualForce page that needs to be displayed on our website through an iframe. The problem is that both Mozilla and Chrome are displaying error message, saying that the connection is not secured. 

"Your connection is not secure
The owner of xyz.force.com has configured their website improperly. To protect your information from being stolen, Firefox has not connected to this website."

I checked the configuration of our site in Salesforce. It looks like HTTPS is enabled. We have a self-signed certificate, but that's it. 

We're using Salesforce Classic and for the moment there's no project to use tools like Canvas or Lightning out...  
Any suggestions? 
Thanks.  
Best Answer chosen by Stéphanie Park
Khan AnasKhan Anas (Salesforce Developers) 
Hi Stéphanie,

Greetings to you!

According to Salesforce Knowledge Article (https://help.salesforce.com/articleView?id=000230362&type=1):

Force.com Sites uses different domains for HTTP versus HTTPS. The force.com sub-domain gets sent to Akamai and the HTTPS version goes to the secure.force.com domain instead of force.com. Attempting to use HTTPS on the force.com subdomain results in a certificate error. 

The right URL usage would be:

HTTPS: https://xyz.secure.force.com

HTTP: http://xyz.force.com

It is key to note that the Require Secure Connections (HTTPS) option can help ensure that anyone who accesses http://xyz.force.com gets redirected to https://xyz.secure.force.com

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Andrew4Andrew4 
Hi all,

I've been stuck on this for a while, so I'm finally asking for help - issue is similar to this one:
https://developer.salesforce.com/forums?id=906F000000094yFIAQ

I have a Visualforce page that uses the standard Event controller.  I overrode the "New Event" button to direct to this Visualforce page.  I'm having trouble pre-populating certain fields on that page.

For example, {!Event.whoID} is passed in the button URL and pre-populates the appropriate field by default.  I want to pass the User ID too and populate the Assigned To field, but I can't get it to work.  The default New Event page (which uses the same standard Event controller) populates the Assigned To field automatically, and without any additions in the URL... what am I missing?  Does my VF page need a controller extension?  If so, can anyone give pointers on what that needs to look like?

I assume I need to A) include whatever IDs I want populated in a custom button URL, and simultaneously B) build a controller extension that tells my VF page to pull the values out of the URL and load them in my input fields.  But all my attempts to implement this setup so far have failed.

Any pointers will be greatly, greatly appreciated.  Thanks for your help!



VF page snippet:
<apex:page standardController="Event" showHeader="true" sidebar="true">
    <apex:sectionHeader title="Log A Call"/>
    <apex:form id="pageForm">
        <apex:pageBlock title="Call Edit" mode="edit">
            <apex:pageBlockButtons location="both">
                <apex:commandButton value="Save" action="{!save}" id="saveButton"/>
                <apex:commandButton value="Cancel" action="{!cancel}" />
            </apex:pageBlockButtons>
            <br />
            <apex:pageBlockSection title="Owner" columns="2" collapsible="false">
                <apex:inputField value="{!Event.ownerID}" label="Who took the call?" style="width:200px;height:15px;" />
                <apex:inputField value="{!Event.StartDateTime}" label="Start" />
                <apex:inputField value="{!Event.Subject}" label="Subject" />
                <apex:inputField value="{!Event.EndDateTime}" label="End" />
                <apex:inputField label="Person" value="{!Event.whoID}" style="width:300px;height:20px;" />
                </apex:pageBlockSection>
                </apex:pageBlock>
    </apex:form>
</apex:page>

Current button URL (owner ID to be added):
https://c.cs8.visual.force.com/apex/NewLogCall?who_id=XXXX&retURL=%XXXX&sfdc.override=1


Assuming a controller extension that looks something like:
public class callExtension {
    public callExtension(ApexPages.StandardController stdController){
    public Event getEvent(){
        if(event == null) event = new Event();
        event.ownerid = ApexPages.currentPage().getParameters().get('ownerID');
        return event;
        }
    }
}


Thanks again!


Andrew

 
Best Answer chosen by Andrew4
Andrew4Andrew4
This is finally working - for any subsequent viewers, this is the final setup:

The custom button URL is as follows (OnClick JavaScript):
window.location = '/apex/NewLogCall?who_id={!Contact.Id}&ownerid={!$User.Id}&sfdc.override=1';


The controller extension is as follows:
public class callExtension2 {
public Event event{get; set;}
    public callExtension2(ApexPages.StandardController stdController){
       if(event == null) event = new Event();
       event.ownerid = ApexPages.currentPage().getParameters().get('ownerid');
       event.whoid = ApexPages.currentPage().getParameters().get('who_id');
    }
}


For subsequent fields, simply add a new line in the controller extension, and add the value of the field into the button URL.  Essentially the same solution as in the other thread on this topic, but this is code you can paste directly and get working.  Thanks for everyone's help!
RupBRupB 

Hi,

 

- Sorry to bother, but I found no answer to this wuestion either on the web, or in the dev forum, or in the Apex documentation - 

 

I have a trigger, which detects error conditions and feeds errors to the class or field.

This gives a nice result interactively, in the GUI.

But how do I write test code to catch these errors ?  Is there a System.AssertException(), or the equivalent ? 

 

trigger createOrder on Asset (after insert, after update) {[...] if (price.get(a.Product2Id) == NULL) { System.debug(' error : no active price'); a.Product2Id.addError('no active price on the Product'); }[...]}

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
sfdccoder1sfdccoder1

Hi RupB,

 

I worked out a solution for a similar case I had where addError() was used for a record and not for a field.

I  believe though it should work for your case too.

 

The idea is to:

 

a. Write code in the test class that will cause the trigger to 'addError()'.

b. Surround the above test class code with try - catch.

cAssert that an exception is thrown and that the exception message is the same one you created with 'addError()'.

 

Here's an example (partly pseudo) code from both trigger and test class:

 

Trigger: 

 

if(myRecord.MyField == some value)

myRecord.addError('My Error Message');

 

 

Test Class: 

 

try

{

MyRecord.MyField = a value that will cause an error

update MyRocord;

throw new MyException('An exception should have been thrown by the trigger but was not.'); // 1. If we get to this line it means an error was not added and the test class should throw an exception here. 2MyException class extends Exception.

}

catch(Exception e)

{

Boolean expectedExceptionThrown =  e.getMessage().contains('My Error Message')) ? true : false;

System.AssertEquals(expectedExceptionThrown, true);

 

 

Let me know if this did the work

 

 

Message Edited by sfdccoder1 on 09-01-2009 01:32 AM
Munira MajmundarMunira Majmundar 
Can folks who have completed Salesforce Connect Trailhead help?

I am getting the following error:
Challenge Not yet complete... here's what's wrong: 
An external object with the API name Phone_Plan__x does not exist

The instruction on the Challenge says
Note that you will need to adjust the Object Names for the two external objects from the default setting after the initial sync.

So, I go to the External Object and changed the API to Phone_Plan__x

This gives me a validation error
Error: The Object Name field can only contain underscores and alphanumeric characters. It must be unique, begin with a letter, not include spaces, not end with an underscore, and not contain two consecutive underscores. 

It says the Object Name field should not contain two consecutive underscores.  But, the API name does contain two consecutive underscores at the end.

Can someone please help?

Thanks,
Munira

 
Best Answer chosen by Munira Majmundar
Sandeep WaliaSandeep Walia
Sharing a screenshot would have been helpful.

But an external object doen not allow to setup the API name.We can only change the Label,Plural Label and Object Name while creating the object as shown below:
User-added image

Instead of naming your object Phone_Plan__x,change it to just Phone Plan.
Richard Rodriguez 1Richard Rodriguez 1 
I'm trying to create an Apex Class that checks all Account records on a daily basis and sends an email to the email field on ones that have a review due on that date.

For example:
Vendor ABC Pty Ltd has opted in for reviews (Vendor Review: Reminders = true), has an annual review date set in their record (Vendor Review: Date = 17/02/2019), and an email address set in their record (Vendor Review: Email = abc@test.com).

Here is my code:
global class VendorReviewCronJob implements Schedulable{ 
    
        global void execute(SchedulableContext SC) {
            sendmail();
        }

        public List<Id> getVendorReviewEmailAddresses(Integer Month, Integer Day) 
        { 
            List<Id> mailToIds = new List<Id>();
             
            Account[] a = [SELECT Id, Vendor_Review_Email__c, Vendor_Review_Date__c, Vendor_Review_Reminders__c
                            FROM Account 
                            WHERE DAY_IN_MONTH(Vendor_Review_Date__c) = : Day 
                            AND CALENDAR_MONTH(Vendor_Review_Date__c) = : Month   
                            ];
        
            for(Account recipient : a) {
                    
                    System.Debug('\n*******Found VendorReview Recipient');
                                        
                    if (recipient.Vendor_Review_Reminders__c == true)
                    {
                        mailToIds.add(recipient.Id);
                        System.Debug('\n*******Recipient: '+ recipient.Vendor_Review_Email__c);
                         
                    } else {
                        System.Debug('\n*******NO Recipient');
                    }
                
            }

            return mailToIds;
        }




        public void sendMail() 
        {
      
            String debugAddress = 'eyewell@salesforce.com';
            String VendorReviewEmailTemplateName = 'User_Vendor_Review_Required';       
            String debugMessage;
            String[] toAddresses;

            Integer DayOfEvent   = date.today().day();
            Integer MonthOfEvent = date.today().month();

            List<Id> VendorReviewIdsList = getVendorReviewEmailAddresses(MonthOfEvent,DayOfEvent);

            EmailTemplate VendorReviewTemplate = [select Id,Name,Subject,body from EmailTemplate where DeveloperName = :VendorReviewEmailTemplateName];
 
            if(VendorReviewTemplate != null && VendorReviewIdsList.isEmpty() == false)
            {

                Messaging.MassEmailMessage VendorReviewMail = new Messaging.MassEmailMessage();
    
                VendorReviewMail.setTargetObjectIds(VendorReviewIdsList);
                VendorReviewMail.setTemplateId(VendorReviewTemplate.Id);
                VendorReviewMail.setUseSignature(false);
                VendorReviewMail.setSaveAsActivity(true);

                try {
                    Messaging.sendEmail(new Messaging.MassEmailMessage[] { VendorReviewMail });
                }catch(Exception e)
                {
                    System.Debug(e);
                }
           
            }
            else
            {
                System.Debug('VendorReviewCronJob:sendMail(): Either an email template could not be found, or no Account has a Vendor Review today');
            }

                
        }

    
}
I've scheduled the apex class to run daily, but although it's showing that it has run, the emails for the reviews due that day haven't sent, and I also haven't received the confirmation email of how many were sent.

Admittedly, I got the base of the code from a mailer that was checking for birthdays on a Contact object, but I felt the same principles still applied.

Can anybody see where I've gone wrong?
Best Answer chosen by Richard Rodriguez 1
SarvaniSarvani
Hello Richard,

I see there is no problem in your code. It worked for me, when I tested on "contact" object but NOT  for "Account" object. It gave me error "Only Users, Contacts, Leads, and Person objects are allowed for targetObjectIds.: []."  Try using SingleEmailMessage method and use setToAddresses attribute to set the email receiver.

Hope it helps,

Thanks,
Sarvani
Brian Chipman 4Brian Chipman 4 
Would like to create a class to POST some data on an endpoint provided by an outside vendor.  Am modeling it on the "Mighty Moose" Trailhead example (https://trailhead.salesforce.com/en/content/learn/modules/apex_integration_services/apex_integration_rest_callouts) and the only difference seems to be the endpoint, the existence of an "api_key" (which the vendor says should be part of the url), and am passing more than one field.  Looks simple, but I have never done this type of thing before.  

Am testing in the "Open Execute Anonymous Window" of the developer console.  The trailhead example works fine but I am always getting a 400 Bad Request error for the real call out.  I do have a Remote Site setting.

Anything in the code below you can see (some data changed for security reasons)?
Any code you think might work better?
Any questions or details I should ask the vendor?
The vendor says I should be getting an explanatory message, but in the debug log I only see '400 Bad Request' and some other seemingly unrelated stuff.
 
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://my.domain.com/icon/send_eligible_offers?api_key=abcd-1234');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');

// Set the body as a JSON object
request.setBody('{"product_sku":"NTL07007", "serial_number":"1234343434", "user_email":"user.name@gmail.com", "sales_person_email":"agent@mail.com"}');

HttpResponse response = http.send(request);

// Parse the JSON response
if (response.getStatusCode() != 201) {
    System.debug('The status code returned was not expected: ' +
        response.getStatusCode() + ' ' + response.getStatus());
} else {
    System.debug(response.getBody());
}

 
Best Answer chosen by Brian Chipman 4
Egor Gerasimenko 9Egor Gerasimenko 9
400 Bad Request is the response from the endpoint you are trying to hit, and typically indicates that you are sending some bad data. Perhaps you are missing a header or your JSON doesn't match the expected schema. You can try to send the same request using a REST tool like Postman to confirm that the problem is not with the Apex code. 
Sammy7Sammy7 
Hi, 
 Im getting the following error and cannot figure out why: 

System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Email address is invalid: null: [toAddresses, null]

Class.email_class.send: line 48, column 1
Class.TestquoteEmailclass.sendEmailTestMethod: line 47, column 1

Below is my test class: 
@isTest
public class TestquoteEmailclass {
    @isTest static void sendEmailTestMethod(){
    
        Product2 prod = new Product2(Name = 'SLA: Bronze', IsActive = true);
        insert prod;
        PricebookEntry pbe=new PricebookEntry(unitprice=0.01,Product2Id=prod.Id, Pricebook2Id=Test.getStandardPricebookId(), IsActive= true); 
        insert pbe; 
        Account acc = new Account (name='Acme');
        insert acc;
        Opportunity opp= new Opportunity (name='Testopp', Accountid=acc.id, CloseDate= date.today(), StageName='Closed Won', Pricebook2id=Test.getStandardPricebookId());
        insert opp; 
        OpportunityLineItem oppLine = new OpportunityLineItem( pricebookentryid=pbe.Id,TotalPrice=2000, Quantity = 2,Opportunityid = opp.Id);
        insert oppLine;       
        Quote q= new Quote (Name='Testq', Opportunityid=opp.id, QuotetoInvoice__c= True,  Pricebook2id=Test.getStandardPricebookId());
        insert q;
    
     System.currentPagereference().getParameters().put('id',q.id);
     Attachment objAtt = new Attachment();
     objAtt.Name = 'Test';
     objAtt.body = Blob.valueof('string');
     objAtt.ParentId = q.Id;
     insert objAtt;

         ApexPages.StandardController sc =new ApexPages.StandardController(q); 
        email_class ec=new email_class (sc);
        ec.ToAddresses='test@gmail.com';
         ec.CCAddresses='test2@gmail.com';
        ec.emailCC= 'test3@gmail.com';
        ec.email_body='test1111111';
        ec.subject='test22222';
        
         Messaging.InboundEmail email = new Messaging.InboundEmail();  
         Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
        email.plainTextBody = 'This should become a note';
        email.fromAddress ='test@test.com';
        String contactEmail = 'jsmith@salesforce.com';
        email.ccAddresses = new String[] {'Jon Smith <' + contactEmail + '>'};
        email.subject = 'Dummy Account Name 123';

        ec.send();

}
}

And my controller:
public class email_class{
        
    Public string ToAddresses {get;set;}
    Public string CCAddresses {get;set;}
    Public string quoteId {get;set;}
    Public string subject {get;set;}
    public string email_body {get;set;}
    public string emailTo {get;set;}
    public string emailCC {get;set;}
     public  string [] ccaddress;   
              
        
        
        public email_class(ApexPages.StandardController controller) {
                quoteId = ApexPages.currentPage().getParameters().get('id');
    }
        
    Public PageReference send(){

                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); // set the to address
                mail.setToAddresses(new String[] {emailTo}); 
               // mail.setCCAddresses(new String[] {emailCC});   //set the cc address
                   
        if(emailCC != null && emailCC.trim() != '')
        {
        ccaddress = emailCC.split(',',0);
        mail.setCCAddresses(ccaddress);}
                                                              
   
                mail.setSubject(subject);
                mail.setBccSender(false);
                mail.setUseSignature(false);
                mail.setPlainTextBody(email_body);
               

                List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();

                for (Attachment a : [select Name, Body, BodyLength from Attachment where ParentId = :quoteId]){  // Add to attachment file list  
                        Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();  
                        efa.setFileName(a.Name); 
                        efa.setBody(a.Body); 
                        fileAttachments.add(efa);
                }
                mail.setFileAttachments(fileAttachments);// Send email
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
                return null;
        }
}

Any help is appreciated !
Best Answer chosen by Sammy7
Sammy7Sammy7
Forgot to pass "emailTo" DOH !