You need to sign in to do that
Don't have an account?

i am getting error when i am not selected any field in my query
Error:-
|System.QueryException: unexpected token: 'null'
i am getting this error in myclass when i not selected any field
i need to this is dynamically hoe can i do that
my query like:-
select ID,P_Edition__c,p_Opprotuny_name__c,P_Opportunity_ID__c,P_Stage__c,P_Banner__c,null from opportunitylineitem where P_Edition__c = 'Adipec 2018'
how can avoid that if any time i skeep that field and run the class did not get this error please help me
|System.QueryException: unexpected token: 'null'
i am getting this error in myclass when i not selected any field
i need to this is dynamically hoe can i do that
my query like:-
select ID,P_Edition__c,p_Opprotuny_name__c,P_Opportunity_ID__c,P_Stage__c,P_Banner__c,null from opportunitylineitem where P_Edition__c = 'Adipec 2018'
how can avoid that if any time i skeep that field and run the class did not get this error please help me
public class Post_Records {
Public static void Insert_Records()
{
List<Floor_Plan_Mapping__c> LstFlrmapping=new list< Floor_Plan_Mapping__c>();
LstFlrmapping=[select Id, Edition__c,Object__c,Opportunity__c,Opportunity_Id__c,Stage__c,Banner_Name__c,Stand_no__c,Edition_Event_Name__c from Floor_Plan_Mapping__c order by createdDate DESC limit 1];
String query= 'select ID,'+LstFlrmapping[0].Edition__c+','+LstFlrmapping[0].Opportunity__c+','+LstFlrmapping[0].Opportunity_Id__c+','+LstFlrmapping[0].Stage__c+','+LstFlrmapping[0].Banner_Name__c +','+LstFlrmapping[0].Stand_no__c +' from '+LstFlrmapping[0].Object__c+' where '+LstFlrmapping[0].Edition__c+' = \''+LstFlrmapping[0].Edition_Event_Name__c +'\'';
String Edition=LstFlrmapping[0].Edition__c;
String Opportunity=LstFlrmapping[0].Opportunity__c;
String OpprtunityId=LstFlrmapping[0].Opportunity_Id__c;
String Objects=LstFlrmapping[0].Object__c;
String stage=LstFlrmapping[0].Stage__c;
String BannerName=LstFlrmapping[0].Banner_Name__c;
String StandNo=LstFlrmapping[0].Stand_no__c;
System.debug('Query formed----> '+query);
List<sObject> sc= Database.query(query);
System.debug('All Records -->'+sc);
List<OppWrapper> oppWrapperVarList = new List<OppWrapper>();
for(sObject s : sc)
{
OpportunityLineItem o = (OpportunityLineItem)s ;
OppWrapper oppwrappervar=new OppWrapper(o.P_Edition__c,o.P_Opportunity_ID__c,o.p_Opprotuny_name__c,o.P_Stage__c,o.Stand_Number_s__c,o.P_Banner__c);
oppWrapperVarList.add(oppwrappervar);
}
string jsonbody=Json.serialize(oppWrapperVarList);
system.debug('Json body---->'+jsonbody);
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setTimeout(20000);
//request.setEndpoint('http://fpdatamap.salesforceoutsourcing.in/api/FPDatas');
request.setEndpoint('http://sfdata.iqratechnology.com/api/data');
request.setMethod('POST');
request.setHeader('Content-Type','application/json');
request.setBody(jsonbody);
HttpResponse response = http.send(request);
system.debug('Response body '+ response.getBody());
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
}
public class OppWrapper
{
public String EventName {get;set;}
public String RecordId {get;set;}
public String RecordName {get;set;}
public String RecordStage {get;set;}
public String StandNo {get;set;}
public String BannerName {get;set;}
public OppWrapper(String EventName,String RecordId,String RecordName,String RecordStage,String StandNo,String BannerName)
{
this.EventName =EventName;
this.RecordId =RecordId;
this.RecordName =RecordName;
this.RecordStage=RecordStage;
this.StandNo=StandNo;
this.BannerName=BannerName;
}
}
}
here is my class sir please chehk
Line: 71, Column: 1
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: OpportunityLineItem.Stand_Number_s__c
in yellow highlighted fields i skeep to select that field please see this how to avoid if i am not selected any field but still need to post data according to selected fields
sorry sir i didnt get you
sir u der?
sir actually the things need to fields optional if not selected then no imapact just post the records on selected fields only
can it be possible?
List<OppWrapper> oppWrapperVarList = new List<OppWrapper>();
050 for(sObject s : sc)
051 {
052 OpportunityLineItem o = (OpportunityLineItem)s ;
053 OppWrapper oppwrappervar=newOppWrapper(o.P_Edition__c,o.P_Opportunity_ID__c,o.p_Opprotuny_name__c,o.P_Stage__c,o.Stand_Number_s__c,o.P_Banner__c);
054 oppWrapperVarList.add(oppwrappervar);
055 }
can you please chehk this how to avoid if any field was not selected i mean need to do optional
Error:-
Line: 69, Column: 1
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: OpportunityLineItem.Stand_Number_s__c
like if skeep some field to add then it suold be run with rest selected fields i am i need to keep fields optional not mandatory
Public static void Insert_Records()
{
List<Floor_Plan_Mapping__c> LstFlrmapping=new list< Floor_Plan_Mapping__c>();
LstFlrmapping=[select Id, Edition__c,Object__c,Opportunity__c,Opportunity_Id__c,Stage__c,Banner_Name__c,Stand_no__c,Edition_Event_Name__c from Floor_Plan_Mapping__c order by createdDate DESC limit 1];
String query= 'select ID,'+LstFlrmapping[0].Edition__c+','+LstFlrmapping[0].Opportunity__c+','+LstFlrmapping[0].Opportunity_Id__c+','+LstFlrmapping[0].Stage__c+','+LstFlrmapping[0].Banner_Name__c +','+LstFlrmapping[0].Stand_no__c +' from '+LstFlrmapping[0].Object__c+' where '+LstFlrmapping[0].Edition__c+' = \''+LstFlrmapping[0].Edition_Event_Name__c +'\'';
String Edition=LstFlrmapping[0].Edition__c;
String Opportunity=LstFlrmapping[0].Opportunity__c;
String OpprtunityId=LstFlrmapping[0].Opportunity_Id__c;
String Objects=LstFlrmapping[0].Object__c;
String stage=LstFlrmapping[0].Stage__c;
String BannerName=LstFlrmapping[0].Banner_Name__c;
String StandNo=LstFlrmapping[0].Stand_no__c;
System.debug('Query formed----> '+query);
List<sObject> sc= Database.query(query);
System.debug('All Records -->'+sc);
List<OppWrapper> oppWrapperVarList = new List<OppWrapper>();
for(sObject s : sc)
{
OpportunityLineItem o = (OpportunityLineItem)s ;
OppWrapper oppwrappervar=new OppWrapper(o.P_Edition__c,o.P_Opportunity_ID__c,o.p_Opprotuny_name__c,o.P_Stage__c,o.Stand_Number_s__c,o.P_Banner__c);
oppWrapperVarList.add(oppwrappervar);
}
string jsonbody=Json.serialize(oppWrapperVarList);
system.debug('Json body---->'+jsonbody);
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setTimeout(20000);
//request.setEndpoint('http://fpdatamap.salesforceoutsourcing.in/api/FPDatas');
request.setEndpoint('http://sfdata.iqratechnology.com/api/data');
request.setMethod('POST');
request.setHeader('Content-Type','application/json');
request.setBody(jsonbody);
HttpResponse response = http.send(request);
system.debug('Response body '+ response.getBody());
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
}
public class OppWrapper
{
public String EventName {get;set;}
public String RecordId {get;set;}
public String RecordName {get;set;}
public String RecordStage {get;set;}
public String StandNo {get;set;}
public String BannerName {get;set;}
public OppWrapper(String EventName,String RecordId,String RecordName,String RecordStage,String StandNo,String BannerName)
{
this.EventName =EventName;
this.RecordId =RecordId;
this.RecordName =RecordName;
this.RecordStage=RecordStage;
this.StandNo=StandNo;
this.BannerName=BannerName;
}
}
}
here is my class currently it is working fine but when i skeep any fields throghs above error i need to do fields optional i am if i am not selected any field then it will skeep field and run the class on remaining wichever i selected
for(sObject s : sc)
45 {
46 OpportunityLineItem o = (OpportunityLineItem)s ;
47 OppWrapper oppwrappervar=newOppWrapper(o.P_Edition__c,o.P_Opportunity_ID__c,o.p_Opprotuny_name__c,o.P_Stage__c,o.Stand_Number_s__c,o.P_Banner__c);
48 oppWrapperVarList.add(oppwrappervar);
49 }
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: OpportunityLineItem.Stand_Number_s__c
when we are querying for add the fields in wrapper class on that time it is shoing error
This means the error is coming through your API. The above class is fine. You will need to update the REST API class. Which is posting data to Salesforce.
http://sfdata.iqratechnology.com/api/data
The class that is starting with something like this
@RestResource(urlMapping='/data/')
i will show you what i am doing in details ....

