You need to sign in to do that
Don't have an account?
Wik
Error: Compile Error: Invalid type: QueryResult at line 5 column 9
Hi,
The following line trows error
QueryResult result = conn.query( 'SELECT Id FROM Account WHERE GroupId = \'00Ge0000000GrKK\' AND Account_Type__c = \'SAM Managed\'' );
Help me fix the same
The following line trows error
QueryResult result = conn.query( 'SELECT Id FROM Account WHERE GroupId = \'00Ge0000000GrKK\' AND Account_Type__c = \'SAM Managed\'' );
Help me fix the same
You have written wrong format for getting List of Account record using dynamic SOQL query.
see below Example:
List<Account> result = database.query( 'SELECT Id FROM Account WHERE Account_Type__c = \'SAM Managed\'' );
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/
even the above line is throwing error
Error: Compile Error: Method does not exist or incorrect signature: [SObject].getId() at line 12 column 32
{
public void method()
{
QueryResult result = conn.query( 'SELECT Id FROM Account WHERE GroupId = \'00Ge0000000GrKK\' AND Account_Type__c = \'SAM Managed\'' );
// Create a new AccountShare object
List<AccountShare> shares = new List<AccountShare>();
for ( sObject rec : result.getRecords() )
{
AccountShare share = new AccountShare();
share.setAccountId(rec.getId());
//Set the portal user Id to share the accounts with
share.setUserOrGroupId( '00Ge0000000GrGX' );
share.setAccountAccessLevel( 'Edit' );
share.setOpportunityAccessLevel( 'Read' );
share.setCaseAccessLevel( 'Edit' );
shares.add( share );
}
conn.create( shares.toArray( new AccountShare[ shares.size() ] ) );
Try to use following class code to fulfill your requirement.
Apex Class:
public class AccShare{
public void method(){
List<Account> result = database.query( 'SELECT Id FROM Account WHERE GroupId = \'00Ge0000000GrKK\' AND Account_Type__c = \'SAM Managed\'' );
// Create a new AccountShare object
List<AccountShare> shares = new List<AccountShare>();
for ( sObject rec : result)
{
AccountShare share = new AccountShare();
share.AccountId = rec.Id;
//Set the portal user Id to share the accounts with
share.UserOrGroupId = '00Ge0000000GrGX';
share.AccountAccessLevel = 'Edit';
share.OpportunityAccessLevel = 'Read';
share.CaseAccessLevel = 'Edit';
shares.add( share );
}
insert shares;
}
}
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/
but this piece of code is not serving my purpose.
i want to share Accounts of a particular public group with ACCount Type as SAM Managed with a particular user.