function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mayank Srivastava (Salesforce fan)Mayank Srivastava (Salesforce fan) 

Invalid left-hand side in Assignment Error message when clicking custom button

 

I created a custom button that sends out an E-mail whenever it is clicked. It was working fine until I added a new  logic to not let it function when it is clicked more than once. 

 

Original code:

 

if('{!QA_Release__c.Client_Site_Type__c}'!='' && '{!QA_Release__c.Time_for_Upgrade_Update__c}'!='')

{
location.replace('/email/author/emailauthor.jsp?saveURL={!QA_Release__c.Id}&p3_lkid={!QA_Release__c.Id}&rtype=003&p2_lkid={!QA_Release__c.Assignee__c}&p24=support-sentrydevelopment@clearstructure.com&p4={!QA_Release__c.Cc__c}&template_id=00XC0000001Suga');

}

else 
alert('The "Installation Type" and "Upgrade/Update can be done" fields both need to be filled in order to complete this action.' );

}

 

I now added a custom field called Is_Mail_Sent to my custom object and the idea is to have a default value of 0 for this field whenever a record is created. When someone clicks on my custom button , it should send out an E-mail and set Is_Mail_Sent to 1.  If someone tries to send out an E-mail again , I check if Is_Mail_Sent =1 and if it is 1 , no email should be allowed to be sent.

 

if('{!QA_Release__c.Is_Mail_Sent__c}'!=1)

{

if('{!QA_Release__c.Client_Site_Type__c}'!='' && '{!QA_Release__c.Time_for_Upgrade_Update__c}'!='')

{
location.replace('/email/author/emailauthor.jsp?saveURL={!QA_Release__c.Id}&p3_lkid={!QA_Release__c.Id}&rtype=003&p2_lkid={!QA_Release__c.Assignee__c}&p24=support-sentrydevelopment@clearstructure.com&p4={!QA_Release__c.Cc__c}&template_id=00XC0000001Suga');

}

else 
alert('The "Installation Type" and "Upgrade/Update can be done" fields both need to be filled in order to complete this action.' );

}

else 
alert('Someone already sent an E-mail to support for this task. You cannot perform this action again.' );

'{!QA_Release__c.Is_Mail_Sent__c}'=1;

 

 

I get Invalid left-hand side in Assignment Error message when I click custom button even for the first time. Can someone please help me know what's wrong?

kreshokresho

By reading the first and last lines of your updated code, I assume that QA_Release__c.Is_Mail_Sent__c contains values like null, 0 and 1. If this is true, than your last line renders to:

 

'null' = 1;

 

which is would give you the Invalid left-hand side in Assignment Error.

 

Try this:

 

var mailSent = false;
if('{!QA_Release__c.Is_Mail_Sent__c}'!=1 || mailSent) { if('{!QA_Release__c.Client_Site_Type__c}'!='' && '{!QA_Release__c.Time_for_Upgrade_Update__c}'!='') { location.replace('/email/author/emailauthor.jsp?saveURL={!QA_Release__c.Id}&p3_lkid={!QA_Release__c.Id}&rtype=003&p2_lkid={!QA_Release__c.Assignee__c}&p24=support-sentrydevelopment@clearstructure.com&p4={!QA_Release__c.Cc__c}&template_id=00XC0000001Suga'); } else alert('The "Installation Type" and "Upgrade/Update can be done" fields both need to be filled in order to complete this action.' ); } else alert('Someone already sent an E-mail to support for this task. You cannot perform this action again.' ); mailSent = true;

This will work until the page is reloaded. To make it permanent, in emailauthor.jsp you will also need to update the record's Is_Mail_Sent__c field to true.

 

Regards,
Kresimir
Apex Editor LS - free alternative to Force.com apex editor.
Give kudos (click blue star under my icon) if this was useful

 

 

Mayank Srivastava (Salesforce fan)Mayank Srivastava (Salesforce fan)

You're a genius. That worked perfectly. Thank you :)