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
SImmySImmy 

Why am not able to save this code. It keeps getting error unexpected +=. Please help me

Account IT = new Account();
String integrationtransactionId= '0016F00001y5mQW';
List<String> fields = new List<String>(Account.SObjectType.getDescribe().fields.getMap().keySet());
String soql='';
soql=soql+' select ';
soql=soql+String.join(fields, ',');
System.debug('checking'+soql);
soql=soql+' from Account where id=:integrationtransactionid';
System.debug('soqq'+soql);
IT=database.query(soql);
System.debug('itt'+IT);
String ack=IT.Request__c;  
System.debug('acksss--'+ack);

 
Rounak SharmaRounak Sharma
hi simmi,
I executed the same code in my anonymous and because I dont have request object i removed that and also database.query will not return any thing. check if you are getting the error from some where else.User-added image
 
SImmySImmy
@
Rounak Sharma Thanks for the reply. But my problem is I am not able to save this code to apex class.
Can you just try at your end please? and also database.query will return I believe because I have only used Account and request__c is just a field in account.
SImmySImmy
I am not even able to save this little code even :
List<String> fields = new List<String>(Account.SObjectType.getDescribe().fields.getMap().keySet());
/*String soql = '' ;
soql+= ' select ' + String.join(fields, ',');


Error : 
Error: Compile Error: Unexpected token '+='. at line 7 column 5

 
SImmySImmy
Nikhil Suthar  Thanks for your response. But what I am trying here is, I want to save this code           
String integrationtransactionId= '0012v00002NTHC3'; //account id
Account IT = new Account();
List<String> fields = new List<String>(Account.SObjectType.getDescribe().fields.getMap().keySet());
String soql = '' ;
soql+= ' select ' + String.join(fields, ',');
soql+= ' from Account  where id=:integrationtransactionid';


IT=database.query(soql);

String ack=IT.Request__c;  
System.debug('acksss--'+ack);

But it keeps giving me error i.e.     Error: Compile Error: Unexpected token '+=
 
Rounak SharmaRounak Sharma
hello simmy,
can you try this way?
 String body =  '<table allign="center"><tr><td>' +'<img id=r1sp1 src=' + strDocUrl + '></img>'+'<tr><td>' +'<br /><br />Dear Sir/Madam,  ';
                    body += '<br /><br /> ' + 'Please find the attachment of the report';
                    body += '<br /><br />This is a system generated message, please do not reply. ';
                    body += '<br />Best Regards. <br /><br /><br />'+'</table>';
this is a sample code i did few time ago.
do let me know if it helps
thanks
Nikhil SutharNikhil Suthar
String integrationtransactionId= '0012v00002NTHC3';
List<String> field = new List<String>(Account.SObjectType.getDescribe().fields.getMap().keySet());

String soql = 'select' + String.join(field, ',') + 'from Account where id =:integrationtransactionid ';
Account IT= database.query(soql);
It is working 
SImmySImmy
Hi Rounak, it's still giving me the same error i.e. += unexpected error. It's really annoying because in my org only it's not working.
SImmySImmy
Nikhil, it's working only this way but I want to use it that way like concatenating it by += ... Why it's not working any idea?
Nikhil SutharNikhil Suthar
Simmy why you want to do that way it is working as your requirement ..As for the reason i think it may be String is immutable but i am not sure of it.
SImmySImmy
I am just curious why it's not working in my org but in others it's working. So strange!
Nikhil SutharNikhil Suthar


It is not working in my org also. You can see the errrors here.
User-added image
 
SImmySImmy
🤔 😂 So it's common!!
SImmySImmy
Thanks for your efforts Nikhil.
Nikhil SutharNikhil Suthar
Hello Simmy,
just use your code in class constructor or method it will work.
public with sharing class testhello {
public void methodeone( ) {
    Account IT = new Account();
    String integrationtransactionId= '0016F00001y5mQW';
    List<String> fields = new List<String>(Account.SObjectType.getDescribe().fields.getMap().keySet());
    String soql2 = '';
    soql2 += ' select ';
    soql2 += String.join(fields, ',');
    System.debug('checking'+soql2);
    soql2+=' from Account where id=:integrationtransactionid';
    System.debug('soqq'+soql2);
    IT=database.query(soql2);
    System.debug('itt'+IT);   
}
}

 
Chinnu ChinnuChinnu Chinnu
Hi everyone,
Hey, This is my code..
VF page:
<apex:page controller="ContactsVisualforceController" standardStylesheets="false">
    <apex:form>
    <apex:pageBlock title="Contacts List">
   
             
        <apex:repeat value="{!displayAccounts}" var="acc">
           <dl>
                <dt>Account Name:</dt>
                <dd><apex:outputText value="{!acc.Name}"/></dd> 
            </dl>
            
            <dl><dt>Contact Names:</dt></dl>

            <apex:pageblocktable value="{!acc.Contacts}" var="cont">
                
                <apex:column value="{!cont.firstname}"/>
                <apex:column value="{!cont.lastname}"/>

         </apex:pageblocktable>
       </apex:repeat>
    </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:
public class ContactsVisualforceController {
    public list<Account> displayAccounts {get; set;}
    public ContactsVisualforceController(){
        displayAccounts = [select id,name,(select id,name,firstname,lastname from Contacts) from Account];
    }
}


This is working fine ok.. But now I want to display as Block means

AccountName1 here          All related Contacts For that AccountName1 should display here
AccountName2 here          All related Contacts For that AccountName2 should display here
AccountName3 here          All related Contacts For that AccountName3 should display here

like this I want to display 10 records in one page and another 10 records on another page so pagination we have to use..
So I want how can we do that can anyone please tell me..
Ajay K DubediAjay K Dubedi
Hi Simmy,

I understand your problem and I have gone through this also. The same code I tried in my org and I found its working fine in my org.Although this problem is not a org problem.This is syntax error.Please try my code once also that is given below.

public class testJoin {
    public static void test(){
    Account IT = new Account();
    String integrationtransactionId= '0016F00001y5mQW';
    List<String> fields = new List<String>(Account.SObjectType.getDescribe().fields.getMap().keySet());
    String soql='';
    soql=soql+' select ';

    soql=soql+String.join(fields, ',');
    System.debug('-->'+soql);
    soql=soql+' from Account where id=:integrationtransactionid';
    System.debug('-->'+soql);
    IT=database.query(soql);
    System.debug('itt'+IT);
   // String ack=IT.Request__c;         //I did comment this because this field is not exist in Account obj in my                                              org.
   // System.debug('acksss--'+ack);
    }
}


I am sharing two snaps of code and its output also for you better help.

User-added image

User-added image


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com 
SImmySImmy
It was working when I tried the code enclosed in a method as depicted in the last comments. Anyway Thanks for your help. ☺️
Suraj Tripathi 47Suraj Tripathi 47

Hi Simmy

I am writing a Program. Please check it and it will help

String int= '0012v00002NTHd4'; //account id
Account acc= new Account();
List<String> fields = new List<String>(Account.SObjectType.getDescribe().fields.getMap().keySet());
String soql = '' ;
soql+= ' select ' + String.join(fields, ',');
soql+= ' from Account  where id=:int';


acc=database.query(soql);

String ack=acc.Request__c;  
System.debug('acksss--'+ack);

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,

Suraj Tripathi