Actually i am having this vf page (mapping scrren) i am selecting fields accoridng to whic object i have selected

i have do all the fields are optional whatever fields i want to select i can selcte it is an optional then we save mappin in Floor Plan Mapping object(custom object) i.e api names of the fields which i have selcted and object name and Editon value it is unders first field
i.e FM Expo 2017
accoridng to this fields api name and Object name and value(Fm Expo 2017) we fecth the records from Opportuniy line item object and post the records in third party API
so the thing is when i not selcte any fields in ,mapping scrren(VF) so it may be optional do not throgh any error skeep that field and POst the records in thirdd party API on the basis of selected fields
please see this
OppWrapper oppwrappervar= new OppWrapper(o.P_Edition__c,o.P_Opportunity_ID__c,o.p_Opprotuny_name__c,o.P_Stage__c,o.Stand_Number_s__c,o.P_Banner__c);
can we do this to like this ??
String query= 'select ID,' ;
if(LstFlrmapping[0].Edition__c!=null){
query += LstFlrmapping[0].Edition__c+',' ;
}
if(LstFlrmapping[0].Opportunity__c!=null){
query += LstFlrmapping[0].Opportunity__c+',' ;
}
if(LstFlrmapping[0].Opportunity_Id__c!=null){
query += LstFlrmapping[0].Opportunity_Id__c+',' ;
}
if(LstFlrmapping[0].Stage__c!=null){
query += LstFlrmapping[0].Stage__c+',' ;
}
if(LstFlrmapping[0].Banner_Name__c!=null){
query += LstFlrmapping[0].Banner_Name__c+',' ;
}
if(LstFlrmapping[0].Stand_no__c!=null){
query += LstFlrmapping[0].Stand_no__c+',' ;
}
to avoid if not selected for wrapper class tooo????
Let me know if this solves your problem.
Stand_no__c is floor plan mapping object field
Stand_Number_s__c is opp line itme object field
OppWrapper oppwrappervar = newOppWrapper(o.P_Edition__c,o.P_Opportunity_ID__c,o.p_Opprotuny_name__c,o.P_Stage__c,o.Stand_Number_s__c,o.P_Banner__c);
this thing i need to dymanic apart from this all are working fine how can we do this dynamic?
15:26:13.1 (52330382)|HEAP_ALLOCATE|[52]|Bytes:114
15:26:13.1 (52347462)|METHOD_EXIT|[1]|01p7E0000029MAF|Post_API_Class.Insert_Records()
15:26:13.1 (52357905)|SYSTEM_MODE_EXIT|false
15:26:13.1 (52562497)|FATAL_ERROR|System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: OpportunityLineItem.Stand_Number_s__c
Class.Post_API_Class.Insert_Records: line 52, column 1
after debugging i found the error on this
OppWrapper oppwrappervar = newOppWrapper(o.P_Edition__c,o.P_Opportunity_ID__c,o.p_Opprotuny_name__c,o.P_Stage__c,o.Stand_Number_s__c,o.P_Banner__c);
now we must have to this to do dynamic how can we do this to dynamic?
on line 52. You will have to update that class
To make that wrapper code dynamic you will have to use dynamic apex to get object and fields name.
on line 52. You will have to update that class
To make that wrapper code dynamic you will have to use dynamic apex to get object and fields name.
ok can you please show me how to do that
line no 52:- newOppWrapper(o.P_Edition__c,o.P_Opportunity_ID__c,o.p_Opprotuny_name__c,o.P_Stage__c,o.Stand_Number_s__c,o.P_Banner__c);
Public static void Insert_Records()
{
List<Floor_Plan_Mapping__c> LstFlrmapping=new list< Floor_Plan_Mapping__c>();
LstFlrmapping=[select Id, Edition__c,Object__c,Opportunity__c,Opportunity_Id__c,Stage__c,Banner_Name__c,Stand_no__c,Edition_Event_Name__c from Floor_Plan_Mapping__c order by createdDate DESC limit 1];
String query= 'select ID,' ;
if(LstFlrmapping[0].Edition__c!=null){
query += LstFlrmapping[0].Edition__c+',' ;
}
if(LstFlrmapping[0].Opportunity__c!=null){
query += LstFlrmapping[0].Opportunity__c+',' ;
}
if(LstFlrmapping[0].Opportunity_Id__c!=null){
query += LstFlrmapping[0].Opportunity_Id__c+',' ;
}
if(LstFlrmapping[0].Stage__c!=null){
query += LstFlrmapping[0].Stage__c+',' ;
}
if(LstFlrmapping[0].Banner_Name__c!=null){
query += LstFlrmapping[0].Banner_Name__c+',' ;
}
if(LstFlrmapping[0].Stand_no__c!=null){
query += LstFlrmapping[0].Stand_no__c+',' ;
}
query = query.removeEnd(',');
query += ' from '+LstFlrmapping[0].Object__c+' where '+LstFlrmapping[0].Edition__c+' = \''+LstFlrmapping[0].Edition_Event_Name__c +'\'';
String Edition=LstFlrmapping[0].Edition__c;
String Opportunity=LstFlrmapping[0].Opportunity__c;
String OpprtunityId=LstFlrmapping[0].Opportunity_Id__c;
String Objects=LstFlrmapping[0].Object__c;
String stage=LstFlrmapping[0].Stage__c;
String BannerName=LstFlrmapping[0].Banner_Name__c;
String StandNo=LstFlrmapping[0].Stand_no__c;
System.debug('Query formed----> '+query);
List<sObject> sc= Database.query(query);
System.debug('All Records -->'+sc);
List<OppWrapper> oppWrapperVarList = new List<OppWrapper>();
for(sObject s : sc)
{
OpportunityLineItem o = (OpportunityLineItem)s ;
OppWrapper oppwrappervar=new OppWrapper(o.P_Edition__c,o.P_Opportunity_ID__c,o.p_Opprotuny_name__c,o.P_Stage__c,o.Stand_Number_s__c,o.P_Banner__c);
oppWrapperVarList.add(oppwrappervar);
}
string jsonbody=Json.serialize(oppWrapperVarList);
system.debug('Json body---->'+jsonbody);
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setTimeout(20000);
//request.setEndpoint('http://fpdatamap.salesforceoutsourcing.in/api/FPDatas');
request.setEndpoint('http://sfdata.iqratechnology.com/api/data');
request.setMethod('POST');
request.setHeader('Content-Type','application/json');
request.setBody(jsonbody);
HttpResponse response = http.send(request);
system.debug('Response body '+ response.getBody());
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
}
public class OppWrapper
{
public String EventName {get;set;}
public String RecordId {get;set;}
public String RecordName {get;set;}
public String RecordStage {get;set;}
public String StandNo {get;set;}
public String BannerName {get;set;}
public OppWrapper(String EventName,String RecordId,String RecordName,String RecordStage,String StandNo,String BannerName)
{
this.EventName =EventName;
this.RecordId =RecordId;
this.RecordName =RecordName;
this.RecordStage=RecordStage;
this.StandNo=StandNo;
this.BannerName=BannerName;
}
}
}
public class Post_Records {
Public static void Insert_Records()
{
List<Floor_Plan_Mapping__c> LstFlrmapping=new list< Floor_Plan_Mapping__c>();
LstFlrmapping=[select Id, Edition__c,Object__c,Opportunity__c,Opportunity_Id__c,Stage__c,Banner_Name__c,Stand_no__c,Edition_Event_Name__c from Floor_Plan_Mapping__c order by createdDate DESC limit 1];
String query= 'select ID,'+LstFlrmapping[0].Edition__c+','+LstFlrmapping[0].Opportunity__c+','+LstFlrmapping[0].Opportunity_Id__c+','+LstFlrmapping[0].Stage__c+','+LstFlrmapping[0].Banner_Name__c +','+LstFlrmapping[0].Stand_no__c +' from '+LstFlrmapping[0].Object__c+' where '+LstFlrmapping[0].Edition__c+' = \''+LstFlrmapping[0].Edition_Event_Name__c +'\'';
String Edition=LstFlrmapping[0].Edition__c;
String Opportunity=LstFlrmapping[0].Opportunity__c;
String OpprtunityId=LstFlrmapping[0].Opportunity_Id__c;
String Objects=LstFlrmapping[0].Object__c;
String stage=LstFlrmapping[0].Stage__c;
String BannerName=LstFlrmapping[0].Banner_Name__c;
String StandNo=LstFlrmapping[0].Stand_no__c;
System.debug('Query formed----> '+query);
List<sObject> sc= Database.query(query);
System.debug('All Records -->'+sc);
List<OppWrapper> oppWrapperVarList = new List<OppWrapper>();
for(sObject s : sc)
{
OpportunityLineItem o = (OpportunityLineItem)s ;
OppWrapper oppwrappervar=new OppWrapper(o.P_Edition__c,o.P_Opportunity_ID__c,o.p_Opprotuny_name__c,o.P_Stage__c,o.Stand_Number_s__c,o.P_Banner__c);
oppWrapperVarList.add(oppwrappervar);
}
string jsonbody=Json.serialize(oppWrapperVarList);
system.debug('Json body---->'+jsonbody);
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setTimeout(20000);
//request.setEndpoint('http://fpdatamap.salesforceoutsourcing.in/api/FPDatas');
request.setEndpoint('http://sfdata.iqratechnology.com/api/data');
request.setMethod('POST');
request.setHeader('Content-Type','application/json');
request.setBody(jsonbody);
HttpResponse response = http.send(request);
system.debug('Response body '+ response.getBody());
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
}
public class OppWrapper
{
public String EventName {get;set;}
public String RecordId {get;set;}
public String RecordName {get;set;}
public String RecordStage {get;set;}
public String StandNo {get;set;}
public String BannerName {get;set;}
public OppWrapper(String EventName,String RecordId,String RecordName,String RecordStage,String StandNo,String BannerName)
{
this.EventName =EventName;
this.RecordId =RecordId;
this.RecordName =RecordName;
this.RecordStage=RecordStage;
this.StandNo=StandNo;
this.BannerName=BannerName;
}
}
}
16:34:01.1 (9027588)|HEAP_ALLOCATE|[16]|Bytes:181
16:34:01.1 (9076754)|USER_DEBUG|[16]|DEBUG|Query formed----> select ID,P_Edition__c,p_Opprotuny_name__c,P_Opportunity_ID__c,P_Stage__c,P_Banner__c,Stand_Number_s__c from opportunitylineitem where P_Edition__c = 'Adipec 2018'
OppWrapper oppwrappervar=new OppWrapper(o.P_Edition__c,o.P_Opportunity_ID__c,o.p_Opprotuny_name__c,o.P_Stage__c,o.Stand_Number_s__c,o.P_Banner__c);
then there is no error but if skeep any field in that time thoghs n error
suppose not selected fields is stand no on that time throgs error
Line: 70, Column: 1
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: OpportunityLineItem.Stand_Number_s__c
Select id , Stand_Number_s__c ,OtherFields from OpportunityLineItem
contactTriggerAccountRelation: execution of BeforeInsert caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Account.Phone Trigger.contactTriggerAccountRelation: line 5, column 1
Can you help me with proper syntax, please? Seems like the field needs to be in the query.
Current code:
public static void AddOrderNumber(Map<Id, Order__c> oldMap,list<Order__c> issListIn,boolean isnew,boolean isODSvccall) {
// List<Order__c> issListIn = [select id,Order_Number__c, from Order__c where id in :Ordermap.keyset()];
*The Query is in the commented line. Trying to save it, but unable to do so